:root {
    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-display: 'Fraunces', Georgia, serif;

    --primary: #1a6b5c;
    --primary-hover: #145549;
    --primary-soft: #e8f4f1;
    --primary-muted: #5a9e8f;

    --accent: #c4783a;
    --accent-soft: #faf0e8;

    --bg: #f7f5f2;
    --bg-warm: #faf9f7;
    --surface: #ffffff;
    --surface-raised: #ffffff;

    --text: #1c1917;
    --text-secondary: #57534e;
    --muted: #78716c;
    --border: #e7e5e4;
    --border-light: #f0eeec;

    --success: #15803d;
    --success-bg: #f0fdf4;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --warning: #b45309;
    --warning-bg: #fffbeb;

    --sidebar-bg: #faf9f7;
    --sidebar-border: #e7e5e4;
    --sidebar-text: #57534e;
    --sidebar-active: #e8f4f1;
    --sidebar-active-text: #1a6b5c;

    --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-sm: 0 2px 8px rgba(28, 25, 23, 0.06);
    --shadow-md: 0 8px 24px rgba(28, 25, 23, 0.08);
    --shadow-lg: 0 16px 48px rgba(28, 25, 23, 0.1);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --transition: 0.18s ease;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* ── Page loader ── */
#page-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    background: rgba(247, 245, 242, 0.94);
    backdrop-filter: blur(8px);
    transition: opacity 0.35s ease, visibility 0.35s ease;
}
#page-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loader-text {
    font-size: 0.9rem;
    color: var(--muted);
    font-weight: 500;
    letter-spacing: 0.01em;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 268px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-bottom: 2rem;
    padding: 0.5rem 0.625rem;
}
.sidebar-logo {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}
.sidebar-logo svg { width: 22px; height: 22px; }
.sidebar-brand h1 {
    font-family: var(--font-display);
    font-size: 1.05rem;
    margin: 0;
    color: var(--text);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.01em;
}
.sidebar-brand small {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 450;
    margin-top: 0.1rem;
}

.sidebar nav { flex: 1; }
.nav-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    padding: 0 0.75rem;
    margin: 0 0 0.5rem;
}
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text);
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
}
.sidebar nav a:hover {
    background: var(--border-light);
    color: var(--text);
    text-decoration: none;
}
.sidebar nav a.active {
    background: var(--sidebar-active);
    color: var(--sidebar-active-text);
    font-weight: 600;
}
.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.75;
}
.sidebar nav a.active .nav-icon { opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 0.75rem 0;
    border-top: 1px solid var(--sidebar-border);
}
.sidebar-user-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user {
    color: var(--text);
    font-weight: 600;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: 0.75rem;
    color: var(--muted);
}
.btn-signout {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.35rem 0;
    font-size: 0.8125rem;
    font-family: inherit;
    font-weight: 500;
    transition: color var(--transition);
}
.btn-signout:hover { color: var(--danger); }
.btn-signout svg { width: 15px; height: 15px; }

.main {
    flex: 1;
    margin-left: 268px;
    padding: 2rem 2.5rem;
    min-height: 100vh;
    background: var(--bg);
}
.main-inner { max-width: 1140px; margin: 0 auto; }

.mobile-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 101;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 1.1rem;
    box-shadow: var(--shadow-sm);
}

/* ── Page header ── */
.page-header-brand {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.practice-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: #0f0f0f;
    padding: 0.35rem;
    flex-shrink: 0;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.25rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}
.page-header h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    line-height: 1.2;
}
.page-header .subtitle {
    margin: 0.4rem 0 0;
    color: var(--text-secondary);
    font-size: 0.9375rem;
    max-width: 52ch;
    line-height: 1.55;
}
.header-actions { display: flex; gap: 0.625rem; flex-wrap: wrap; align-items: center; }

.welcome-banner {
    background: linear-gradient(135deg, var(--primary) 0%, #2d8a78 100%);
    color: #fff;
    border-radius: var(--radius-lg);
    padding: 1.75rem 2rem;
    margin-bottom: 1.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    box-shadow: var(--shadow-md);
}
.welcome-banner h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.welcome-banner p {
    margin: 0.35rem 0 0;
    opacity: 0.9;
    font-size: 0.9375rem;
    max-width: 42ch;
}
.welcome-banner .btn {
    background: rgba(255,255,255,0.95);
    color: var(--primary) !important;
    box-shadow: none;
}
.welcome-banner .btn:hover {
    background: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-xs);
}
.card-title {
    margin: 0 0 1.25rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-body { padding: 1.5rem 1.75rem; }

/* ── Stat cards ── */
.stats-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.5rem;
    box-shadow: var(--shadow-xs);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: box-shadow var(--transition), border-color var(--transition);
}
.stat-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: #d6d3d1;
}
.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.teal { background: var(--primary-soft); color: var(--primary); }
.stat-icon.blue { background: #eff6ff; color: #2563eb; }
.stat-icon.amber { background: var(--accent-soft); color: var(--accent); }
.stat-value {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.1;
    letter-spacing: -0.03em;
}
.stat-label {
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-top: 0.2rem;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
}
th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    font-weight: 600;
    background: var(--bg-warm);
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: #fafaf9; }
tbody tr:last-child td { border-bottom: none; }
.table-actions a {
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
}
.table-actions a:hover {
    background: #d4ebe5;
    text-decoration: none;
    color: var(--primary-hover);
}

code, .code-tag {
    font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace;
    font-size: 0.8125rem;
    background: var(--bg-warm);
    border: 1px solid var(--border);
    padding: 0.15rem 0.45rem;
    border-radius: 5px;
    color: var(--text-secondary);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--primary);
    color: #fff !important;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.01em;
    transition: all var(--transition);
    white-space: nowrap;
    box-shadow: var(--shadow-xs);
}
.btn:hover {
    background: var(--primary-hover);
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0); }
.btn:disabled, .btn.loading {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}
.btn-secondary {
    background: var(--text-secondary);
}
.btn-secondary:hover { background: var(--text); }
.btn-outline {
    background: var(--surface);
    color: var(--text-secondary) !important;
    border: 1px solid var(--border);
    box-shadow: none;
}
.btn-outline:hover {
    background: var(--bg-warm);
    border-color: #d6d3d1;
    color: var(--text) !important;
    box-shadow: none;
}
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.8125rem; }
.btn-spinner {
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: none;
}
.btn.loading .btn-spinner { display: inline-block; }
.btn.loading .btn-label { opacity: 0.9; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }
.badge-suspended, .badge-inactive { background: var(--danger-bg); color: var(--danger); }

/* ── Alerts & toasts ── */
.alert {
    padding: 0.9rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    animation: slideDown 0.3s ease;
    line-height: 1.5;
}
.alert-success { background: var(--success-bg); color: #14532d; border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-bg); color: #7f1d1d; border: 1px solid #fecaca; }
.error-list {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
    line-height: 1.5;
}
.error-list li { margin-bottom: 0.25rem; }
.field-error {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.8125rem;
    color: var(--danger);
    font-weight: 500;
    line-height: 1.4;
}
.input-invalid,
.has-error input,
.has-error select,
.has-error textarea {
    border-color: #f87171 !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}
.label-optional {
    font-weight: 450;
    color: var(--muted);
    font-size: 0.75rem;
}

#toast-container {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    padding: 0.9rem 1.25rem;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}
.toast.success { background: var(--success); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ── Forms ── */
.form-section {
    margin-bottom: 2rem;
    padding-bottom: 1.75rem;
    border-bottom: 1px solid var(--border-light);
}
.form-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section h3 {
    margin: 0 0 0.3rem;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.form-section .hint {
    margin: 0 0 1.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.55;
}
.form-group { margin-bottom: 1.15rem; }
label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.8125rem;
    color: var(--text);
    letter-spacing: 0.01em;
}
input, select, textarea {
    width: 100%;
    padding: 0.625rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.9rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--surface);
    color: var(--text);
}
input::placeholder, textarea::placeholder {
    color: #a8a29e;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-muted);
    box-shadow: 0 0 0 3px rgba(26, 107, 92, 0.12);
}
input[type="color"] { height: 44px; padding: 0.3rem; cursor: pointer; }
input[type="checkbox"],
input[type="radio"] {
    width: auto;
    min-width: 1rem;
    height: 1rem;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    box-shadow: none;
    accent-color: var(--primary);
    cursor: pointer;
}
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    box-shadow: 0 0 0 3px rgba(26, 107, 92, 0.12);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.15rem;
}
.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.75rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border-light);
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
}
.empty-state-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    background: var(--primary-soft);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}
.empty-state-icon svg { width: 26px; height: 26px; }
.empty-state p {
    margin: 0 0 1.25rem;
    font-size: 0.9375rem;
    max-width: 32ch;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.55;
}

/* ── Auth page ── */
.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.auth-panel-left {
    background: linear-gradient(160deg, #1a6b5c 0%, #145549 45%, #0f3d35 100%);
    color: #fff;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.auth-panel-left::before {
    content: '';
    position: absolute;
    top: -20%;
    right: -15%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 70%);
    border-radius: 50%;
}
.auth-panel-left::after {
    content: '';
    position: absolute;
    bottom: -10%;
    left: -10%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, rgba(255,255,255,0.05) 0%, transparent 70%);
    border-radius: 50%;
}
.auth-panel-content {
    position: relative;
    z-index: 1;
    max-width: 400px;
}
.auth-panel-content .brand-mark {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    backdrop-filter: blur(4px);
}
.auth-panel-content .brand-mark svg { width: 26px; height: 26px; color: #fff; }
.auth-panel-content h1 {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    margin: 0 0 1rem;
    line-height: 1.2;
    letter-spacing: -0.02em;
}
.auth-panel-content p {
    font-size: 1rem;
    line-height: 1.65;
    opacity: 0.88;
    margin: 0;
}
.auth-panel-right {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    background: var(--bg-warm);
}
.auth-card {
    width: 100%;
    max-width: 400px;
}
.auth-brand {
    margin-bottom: 2rem;
}
.auth-brand h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
}
.auth-brand p {
    margin: 0.5rem 0 0;
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.55;
}

/* ── Info pills ── */
.info-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 1.5rem;
}
.info-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-xs);
}
.info-pill .label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.35rem;
}
.info-pill .value { font-weight: 600; font-size: 0.9375rem; color: var(--text); }

.muted { color: var(--muted); }
.text-sm { font-size: 0.8125rem; }

/* ── Pagination ── */
.pagination-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.1rem;
    border-top: 1px solid var(--border-light);
    background: var(--bg-warm);
}
.pagination-nav a {
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.pagination-nav a:hover {
    background: var(--primary-soft);
    border-color: transparent;
    color: var(--primary);
    text-decoration: none;
}
.pagination-nav .disabled { color: var(--muted); font-size: 0.8125rem; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-panel-left { display: none; }
    .auth-panel-right { min-height: 100vh; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; padding: 1.25rem; padding-top: 4rem; }
    .mobile-toggle { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; }
    .welcome-banner { padding: 1.35rem 1.5rem; }
}

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    padding: 0;
    text-decoration: underline;
}

.field-hint {
    margin-top: 0.35rem;
    font-size: 0.8125rem;
    color: var(--muted);
    line-height: 1.5;
}

.field-checkbox {
    margin-top: 0.25rem;
}

.checkbox-label {
    display: flex;
    gap: 0.65rem;
    align-items: flex-start;
    margin-bottom: 0;
    font-size: 0.875rem;
    font-weight: 450;
    line-height: 1.55;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 0.2rem;
}
