*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --sage: #4A7C6F;
    --sage-deep: #2D5A4E;
    --sage-light: #E8F0ED;
    --cream: #FAF8F5;
    --warm: #E8825C;
    --warm-light: #FFF0EB;
    --charcoal: #1A1A1A;
    --text: #3A3A3A;
    --text-muted: #7A7A7A;
    --white: #FFFFFF;
    --border: rgba(74, 124, 111, 0.12);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(74, 124, 111, 0.08);
    --shadow-lg: 0 8px 32px rgba(74, 124, 111, 0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    color: var(--text);
    background: var(--cream);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ---- APP NAV ---- */
.app-nav {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
    padding: 0.9rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(250, 248, 245, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--sage-deep);
    letter-spacing: -0.03em;
    text-decoration: none;
}
.logo span { color: var(--warm); }

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 100px;
    transition: all 0.15s ease;
}
.nav-link:hover { color: var(--sage-deep); background: var(--sage-light); }
.nav-link.active { color: var(--sage-deep); background: var(--sage-light); }

/* ---- MAIN CONTENT ---- */
#app-content {
    max-width: 960px;
    margin: 0 auto;
    padding: 5.5rem 1.25rem 3rem;
    min-height: 100vh;
}

/* ---- PAGE HEADER ---- */
.page-header {
    margin-bottom: 2rem;
}
.page-header h1 {
    font-family: 'Syne', sans-serif;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--charcoal);
    letter-spacing: -0.03em;
}
.page-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.3rem;
}
.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ---- CARDS ---- */
.card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.card-lg { padding: 2rem; }

/* ---- STATS GRID ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid var(--border);
    text-align: center;
}
.stat-card .stat-value {
    font-family: 'Syne', sans-serif;
    font-size: 2rem;
    font-weight: 800;
    color: var(--sage-deep);
    letter-spacing: -0.03em;
}
.stat-card .stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

/* ---- VISIT LIST ---- */
.visit-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.visit-item {
    background: var(--white);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.visit-item:hover {
    border-color: var(--sage);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.visit-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.visit-icon.routine { background: var(--sage-light); }
.visit-icon.medication { background: #EDE9FE; }
.visit-icon.therapy { background: var(--warm-light); }
.visit-icon.assessment { background: #FEF3C7; }
.visit-icon.personal_care { background: #DBEAFE; }
.visit-icon.other { background: #F3F4F6; }

.visit-info {
    flex: 1;
    min-width: 0;
}
.visit-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--charcoal);
    margin-bottom: 0.15rem;
}
.visit-info p {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.visit-meta {
    text-align: right;
    flex-shrink: 0;
}
.visit-meta .visit-date {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}
.visit-meta .visit-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    margin-top: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-draft { background: #FEF3C7; color: #92400E; }
.badge-reviewed { background: var(--sage-light); color: var(--sage-deep); }
.badge-finalized { background: var(--sage); color: white; }

/* ---- FORMS ---- */
.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--charcoal);
    margin-bottom: 0.4rem;
    letter-spacing: 0.01em;
}
.form-group label .optional {
    color: var(--text-muted);
    font-weight: 400;
}
.form-input {
    width: 100%;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-family: inherit;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}
.form-input:focus {
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(74, 124, 111, 0.1);
}
.form-input::placeholder {
    color: #B5B5B5;
}
textarea.form-input {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}
select.form-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237A7A7A' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* ---- VOICE INPUT ---- */
.voice-input-area {
    position: relative;
}
.voice-controls {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
}
.btn-voice {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: var(--warm-light);
    color: var(--warm);
    border: 1.5px solid transparent;
    border-radius: 100px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-voice:hover {
    background: var(--warm);
    color: white;
}
.btn-voice.recording {
    background: #FEE2E2;
    color: #DC2626;
    border-color: #FECACA;
    animation: recording-pulse 1.5s ease-in-out infinite;
}
@keyframes recording-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.2); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}
.voice-status {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary {
    background: var(--sage);
    color: white;
}
.btn-primary:hover { background: var(--sage-deep); }
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-secondary {
    background: var(--sage-light);
    color: var(--sage-deep);
}
.btn-secondary:hover { background: #D5E5DF; }
.btn-warm {
    background: var(--warm);
    color: white;
}
.btn-warm:hover { background: #D06E48; }
.btn-outline {
    background: transparent;
    color: var(--sage);
    border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--sage); background: var(--sage-light); }
.btn-sm {
    padding: 0.45rem 1rem;
    font-size: 0.8rem;
}
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 10px;
}

/* ---- CARE NOTE DISPLAY ---- */
.care-note-display {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}
.care-note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--sage-light);
}
.care-note-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--sage-deep);
}
.care-note-body {
    padding: 1.5rem;
}
.care-note-section {
    margin-bottom: 1.5rem;
}
.care-note-section:last-child { margin-bottom: 0; }
.care-note-section h4 {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sage);
    margin-bottom: 0.5rem;
}
.care-note-section p, .care-note-section li {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text);
}
.care-note-section ul {
    list-style: none;
    padding: 0;
}
.care-note-section ul li {
    padding: 0.25rem 0;
    padding-left: 1.2rem;
    position: relative;
}
.care-note-section ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.65rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sage);
}

.vitals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.6rem;
}
.vital-chip {
    background: var(--sage-light);
    border-radius: var(--radius-xs);
    padding: 0.5rem 0.75rem;
    text-align: center;
}
.vital-chip .vital-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.vital-chip .vital-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--sage-deep);
    margin-top: 0.1rem;
}

.concern-banner {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}
.concern-banner .concern-icon { flex-shrink: 0; font-size: 1rem; }
.concern-banner p { font-size: 0.85rem; color: #991B1B; }

/* ---- CLIENT CARDS ---- */
.client-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.client-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s ease;
}
.client-card:hover {
    border-color: var(--sage);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.client-card h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--charcoal);
    margin-bottom: 0.5rem;
}
.client-card-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.client-card-meta span {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* ---- MODAL ---- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal {
    background: var(--white);
    border-radius: var(--radius);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--charcoal);
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
}
.modal-body {
    padding: 1.5rem;
}
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* ---- LOADING ---- */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 1rem;
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--sage-light);
    border-top-color: var(--sage);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ---- EMPTY STATE ---- */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
}
.empty-state .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    opacity: 0.6;
}
.empty-state h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--charcoal);
    margin-bottom: 0.5rem;
}
.empty-state p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* ---- TOAST ---- */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    background: var(--charcoal);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    max-width: 340px;
}
.toast.success { background: var(--sage-deep); }
.toast.error { background: #DC2626; }
@keyframes slideUp {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---- AI GENERATING ---- */
.ai-generating {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2.5rem;
    gap: 1rem;
}
.ai-dots {
    display: flex;
    gap: 0.4rem;
}
.ai-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sage);
    animation: ai-bounce 1.4s ease-in-out infinite;
}
.ai-dots span:nth-child(2) { animation-delay: 0.16s; }
.ai-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes ai-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
.ai-generating p {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--sage-deep);
}

/* ---- BACK LINK ---- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 1.25rem;
    transition: color 0.15s ease;
}
.back-link:hover { color: var(--sage); }

/* ---- FORMATTED NOTE ---- */
.formatted-note {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
}
.formatted-note h1, .formatted-note h2, .formatted-note h3 {
    font-family: 'Syne', sans-serif;
    color: var(--charcoal);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}
.formatted-note h1 { font-size: 1.3rem; }
.formatted-note h2 { font-size: 1.1rem; }
.formatted-note h3 { font-size: 0.95rem; }
.formatted-note p { margin-bottom: 0.75rem; }
.formatted-note ul, .formatted-note ol { margin-left: 1.5rem; margin-bottom: 0.75rem; }
.formatted-note strong { color: var(--charcoal); }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
    .app-nav { padding: 0.75rem 1rem; }
    .nav-links { gap: 0.1rem; }
    .nav-link { padding: 0.4rem 0.7rem; font-size: 0.78rem; }
    #app-content { padding: 5rem 1rem 2rem; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .client-grid { grid-template-columns: 1fr; }
    .vitals-grid { grid-template-columns: repeat(2, 1fr); }
    .page-header h1 { font-size: 1.5rem; }
    .care-note-body { padding: 1rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
    .stat-card { padding: 1rem 0.5rem; }
    .stat-card .stat-value { font-size: 1.5rem; }
}
