:root {
    --bg: #f4f7fb;
    --panel: #fff;
    --line: #d9e2ef;
    --line-soft: #edf2f8;
    --text: #132034;
    --muted: #697890;
    --brand: #f2554b;
    --blue: #1867d8;
    --blue-soft: #eef5ff;
    --green: #15803d;
    --shadow: 0 10px 24px rgba(17, 31, 52, .055);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Aptos", "Segoe UI Variable", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--blue); text-decoration: none; }
button, input, select { font: inherit; }
.topbar {
    height: 60px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
}
.brand { display: inline-flex; align-items: center; color: var(--brand); }
.brand-logo { display: block; height: auto; }
.brand-logo-horizontal { width: 178px; max-height: 38px; }
.nav { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.wrap { width: min(1420px, calc(100% - 40px)); margin: 22px auto; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(430px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: 0 12px 30px rgba(22, 34, 58, .08); }
.auth-logo { display: block; width: 132px; height: auto; margin: 0 0 24px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.panel-pad { padding: 22px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.title { margin: 0 0 6px; font-size: 30px; line-height: 1.15; }
.subtitle { margin: 0; color: var(--muted); }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 700; color: #33435f; }
.input, .select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    padding: 10px 12px;
    color: var(--text);
}
.search {
    min-height: 62px;
    font-size: 18px;
    padding: 16px 18px;
    box-shadow: 0 4px 12px rgba(22, 34, 58, .05);
}
.doctor-hero { margin-top: 12px; }
.doctor-search { margin: 22px 0 34px; display: grid; gap: 16px; }
.search-shell {
    min-height: 64px;
    border: 1px solid #cfd9ea;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(22, 34, 58, .06);
    display: grid;
    grid-template-columns: 48px 1fr auto;
    align-items: center;
    padding: 0 16px;
}
.search-icon { color: #607292; font-size: 30px; line-height: 1; transform: translateY(-1px); }
.search-input { min-width: 0; border: 0; outline: 0; color: var(--text); font-size: 20px; background: transparent; }
.search-input::placeholder { color: #667894; opacity: 1; }
.search-key { border: 0; border-radius: 6px; background: #eef2f7; color: #637089; padding: 7px 10px; font-size: 13px; cursor: pointer; }
.search-key:disabled { cursor: wait; opacity: .72; }
.doctor-search.is-searching .search-shell { border-color: #9fbef3; box-shadow: 0 0 0 3px rgba(29, 111, 242, .10), 0 4px 14px rgba(22, 34, 58, .06); }
.doctor-search.is-searching .search-input { cursor: wait; }
.search-status {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #c7d8f7;
    background: #f1f6ff;
    color: #245196;
    border-radius: 8px;
    padding: 12px 14px;
}
.search-wait {
    border: 1px solid #fed7aa;
    background: #fff7ed;
    color: #9a3412;
    border-radius: 8px;
    padding: 12px 14px;
}
.search-status[hidden],
.search-wait[hidden] {
    display: none;
}
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(29, 111, 242, .25);
    border-top-color: var(--blue);
    border-radius: 999px;
    animation: spin .8s linear infinite;
    flex: 0 0 auto;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.search-examples { display: flex; align-items: center; gap: 12px; padding-left: 18px; color: #667894; font-size: 14px; flex-wrap: wrap; }
.search-examples a { border-radius: 999px; background: #eef2f7; color: #61708b; padding: 6px 14px; }
.activity-section { display: grid; gap: 14px; }
.activity-heading h2 { margin: 0; font-size: 18px; }
.activity-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(22, 34, 58, .05); overflow: hidden; }
.activity-row { display: grid; grid-template-columns: 260px 1fr 34px; gap: 22px; align-items: center; min-height: 86px; padding: 16px 18px; border-top: 1px solid var(--line); color: var(--text); }
.activity-row:first-child { border-top: 0; }
.patient-summary { display: flex; align-items: center; gap: 16px; min-width: 0; }
.patient-summary strong { display: block; color: var(--text); }
.patient-avatar { background: var(--avatar-bg, #eaf1ff); color: var(--avatar-color, #1d6ff2); }
.activity-studies { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 12px; align-items: center; }
.study-card { min-height: 56px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; align-items: center; gap: 12px; background: #fff; min-width: 0; }
.study-card strong { display: block; color: var(--text); font-size: 13px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.study-card small { display: block; color: var(--muted); margin-top: 4px; }
.study-icon { width: 30px; height: 30px; border-radius: 999px; display: grid; place-items: center; background: #eef4ff; color: var(--blue); flex: 0 0 auto; font-weight: 800; }
.activity-open { color: #7d8ba3; font-size: 30px; text-align: center; }
.empty-state { padding: 34px 20px; }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); }
.empty-state p { margin: 0 0 18px; max-width: 680px; }
.pagination { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pagination-pages { display: flex; align-items: center; gap: 6px; }
.pagination-page {
    min-width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 7px;
    display: grid;
    place-items: center;
    color: var(--text);
    background: #fff;
    font-size: 14px;
    font-weight: 700;
}
.pagination-page.is-current { background: var(--blue); border-color: var(--blue); color: #fff; }
.pagination-disabled { opacity: .5; cursor: default; }
.btn {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: 8px 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    font-size: 13px;
    font-weight: 650;
    box-shadow: 0 1px 2px rgba(17, 31, 52, .04);
}
.btn:hover { border-color: #b8c7dc; background: #f8fafc; }
.btn-sm { min-height: 34px; padding: 7px 10px; font-size: 13px; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-danger { color: #b42318; }
.badge { border-radius: 999px; padding: 4px 9px; background: #eef4ff; color: #1d4ed8; font-size: 12px; font-weight: 700; }
.badge-green { background: #e9f8ee; color: var(--green); }
.alert { border-radius: 7px; padding: 12px 14px; margin: 12px 0; background: #fff4ed; border: 1px solid #fed7aa; color: #9a3412; }
.status { border-radius: 7px; padding: 12px 14px; margin: 12px 0; background: #ecfdf3; border: 1px solid #bbf7d0; color: #166534; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 14px 16px; text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.referrer-option { cursor: pointer; }
.referrer-option:hover,
.referrer-option:focus,
.referrer-option.is-selected { background: #f3f7ff; outline: none; }
.referrer-option.is-selected { box-shadow: inset 3px 0 0 var(--blue); }
.patient-row { display: grid; grid-template-columns: 230px 1fr 90px; gap: 16px; padding: 16px 18px; border-top: 1px solid var(--line); align-items: center; }
.avatar { width: 48px; height: 48px; border-radius: 999px; background: var(--avatar-bg, #eaf1ff); color: var(--avatar-color, #1d6ff2); display: grid; place-items: center; font-weight: 800; }
.study-chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 7px; padding: 10px 12px; min-width: 210px; background: #fff; }
.media { width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #000; }
.pre { white-space: pre-wrap; background: #0f172a; color: #e5e7eb; padding: 16px; border-radius: 8px; overflow: auto; }
.crumbs {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #667894;
    font-size: 12px;
    margin: -2px 0 14px;
}
.crumbs a,
.crumbs strong {
    color: #53647f;
    font-weight: 700;
}
.patient-study-shell {
    display: grid;
    grid-template-columns: 318px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}
.patient-sidebar {
    overflow: hidden;
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 98px);
    display: flex;
    flex-direction: column;
}
.patient-profile {
    min-height: 112px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 18px;
    border-bottom: 1px solid var(--line);
}
.patient-profile-avatar {
    width: 58px;
    height: 58px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    font-size: 21px;
    font-weight: 800;
    flex: 0 0 auto;
}
.patient-profile h1 {
    margin: 0 0 4px;
    font-size: 19px;
    line-height: 1.15;
    letter-spacing: -.01em;
}
.patient-profile p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 550;
}
.study-list-section {
    min-height: 0;
    padding: 16px 12px 14px;
    display: flex;
    flex-direction: column;
}
.study-list-section h2,
.study-files h3 {
    margin: 0 0 10px;
    font-size: 14px;
    line-height: 1.2;
    letter-spacing: -.005em;
}
.study-list {
    min-height: 0;
    overflow: auto;
    display: grid;
    gap: 7px;
    padding-right: 2px;
}
.study-list-item {
    min-height: 54px;
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
    color: var(--text);
    background: #fff;
    transition: background .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.study-list-item:hover {
    border-color: #c3d0e1;
    background: #fbfdff;
}
.study-list-item.is-selected {
    border-color: #b8d0f4;
    background: var(--blue-soft);
    box-shadow: inset 3px 0 0 var(--blue);
}
.study-list-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--blue-soft);
    color: var(--blue);
    font-size: 16px;
    font-weight: 800;
}
.study-list-item.is-selected .study-list-icon {
    background: #dcecff;
    color: var(--blue);
}
.study-list-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 700;
}
.study-list-date {
    color: #61708b;
    font-size: 12px;
    white-space: nowrap;
}
.study-detail {
    padding: 20px 22px 22px;
}
.study-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}
.eyebrow {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.study-detail-header h2 {
    margin: 0;
    font-size: 26px;
    line-height: 1.14;
    letter-spacing: -.02em;
}
.study-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.study-actions .btn {
    min-width: 142px;
    font-weight: 650;
}
.study-meta-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 18px;
    margin: 0 0 14px;
    padding: 10px 12px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fbfdff;
}
.study-meta-grid div {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 8px;
    align-items: baseline;
    min-height: 22px;
}
.study-meta-grid dt {
    color: #6e7d94;
    font-size: 11px;
    font-weight: 650;
}
.study-meta-grid dd {
    min-width: 0;
    margin: 0;
    color: #27364d;
    font-size: 12px;
    font-weight: 650;
    overflow-wrap: anywhere;
}
.study-files {
    padding-top: 0;
}
.file-button-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}
.file-button {
    min-height: 54px;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 9px 10px;
    display: flex;
    align-items: center;
    gap: 9px;
    text-align: left;
    cursor: pointer;
    transition: background .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.file-button:hover {
    border-color: #c3d0e1;
    background: #fbfdff;
}
.file-button.is-active {
    border-color: #b8d0f4;
    background: var(--blue-soft);
    box-shadow: inset 3px 0 0 var(--blue);
}
.file-button-text {
    min-width: 0;
    flex: 1 1 auto;
}
.file-button strong,
.file-button small {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-button strong {
    font-size: 13px;
    line-height: 1.2;
}
.file-button small {
    color: var(--muted);
    font-size: 11px;
    margin-top: 2px;
}
.file-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: grid;
    place-items: center;
    background: #eef4ff;
    color: var(--blue);
    font-size: 12px;
    font-weight: 900;
    flex: 0 0 auto;
}
.file-icon-html {
    background: #eaf2ff;
    color: var(--blue);
    font-size: 17px;
}
.file-icon-pdf {
    background: #fff1ef;
    color: #e3362d;
}
.file-icon-image {
    background: #eafaf1;
    color: #15803d;
    font-size: 18px;
}
.file-icon-video {
    background: #eef4ff;
    color: var(--blue);
    font-size: 15px;
}
.study-viewer {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}
.study-viewer.is-report {
    border-color: #d7e0ee;
    box-shadow: 0 12px 28px rgba(23, 32, 51, 0.05);
}
.viewer-toolbar {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 9px 7px 13px;
    border-bottom: 1px solid var(--line);
    background: #fbfdff;
}
.viewer-toolbar[hidden] {
    display: none !important;
}
.viewer-toolbar strong {
    display: block;
    font-size: 13px;
}
.study-viewer.is-report .viewer-toolbar strong {
    color: #172033;
    font-size: 20px;
    line-height: 1.1;
    letter-spacing: 0;
}
.viewer-toolbar span {
    display: block;
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
}
.viewer-toolbar span:empty {
    display: none;
}
.viewer-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
}
.btn-small {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}
.viewer-canvas {
    min-height: 520px;
    background: #f7f9fc;
}
.study-viewer.is-report .viewer-canvas {
    min-height: 430px;
    background: #fff;
}
.viewer-canvas iframe,
.viewer-canvas img,
.viewer-canvas video {
    display: block;
    width: 100%;
    height: 66vh;
    min-height: 520px;
    border: 0;
    background: #fff;
}
.study-viewer.is-report .viewer-canvas iframe {
    height: 58vh;
    min-height: 430px;
}
.viewer-canvas img,
.viewer-canvas video {
    object-fit: contain;
}
.empty-viewer {
    border: 1px dashed #cfd9ea;
    border-radius: 8px;
    padding: 28px;
    color: var(--muted);
    background: #f8fafc;
}
@media (max-width: 800px) {
    .wrap { width: min(100% - 24px, 1380px); margin: 22px auto; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .patient-row { grid-template-columns: 1fr; }
    .activity-row { grid-template-columns: 1fr; gap: 14px; }
    .activity-studies { grid-template-columns: 1fr; }
    .activity-open { display: none; }
    .search-shell { grid-template-columns: 36px 1fr auto; padding: 0 10px; }
    .search-input { font-size: 16px; }
    .between { align-items: flex-start; flex-direction: column; }
    .crumbs { gap: 9px; flex-wrap: wrap; }
    .patient-study-shell { grid-template-columns: 1fr; }
    .patient-sidebar { position: static; max-height: none; }
    .patient-profile { min-height: auto; padding: 18px 16px; }
    .patient-profile-avatar { width: 52px; height: 52px; font-size: 19px; }
    .study-detail { padding: 18px 14px; }
    .study-detail-header { flex-direction: column; }
    .study-actions { width: 100%; justify-content: stretch; }
    .study-actions .btn { flex: 1 1 100%; }
    .viewer-toolbar { align-items: flex-start; flex-direction: column; }
    .viewer-toolbar-actions { width: 100%; }
    .viewer-toolbar-actions .btn { flex: 1 1 0; }
    .study-meta-grid { grid-template-columns: 1fr; gap: 14px; }
    .study-meta-grid div { grid-template-columns: 1fr; gap: 4px; }
    .file-button-row { grid-template-columns: 1fr; }
    .viewer-canvas,
    .viewer-canvas iframe,
    .viewer-canvas img,
    .viewer-canvas video {
        min-height: 430px;
        height: 62vh;
    }
}
