:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #18202a;
    --muted: #778291;
    --line: #e6eaf0;
    --accent: #e55548;
    --accent-dark: #cb4136;
    --accent-soft: #fff1ef;
    --success: #2d9d69;
    --warning: #c8891c;
    --sidebar: #18202a;
    --sidebar-muted: #9ca7b5;
    --shadow: 0 12px 40px rgba(23, 32, 42, .07);
    --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: currentColor; display: block; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 30;
}
.brand {
    height: 82px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--accent);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .4px;
}
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 16px; }
.brand-copy span { color: var(--sidebar-muted); font-size: 11px; }
.main-nav { padding: 18px 12px; overflow-y: auto; flex: 1; }
.nav-item {
    min-height: 44px;
    padding: 0 12px;
    margin-bottom: 4px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #c7ced8;
    transition: .18s ease;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.is-active { background: rgba(229, 85, 72, .16); color: #fff; }
.nav-item.is-active .nav-icon { color: #ff786b; }
.nav-icon { width: 22px; color: #8995a5; }
.nav-section-title {
    margin: 22px 12px 8px;
    color: #6e7a89;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 10px;
    font-weight: 700;
}
.sidebar-user {
    min-height: 78px;
    padding: 14px 14px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: grid;
    grid-template-columns: 38px minmax(0,1fr) 36px;
    align-items: center;
    gap: 10px;
}
.user-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,.09);
    border-radius: 50%;
    font-weight: 700;
}
.user-meta { min-width: 0; display: grid; }
.user-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.user-meta span { color: var(--sidebar-muted); font-size: 10px; margin-top: 2px; }
.icon-button {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #8e99a7;
}
.icon-button:hover { background: rgba(255,255,255,.07); color: #fff; }
.app-main { margin-left: 260px; min-height: 100vh; }
.topbar {
    height: 70px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.topbar-title { font-size: 17px; font-weight: 700; flex: 1; }
.topbar-user { color: var(--muted); font-size: 12px; }
.mobile-menu { display: none; color: var(--text); }
.content-wrap { padding: 28px; max-width: 1600px; margin: 0 auto; }
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}
.page-head h1 { margin: 0 0 5px; font-size: 25px; line-height: 1.2; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
    min-height: 42px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 0 16px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 650;
}
.btn:hover { border-color: #cfd5dd; background: #fafbfc; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn svg { width: 18px; height: 18px; }
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-card { padding: 20px; }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 750; line-height: 1; }
.stat-hint { color: var(--muted); font-size: 11px; margin-top: 8px; }
.card { overflow: hidden; }
.card-head {
    min-height: 62px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    border-bottom: 1px solid var(--line);
}
.card-head h2 { margin: 0; font-size: 15px; }
.card-body { padding: 20px; }
.mt-18 { margin-top: 18px; }
.mt-24 { margin-top: 24px; }
.toolbar {
    padding: 14px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--line);
}
.search-box { position: relative; min-width: 260px; flex: 1; max-width: 460px; }
.search-box svg {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: #9aa5b2;
    width: 18px;
    height: 18px;
}
.input,
.select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    outline: none;
    padding: 0 13px;
}
.search-box .input { padding-left: 40px; }
.input:focus,
.select:focus { border-color: #b8c1cc; box-shadow: 0 0 0 3px rgba(24,32,42,.04); }
.select { min-width: 160px; width: auto; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th,
.table td { padding: 13px 18px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table th { color: var(--muted); font-size: 11px; font-weight: 700; background: #fbfcfd; }
.table tr:last-child td { border-bottom: 0; }
.table-empty { padding: 54px 20px !important; text-align: center !important; color: var(--muted); }
.empty-state { text-align: center; padding: 48px 22px; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 6px; }
.quick-actions { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.quick-action {
    min-height: 92px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: #fff;
}
.quick-action:hover { border-color: #ccd3dc; box-shadow: 0 8px 24px rgba(23,32,42,.05); }
.quick-action span { color: var(--muted); font-size: 11px; }
.quick-action strong { font-size: 14px; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; border-radius: 999px; font-size: 11px; font-weight: 650; }
.badge-success { color: var(--success); background: #edf8f2; }
.badge-muted { color: #647080; background: #f1f3f6; }

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 26px;
    background:
        radial-gradient(circle at 12% 18%, rgba(229,85,72,.10), transparent 32%),
        radial-gradient(circle at 87% 80%, rgba(24,32,42,.08), transparent 32%),
        #f5f7fa;
}
.auth-card {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(23,32,42,.12);
    padding: 30px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .brand-mark { color: #fff; }
.auth-brand strong { display: block; font-size: 17px; }
.auth-brand span { color: var(--muted); font-size: 11px; }
.auth-card h1 { margin: 0 0 7px; font-size: 24px; }
.auth-card > p { margin: 0 0 22px; color: var(--muted); }
.form-group { margin-bottom: 15px; }
.form-label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 650; }
.auth-card .btn { width: 100%; margin-top: 5px; }
.alert { padding: 11px 13px; border-radius: 10px; margin-bottom: 16px; font-size: 12px; }
.alert-error { background: #fff0ef; color: #a53a31; border: 1px solid #ffd4d0; }
.auth-note { margin-top: 16px; color: var(--muted); font-size: 11px; text-align: center; }
.sidebar-overlay { display: none; }

@media (max-width: 1180px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
    .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
    .app-main { margin-left: 0; }
    .mobile-menu { display: grid; }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 25;
        border: 0;
        background: rgba(13,18,24,.38);
    }
    .sidebar-open .sidebar-overlay { display: block; }
}

@media (max-width: 720px) {
    .topbar { padding: 0 16px; }
    .topbar-user { display: none; }
    .content-wrap { padding: 18px 14px 28px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .actions .btn { flex: 1; }
    .grid-4, .grid-2, .quick-actions { grid-template-columns: 1fr; }
    .search-box { min-width: 100%; max-width: none; }
    .select { flex: 1; min-width: 140px; }
    .auth-card { padding: 24px 20px; }
}

/* Stage 2: doctors and access management */
.alert-success { background: #edf8f2; color: #24704c; border: 1px solid #cfeadd; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 34px; padding: 0 11px; border-radius: 8px; font-size: 11px; }
.btn-danger { color: #a53a31; border-color: #f0cbc7; background: #fff8f7; }
.btn-danger:hover { color: #8f2f28; border-color: #e6b6b1; background: #fff1ef; }
.table-actions-head { width: 1%; }
.table-actions { display: flex; justify-content: flex-end; align-items: center; gap: 7px; }
.table-actions form { margin: 0; }
.muted-text { color: var(--muted); font-size: 10px; }
.form-card { max-width: 920px; }
.form-grid { display: grid; gap: 16px; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-group-wide { grid-column: 1 / -1; }
.form-hint { margin-top: 6px; color: var(--muted); font-size: 10px; }
.form-actions { padding: 16px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.check-row { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check-row input { margin-top: 3px; }
.check-row span { display: grid; gap: 2px; }
.check-row strong { font-size: 12px; }
.check-row small { color: var(--muted); font-size: 10px; }

@media (max-width: 900px) {
    .table-actions { min-width: 330px; justify-content: flex-start; }
}

@media (max-width: 720px) {
    .form-grid-2 { grid-template-columns: 1fr; }
    .form-group-wide { grid-column: auto; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }
}

/* Stage 3: specialties and custom multi-select */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 420px;
}
.tag {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    background: #f1f3f6;
    color: #4f5c6b;
    font-size: 11px;
    white-space: nowrap;
}
.multi-select {
    position: relative;
    width: 100%;
}
.multi-select-control {
    width: 100%;
    min-height: 42px;
    padding: 5px 44px 5px 9px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    display: flex;
    align-items: center;
    text-align: left;
    position: relative;
}
.multi-select-control:hover { border-color: #cfd5dd; }
.multi-select.is-open .multi-select-control {
    border-color: #b8c1cc;
    box-shadow: 0 0 0 3px rgba(24,32,42,.04);
}
.multi-select-values {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    min-width: 0;
}
.multi-select-placeholder {
    color: #9aa5b2;
    padding: 4px 3px;
}
.multi-select-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 0 7px 0 10px;
    border-radius: 8px;
    background: #f1f3f6;
    color: #364250;
    font-size: 11px;
    font-weight: 600;
}
.multi-select-tag-remove {
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #8a95a2;
    font-size: 16px;
    line-height: 18px;
}
.multi-select-tag-remove:hover {
    background: #e2e6eb;
    color: #4d5866;
}
.multi-select-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-50%);
    color: #8894a2;
    pointer-events: none;
    transition: transform .15s ease, color .15s ease;
}
.multi-select-arrow svg {
    width: 20px;
    height: 20px;
}
.multi-select.is-open .multi-select-arrow {
    transform: translateY(-50%) rotate(180deg);
}
.multi-select-dropdown {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 7px);
    z-index: 80;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(23,32,42,.14);
}
.multi-select.is-open .multi-select-dropdown { display: block; }
.multi-select-search-wrap { padding-bottom: 7px; }
.multi-select-options {
    max-height: 230px;
    overflow-y: auto;
    display: grid;
    gap: 3px;
}
.multi-select-option {
    width: 100%;
    min-height: 38px;
    padding: 0 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 9px;
    text-align: left;
}
.multi-select-option:hover { background: #f6f8fa; }
.multi-select-option.is-selected { background: var(--accent-soft); }
.multi-select-check {
    width: 18px;
    height: 18px;
    border: 1px solid #cfd6df;
    border-radius: 5px;
    display: grid;
    place-items: center;
    color: transparent;
    font-size: 11px;
    font-weight: 800;
}
.multi-select-option.is-selected .multi-select-check {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.multi-select-empty {
    padding: 16px 10px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}
.multi-select-manage {
    display: block;
    margin-top: 7px;
    padding: 9px 10px 4px;
    border-top: 1px solid var(--line);
    color: var(--accent-dark);
    font-size: 11px;
    font-weight: 650;
}
.multi-select-manage:hover { text-decoration: underline; }
.inline-add-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}
.inline-edit-form {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 360px;
}
.input-compact {
    min-height: 34px;
    max-width: 360px;
}
.settings-form-card { max-width: 760px; }
.settings-card .card-body p { margin-top: 0; color: var(--muted); }

@media (max-width: 720px) {
    .inline-add-form { grid-template-columns: 1fr; }
    .inline-add-form .btn { width: 100%; }
    .inline-edit-form { min-width: 280px; }
}

/* Core reference books */
.alert-warning {
    background: #fff8e7;
    color: #8a6415;
    border: 1px solid #f1dfad;
}
.select-full {
    width: 100%;
    min-width: 0;
}
.select-compact {
    width: 100%;
    min-width: 180px;
    min-height: 36px;
}
.no-margin { margin-bottom: 0; }
.reference-add-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
    gap: 12px;
    align-items: end;
}
.reference-add-action {
    display: flex;
    align-items: flex-end;
}
.breed-edit-grid {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(170px, .8fr) auto;
    gap: 8px;
    align-items: center;
    min-width: 520px;
}
.btn:disabled {
    opacity: .55;
    cursor: not-allowed;
}
@media (max-width: 820px) {
    .reference-add-grid { grid-template-columns: 1fr; }
    .reference-add-action .btn { width: 100%; }
    .breed-edit-grid { min-width: 500px; }
}
