:root {
    --bg: #f7fafc;
    --panel: #ffffff;
    --panel-soft: #f9fbfd;
    --line: #e0e8f1;
    --line-soft: #edf2f7;
    --line-strong: #cbd8e6;
    --muted: #64748b;
    --text: #111827;
    --primary: #60a5fa;
    --primary-strong: #2563eb;
    --primary-soft: #f0f7ff;
    --primary-border: #d7eafe;
    --primary-hover: #e5f1ff;
    --accent: #3b82f6;
    --accent-soft: #f0f7ff;
    --neutral: #334155;
    --neutral-weak: #edf2f7;
    --neutral-soft: #f1f5f9;
    --danger: #dc2626;
    --shadow-sm: 0 8px 18px rgba(15, 23, 42, .035);
    --shadow-md: 0 18px 38px rgba(15, 23, 42, .06);
}

* {
    box-sizing: border-box;
    letter-spacing: 0;
}

html {
    min-width: 0;
}

body {
    margin: 0;
    font-family: Arial, "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
}

a {
    color: inherit;
}

button,
input,
select {
    font: inherit;
}

button {
    min-width: 78px;
    height: 42px;
    border: 0;
    border-radius: 8px;
    padding: 0 16px;
    color: #fff;
    background: var(--accent);
    cursor: pointer;
    font-weight: 700;
    white-space: nowrap;
    transition: background-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

button:hover {
    background: var(--primary-strong);
    box-shadow: 0 8px 18px rgba(59, 130, 246, .16);
}

button:active {
    transform: translateY(1px);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(96, 165, 250, .28);
    outline-offset: 2px;
}

input,
select {
    width: 100%;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 13px;
    color: var(--text);
    background: #fff;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, .16);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--bg);
}

.auth-panel {
    width: min(380px, calc(100vw - 32px));
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 30px;
    box-shadow: var(--shadow-md);
}

.auth-panel h1 {
    margin: 0 0 8px;
    font-size: 22px;
}

.auth-panel label {
    display: block;
    margin-top: 16px;
    color: var(--neutral);
    font-weight: 700;
}

.auth-panel input {
    margin-top: 7px;
}

.auth-panel button {
    width: 100%;
    margin-top: 22px;
}

.captcha-img {
    display: block;
    width: 112px;
    height: 40px;
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
}

.hint {
    color: var(--muted);
}

.error {
    color: #991b1b;
    background: #fee2e2;
    border-radius: 8px;
    padding: 10px;
}

.console-page {
    min-height: 100vh;
    overflow: hidden;
}

.console-header {
    height: 68px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 20px;
    padding: 0 20px;
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand-block {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    flex: 0 0 48px;
    width: 48px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: #fff;
    background: var(--primary);
    font-size: 15px;
    font-weight: 800;
}

.brand-block h1 {
    margin: 0;
    font-size: 19px;
    line-height: 1.25;
}

.brand-block p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.logout-form {
    margin: 0;
}

.logout-form button {
    min-width: 64px;
    height: 36px;
    background: #475569;
}

.logout-form button:hover {
    background: #334155;
    box-shadow: none;
}

.console-shell {
    height: calc(100vh - 68px);
    display: grid;
    grid-template-columns: minmax(320px, 388px) minmax(0, 1fr);
    gap: 16px;
    padding: 16px;
}

.rail-panel,
.media-workspace {
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.rail-panel {
    background: #fff;
}

.rail-section {
    min-height: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
}

.media-hero h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.25;
}

.media-hero p,
.list-main small,
.media-card-body span,
.workspace-empty p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.search-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 72px;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    background: #fff;
}

.search-bar input {
    height: 40px;
    border-radius: 8px;
    background: var(--panel-soft);
}

.search-bar button {
    min-width: 72px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    color: var(--neutral);
    background: #fff;
    box-shadow: none;
}

.search-bar button:hover {
    color: var(--primary-strong);
    border-color: var(--primary-border);
    background: var(--primary-soft);
    box-shadow: none;
}

.selected-context-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 12px 16px 0;
    background: #fff;
}

.customer-search-bar {
    padding-top: 10px;
}

.back-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--neutral);
    background: var(--panel-soft);
    text-decoration: none;
}

.back-icon:hover {
    color: var(--primary-strong);
    border-color: var(--primary-border);
    background: var(--primary-soft);
}

.back-icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.selected-context {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
}

.selection-list {
    min-height: 0;
    flex: 1;
    overflow: auto;
    padding: 10px 12px 12px;
}

.selection-list a {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 68px;
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--text);
    background: transparent;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.selection-list a:hover {
    background: var(--panel-soft);
    border-color: var(--line);
}

.selection-list a.active {
    background: var(--primary-soft);
    border-color: var(--primary-border);
    box-shadow: inset 3px 0 0 var(--primary-strong);
}

.primary-list a {
    justify-content: space-between;
}

.list-main {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.list-main strong {
    overflow-wrap: anywhere;
    font-size: 17px;
    line-height: 1.25;
}

.row-action {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--primary-strong);
    background: var(--primary-soft);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.selection-list a:hover .row-action {
    color: #fff;
    background: var(--primary-strong);
}

.patient-avatar {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: #fff;
    background: var(--neutral);
    font-weight: 800;
}

.empty-state {
    margin: 0;
    padding: 28px 18px;
    color: var(--muted);
    text-align: center;
}

.empty-state.large {
    margin: auto;
}

.list-total {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    margin: 0;
    padding: 0 16px;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    background: #fff;
    font-size: 12px;
    font-weight: 700;
}

.pager {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 12px;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 13px;
}

.pager a {
    min-width: 72px;
    padding: 7px 12px;
    border-radius: 8px;
    background: var(--neutral-soft);
    color: var(--neutral);
    text-align: center;
    text-decoration: none;
    font-weight: 700;
    white-space: nowrap;
}

.pager a:hover {
    color: var(--primary-strong);
    background: var(--primary-soft);
}

.media-workspace {
    background: #fff;
}

.workspace-empty {
    min-height: 100%;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    padding: 28px;
    text-align: center;
}

.workspace-empty h2 {
    margin: 0;
    font-size: 24px;
}

.empty-illustration {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    color: var(--primary-strong);
    background: var(--primary-soft);
    font-size: 24px;
    font-weight: 900;
}

.media-layout {
    min-height: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
}

.media-hero {
    min-height: 94px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line-soft);
    background: var(--panel-soft);
}

.patient-summary {
    min-width: 0;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--primary-strong);
    font-size: 12px;
    font-weight: 900;
}

.media-summary {
    display: flex;
    gap: 10px;
}

.media-summary span {
    min-width: 96px;
    padding: 11px 13px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
    box-shadow: 0 6px 14px rgba(15, 23, 42, .035);
}

.media-summary strong {
    display: block;
    color: var(--text);
    font-size: 22px;
    line-height: 1.1;
}

.media-tabs {
    display: flex;
    gap: 8px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line-soft);
    background: #fff;
}

.media-tabs a {
    min-width: 118px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: #475569;
    background: var(--neutral-soft);
    text-decoration: none;
    font-weight: 800;
    white-space: nowrap;
}

.media-tabs a:hover {
    border-color: var(--line-strong);
    background: var(--neutral-soft);
}

.media-tabs a span {
    min-width: 24px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #e2e8f0;
    font-size: 12px;
    line-height: 1.35;
}

.media-tabs a.active {
    color: var(--primary-strong);
    border-color: var(--primary-border);
    background: var(--primary-soft);
}

.media-tabs a.active span {
    color: #fff;
    background: var(--primary-strong);
}

.media-stage {
    min-height: 0;
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: 304px;
    align-content: start;
    justify-content: stretch;
    align-items: start;
    gap: 16px;
    padding: 18px clamp(16px, 2.4vw, 26px);
    overflow: auto;
}

.media-stage.is-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 360px;
}

.media-card {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .055);
    overflow: hidden;
}

.media-thumb {
    width: 100%;
    height: 190px;
    min-height: 190px;
    flex: 0 0 190px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    border-bottom: 1px solid var(--line-soft);
    overflow: hidden;
    font-weight: 900;
    text-decoration: none;
}

.image-card .media-thumb {
    color: var(--primary-strong);
    background: var(--primary-soft);
}

.video-card .media-thumb {
    color: var(--neutral);
    background: var(--neutral-soft);
}

.media-thumb img,
.media-thumb video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.media-thumb video {
    background: #0f172a;
}

.media-card-body {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 4px;
    padding: 0 12px;
}

.media-card-body strong {
    overflow-wrap: anywhere;
    font-size: 14px;
    line-height: 1.35;
}

.media-card-actions {
    display: flex;
    gap: 8px;
    padding: 0 12px 12px;
    margin-top: auto;
}

.media-card-actions a {
    min-width: 76px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--primary-strong);
    background: var(--primary-soft);
    text-align: center;
    text-decoration: none;
    font-weight: 800;
    white-space: nowrap;
}

.media-card-actions a:hover {
    background: var(--primary-hover);
}

.media-card-actions a:last-child {
    color: var(--neutral);
    background: var(--neutral-soft);
}

.media-card-actions a:last-child:hover {
    background: #e2e8f0;
}

.media-empty {
    width: 100%;
    min-height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    text-align: center;
}

.media-pager {
    margin-top: auto;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media (max-width: 1100px) {
    .console-page {
        overflow: auto;
    }

    .console-shell {
        height: auto;
        grid-template-columns: 1fr;
    }

    .rail-panel,
    .media-workspace {
        min-height: 360px;
    }
}

@media (max-width: 720px) {
    .console-header {
        height: auto;
        grid-template-columns: 1fr;
        align-items: start;
        padding: 14px 16px;
    }

    .console-shell {
        padding: 12px;
    }

    .media-hero {
        grid-template-columns: 1fr;
    }

    .search-bar {
        grid-template-columns: minmax(0, 1fr) 72px;
        padding: 12px;
    }

    .selected-context-row {
        padding: 10px 12px 0;
    }

    .media-summary {
        width: 100%;
    }

    .media-summary span {
        flex: 1;
        min-width: 0;
    }

    .media-tabs {
        padding: 10px 12px;
    }

    .media-tabs a {
        flex: 1;
        min-width: 0;
    }

    .media-stage {
        grid-template-columns: minmax(0, 1fr);
        padding: 14px;
    }

    .media-thumb {
        min-height: 0;
    }
}
