:root {
    color-scheme: light dark;
    --bg: #f7f8fb;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9dee8;
    --accent: #0f766e;
    --accent-2: #2563eb;
    --danger: #b42318;
    --warning: #b54708;
    --ok: #027a48;
    --shadow: 0 14px 42px rgba(18, 32, 47, .08);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --bg: #101418;
        --panel: #171d22;
        --text: #ecf2f8;
        --muted: #9aa8b6;
        --line: #2b3642;
        --shadow: 0 18px 48px rgba(0, 0, 0, .28);
    }
}

html[data-theme="dark"] {
    --bg: #101418;
    --panel: #171d22;
    --text: #ecf2f8;
    --muted: #9aa8b6;
    --line: #2b3642;
    --shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 14px clamp(16px, 4vw, 48px);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
}
.brand { font-weight: 800; font-size: 1.05rem; margin-right: auto; }
nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
nav a { color: var(--muted); font-weight: 650; font-size: .93rem; }
nav a:hover { color: var(--text); }
.theme-form select { min-width: 88px; }

.page {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 64px;
}
.hero {
    min-height: 320px;
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    align-items: center;
    gap: 28px;
    margin-bottom: 28px;
}
.hero.compact { min-height: 180px; grid-template-columns: 1fr; }
.hero h1, .section-head h1, .profile h1 {
    font-size: clamp(2rem, 4vw, 4rem);
    line-height: 1.02;
    margin: 0;
    max-width: 900px;
}
.section-head { margin: 12px 0 24px; }
.section-head p, .muted { color: var(--muted); }
.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
    font-size: .78rem;
}

.search-panel, .card, .auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.search-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 18px;
}
.grid { display: grid; gap: 18px; }
.doctors { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.doctor-card {
    display: grid;
    grid-template-columns: 74px 1fr;
    gap: 16px;
    padding: 18px;
}
.card { padding: 18px; }
.card, .search-panel, .table-wrap, .auth-card { min-width: 0; }
.card h2 { margin: 0 0 8px; font-size: 1.2rem; }
.avatar {
    width: 74px;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #e0f2fe, #ccfbf1);
    color: #164e63;
    font-weight: 850;
    overflow: hidden;
}
.avatar.large { width: min(220px, 48vw); }
.profile {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 28px;
    align-items: center;
    margin: 28px 0;
}
.facts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.facts span, .status {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--muted);
    font-size: .88rem;
}
.status.approved, .status.completed { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); }
.status.pending, .status.modification_requested, .status.open { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, var(--line)); }
.status.rejected, .status.cancelled, .status.closed { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.status.resolved { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); }

.split {
    display: grid;
    grid-template-columns: minmax(280px, 420px) 1fr;
    gap: 24px;
    align-items: start;
}
.stack { display: grid; gap: 14px; }
.quick-links, .stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}
.stats strong { display: block; font-size: 2.2rem; margin-top: 8px; }

.form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-weight: 700; color: var(--muted); }
.check { display: flex; align-items: center; }
input, select, textarea, button, .button {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
    max-width: 100%;
}
textarea { resize: vertical; }
button, .button {
    display: inline-grid;
    place-items: center;
    width: auto;
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    font-weight: 800;
    cursor: pointer;
}
.button.small { min-height: 34px; padding: 6px 10px; }
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
.auth-card { max-width: 420px; margin: 48px auto; padding: 22px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .82rem; text-transform: uppercase; }
.actions form, .inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions input, .actions select { width: auto; min-width: 140px; }
.notice {
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    background: var(--panel);
}
.notice.success { border-color: color-mix(in srgb, var(--ok) 34%, var(--line)); }
.notice.error { border-color: color-mix(in srgb, var(--danger) 34%, var(--line)); }
.pagination { display: flex; gap: 10px; margin: 24px 0; }
.pagination a { border: 1px solid var(--line); padding: 8px 12px; border-radius: 8px; }
.empty { text-align: center; padding: 80px 0; }
details { margin-top: 12px; }
summary { cursor: pointer; font-weight: 800; }
.wide { grid-template-columns: minmax(320px, 520px) 1fr; }
.alphabet {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 18px 0 24px;
}
.alphabet a {
    display: grid;
    place-items: center;
    width: 38px;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    font-weight: 800;
}
.alphabet a.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.article-page {
    max-width: 860px;
    margin: 28px auto;
}
.article-page h1 { font-size: clamp(2rem, 4vw, 3.7rem); line-height: 1.05; margin: 0 0 14px; }
.lead { color: var(--muted); font-size: 1.12rem; }
.article-body {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(18px, 4vw, 34px);
    box-shadow: var(--shadow);
}
.article-body img, .wysiwyg-editor img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
}
.editor-wrap {
    display: grid;
    gap: 8px;
}
.editor-toolbar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.editor-toolbar button {
    min-height: 36px;
    padding: 6px 10px;
}
.wysiwyg-editor {
    min-height: 260px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 14px;
    overflow: auto;
}
.wysiwyg-editor:focus {
    outline: 2px solid color-mix(in srgb, var(--accent) 36%, transparent);
    outline-offset: 2px;
}
.job-detail { grid-template-columns: 1fr minmax(280px, 380px); }
.site-slider {
    position: relative;
    min-height: clamp(340px, 56vw, 620px);
    overflow: hidden;
    border-radius: 8px;
    margin-bottom: 28px;
    background: #111;
}
.site-slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity .55s ease;
}
.site-slide.active { opacity: 1; }
.site-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: .74;
}
.site-slide-copy {
    position: absolute;
    inset: auto 0 0 0;
    width: min(760px, calc(100% - 32px));
    padding: clamp(22px, 5vw, 54px);
    color: #fff;
}
.site-slide-copy h1 {
    margin: 0;
    font-size: clamp(2rem, 5vw, 4.6rem);
    line-height: 1;
}
.home-cms { max-width: 980px; }
.post-thumb, .page-featured {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 12px;
}
.cms-cats { align-items: center; }
.cms-cat-link {
    width: auto !important;
    aspect-ratio: auto !important;
    padding: 8px 12px;
}
.slide-admin {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 14px;
}
.slide-admin img {
    width: 160px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
}
.menu-item { cursor: grab; }
.tool-color {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 4px 8px;
    min-height: 36px;
}
.tool-color input {
    width: 34px;
    min-height: 28px;
    padding: 0;
    border: 0;
}
.chat-shell {
    max-width: 900px;
    margin: 0 auto;
}
.chat-log {
    display: grid;
    gap: 12px;
    margin: 18px 0;
}
.chat-message {
    max-width: min(720px, 92%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--panel);
    box-shadow: var(--shadow);
}
.chat-message.staff {
    margin-left: auto;
    border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
}
.chat-message.requester {
    margin-right: auto;
}
.chat-message p { margin: 8px 0; }
.chat-message span {
    color: var(--muted);
    font-size: .82rem;
}

@media (min-width: 761px) and (max-width: 1024px) {
    .topbar { gap: 14px; }
    nav { gap: 10px; }
    .hero { grid-template-columns: 1fr; min-height: 260px; }
    .split { grid-template-columns: minmax(280px, 360px) 1fr; }
    .doctors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }
    .brand { margin-right: 0; }
    nav {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: thin;
    }
    nav a { flex: 0 0 auto; }
    .theme-form select { width: 100%; }
    .page {
        width: min(100% - 24px, 1180px);
        padding-top: 18px;
    }
    .hero, .profile, .split { grid-template-columns: 1fr; }
    .hero {
        min-height: auto;
        gap: 18px;
        padding: 10px 0;
    }
    .hero h1, .section-head h1, .profile h1 { font-size: 2rem; }
    .doctor-card {
        grid-template-columns: 58px 1fr;
        gap: 12px;
        padding: 14px;
    }
    .avatar { width: 58px; }
    .avatar.large { width: 160px; }
    .facts { display: grid; grid-template-columns: 1fr; }
    .wide, .job-detail { grid-template-columns: 1fr; }
    .slide-admin { grid-template-columns: 1fr; }
    .slide-admin img { width: 100%; }
    .site-slider { min-height: 360px; }
    .site-slide-copy { padding: 20px; }
    .alphabet { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
    .alphabet a { flex: 0 0 auto; width: 36px; }
    .facts span { border-radius: 8px; }
    .actions form, .inline-form { align-items: stretch; }
    .actions input, .actions select, .actions button, .inline-form button { width: 100%; }
    .table-wrap {
        border: 0;
        background: transparent;
        overflow: visible;
    }
    table, thead, tbody, tr, th, td {
        display: block;
        width: 100%;
        min-width: 0;
    }
    thead { display: none; }
    tr {
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--panel);
        box-shadow: var(--shadow);
        overflow: hidden;
    }
    td {
        border-bottom: 1px solid var(--line);
        padding: 10px 12px;
    }
    td:last-child { border-bottom: 0; }
    input, select, textarea, button, .button { min-height: 46px; }
}

@media (max-width: 420px) {
    .page { width: min(100% - 18px, 1180px); }
    .hero h1, .section-head h1, .profile h1 { font-size: 1.72rem; }
    .card, .search-panel, .auth-card { padding: 14px; }
    .doctor-card { grid-template-columns: 1fr; }
    .avatar { width: 64px; }
    .quick-links, .stats, .doctors { grid-template-columns: 1fr; }
}
