:root {
    --primary:      #4A9B8E;
    --primary-dark: #3d8277;
    --primary-light:#6BB5A8;
    --secondary:    #2C3E50;
    --bg:           #f5f7f6;
    --text:         #2C3E50;
    --border:       #E9ECEF;
    --border-soft:  #d8e4e1;
    --danger:       #c0392b;
    --success:      #27ae60;
    --shadow-light: 0 2px 10px rgba(0,0,0,0.08);
    --transition:   0.2s ease-in-out;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Header (matches landing page style) ─── */
.app-header {
    position: sticky;
    top: 0;
    height: 68px;
    overflow: visible;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-light);
    z-index: 1000;
}

.app-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    max-width: 1200px;
    height: 68px;
    margin: 0 auto;
    padding: 0 1.5rem;
    gap: 1.5rem;
    overflow: hidden;
}

.app-brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    height: 68px;
    overflow: hidden;
    text-decoration: none;
}

.app-logo {
    height: 36px;
    max-height: 36px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

/* Nav links */
.app-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
}

.app-nav a {
    color: var(--secondary);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.45rem 0.85rem;
    border-radius: 6px;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
    position: relative;
}

.app-nav a:hover {
    background: rgba(74, 155, 142, 0.08);
    color: var(--primary);
    text-decoration: none;
}

.app-nav a.active {
    color: var(--primary);
    background: rgba(74, 155, 142, 0.1);
}

/* User info + logout */
.app-header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.app-user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--secondary);
    white-space: nowrap;
}

.app-user-link {
    text-decoration: none;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    transition: background var(--transition), color var(--transition);
}

.app-user-link:hover {
    background: rgba(74, 155, 142, 0.08);
    color: var(--primary);
    text-decoration: none;
}

.btn-header-logout {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 1rem;
    border-radius: 6px;
    border: 1.5px solid var(--border-soft);
    background: transparent;
    color: var(--secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
    cursor: pointer;
}

.btn-header-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(192, 57, 43, 0.05);
    text-decoration: none;
}

/* Mobile toggle */
.app-nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    flex-shrink: 0;
}

.app-nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--secondary);
    border-radius: 2px;
    transition: var(--transition);
}

@media (max-width: 768px) {
    .app-nav-toggle { display: flex; }

    .app-nav,
    .app-header-user {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        position: absolute;
        top: 68px;
        left: 0;
        right: 0;
        background: #fff;
        border-bottom: 1px solid var(--border);
        padding: 0.75rem 1.5rem 1rem;
        box-shadow: var(--shadow-light);
        z-index: 999;
    }

    .app-nav.app-nav--open,
    .app-header-user.app-nav--open {
        display: flex;
    }

    .app-header-inner { position: relative; }
    .app-user-name { font-size: 0.8rem; color: #888; }
}

/* ─── Minimal layout header (login / patient pages) ─── */
.minimal-header {
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
}

.minimal-body { background: var(--bg); }

.minimal-page {
    min-height: calc(100vh - 64px);
}

/* ─── Main content area ─── */
.app-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card h2, .card h3 { margin-bottom: 1rem; }

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; text-decoration: none; }
.btn-outline { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: #e67e22; color: #fff; border: none; }
.btn-warning:hover { background: #ca6f1e; color: #fff; text-decoration: none; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.mt-2 { margin-top: 1.5rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 500; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
}
.form-group textarea { min-height: 100px; resize: vertical; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6cb; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; background: #f9fbfa; }

.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-active { background: #d4edda; color: #155724; }
.badge-inactive { background: #f8d7da; color: #721c24; }
.badge-draft { background: #fff3cd; color: #856404; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 1rem; text-align: center; }
.stat-card .number { font-size: 2rem; font-weight: 700; color: var(--primary); }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

.minimal-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}
.minimal-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2rem;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 4px 24px rgba(44, 62, 80, 0.07);
}
.minimal-card h1 { margin-bottom: 0.5rem; color: var(--primary); }
.minimal-card p.sub { color: #666; margin-bottom: 1.5rem; }

.field-list { list-style: none; }
.field-list li {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.generated-url {
    background: #eef7f5;
    border: 1px solid var(--primary);
    padding: 1rem;
    border-radius: 6px;
    word-break: break-all;
    margin: 1rem 0;
}

.answer-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.answer-item:last-child { border-bottom: none; }
.answer-label { font-weight: 600; font-size: 0.85rem; color: #555; }
.answer-value { margin-top: 0.25rem; }

.checkbox-group label { display: flex; align-items: center; gap: 0.5rem; font-weight: normal; margin-bottom: 0.35rem; }
.radio-group label { display: flex; align-items: center; gap: 0.5rem; font-weight: normal; margin-bottom: 0.35rem; }

.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.text-muted { color: #666; font-size: 0.9rem; }

/* ─── Prescription form ─── */
.medication-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    margin-bottom: 0.5rem;
}

.medication-row .form-group { margin-bottom: 0; }

/* ─── Anamnesis history accordion (prescription page) ─── */
.anamnesis-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.anamnesis-accordion {
    border: 1px solid #e2e8eb;
    border-radius: 8px;
    overflow: hidden;
}

.accordion-item + .accordion-item {
    border-top: 1px solid #e2e8eb;
}

.accordion-trigger {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    transition: background 0.15s;
    gap: 0.75rem;
}

.accordion-trigger:hover { background: #f5f8f7; }
.accordion-trigger[aria-expanded="true"] { background: #f0f7f6; }

.accordion-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.accordion-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.accordion-chevron {
    transition: transform 0.2s;
    color: #888;
}

.accordion-body {
    border-top: 1px solid #e2e8eb;
    background: #fafcfc;
}

.anamnesis-answer-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.answer-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid #eef2f1;
}

.answer-item:last-child { border-bottom: none; }

.answer-label {
    color: #555;
    flex: 1;
    min-width: 0;
}

.answer-value {
    font-weight: 500;
    color: var(--text);
    text-align: right;
    max-width: 55%;
    word-break: break-word;
}

.answer-negative { color: #888; font-weight: 400; }

/* ─── Prescription view ─── */
.medication-list {
    list-style: none;
    counter-reset: med-counter;
    margin: 0;
    padding: 0;
}

.medication-item {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: #fafcfb;
}

.medication-number {
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
    font-size: 0.95rem;
}

.medication-text {
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.5;
}

.prescription-obs {
    margin-top: 1.25rem;
    padding: 0.85rem 1rem;
    background: #f5f7f6;
    border-left: 3px solid var(--primary);
    border-radius: 0 6px 6px 0;
}

.prescription-obs strong {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    margin-bottom: 0.4rem;
}

.prescription-obs p { font-size: 0.9rem; color: #555; }

/* ─── Patient authenticated area ─── */
.patient-hero-card {
    background: linear-gradient(135deg, #f0f8f6 0%, #e6f4f1 100%);
    border-color: #b2d8d2;
}

.patient-hero-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.patient-hero-inner h2 { margin-bottom: 0; }

/* Clinic tags */
.clinic-tag-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.clinic-tag {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.clinic-tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}

/* Response cards */
.response-list { display: flex; flex-direction: column; gap: 0.75rem; }

.response-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    flex-wrap: wrap;
}

.response-card:hover {
    border-color: var(--primary-light);
    box-shadow: 0 2px 12px rgba(74,155,142,0.1);
}

.response-card-info { flex: 1; min-width: 0; }

.response-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.response-card-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.3rem;
}

.response-card-meta .sep { color: #ccc; }

.response-card-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .response-card-actions { width: 100%; justify-content: flex-end; }
}
