:root {
    color-scheme: light;
    --red: #ed1c24;
    --ink: #211d1f;
    --paper: #f6f7f8;
    --surface: #ffffff;
    --muted: #66707a;
    --line: #d8dde2;
    --ok: #137a46;
    --warn: #985b00;
    font-family: "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    min-height: 38px;
    border: 0;
    background: var(--red);
    color: white;
    padding: 0 16px;
    font-weight: 650;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: .72;
}

button.is-loading {
    position: relative;
    pointer-events: none;
}

button.is-loading::before {
    content: "";
    width: 14px;
    height: 14px;
    margin-right: 8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    display: inline-block;
    vertical-align: -2px;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

button.secondary {
    border: 1px solid var(--line);
    background: white;
    color: var(--ink);
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
    border: 0;
    background: var(--red);
    color: white;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

.button-link.secondary {
    border: 1px solid var(--line);
    background: white;
    color: var(--ink);
}

.button-link:visited {
    color: white;
}

.button-link.secondary:visited {
    color: var(--ink);
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    background: white;
    padding: 8px 10px;
}

textarea {
    min-height: 88px;
    resize: vertical;
}

fieldset {
    border: 1px solid var(--line);
    margin: 0;
    padding: 10px;
}

legend {
    color: var(--muted);
    font-size: .86rem;
    font-weight: 650;
}

.role-picker {
    display: grid;
    gap: 8px;
}

.role-picker label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.role-picker input {
    width: auto;
    min-height: auto;
}

label span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: .86rem;
    font-weight: 650;
}

output {
    display: block;
    margin-top: 12px;
    min-height: 22px;
    color: var(--muted);
    font-weight: 700;
}

code {
    display: inline-block;
    max-width: 100%;
    overflow-wrap: anywhere;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    padding: 3px 6px;
    font-family: Consolas, "Segoe UI Mono", monospace;
}

.auth-page {
    min-height: 100vh;
    background:
        linear-gradient(90deg, rgba(255,255,255,.96) 0%, rgba(255,255,255,.86) 44%, rgba(255,255,255,.36) 100%),
        url("/images/background.jpg") center right / cover no-repeat;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    align-items: center;
    padding: 48px;
}

.auth-card {
    width: min(430px, 100%);
    min-width: 0;
    display: grid;
    gap: 16px;
    background: rgba(255,255,255,.9);
    border: 1px solid rgba(33,29,31,.12);
    padding: 32px;
}

.auth-card-wide {
    width: min(1120px, 100%);
}

#files-section {
    min-width: 0;
    container-type: inline-size;
}

#verify-form {
    display: grid;
    gap: 14px;
}

#patient-files .table-wrap {
    max-width: 100%;
    overflow-x: hidden;
}

#patient-files table {
    width: 100%;
    table-layout: fixed;
    min-width: 0;
}

#patient-files th:nth-child(1),
#patient-files td:nth-child(1) {
    width: 150px;
}

#patient-files th:nth-child(2),
#patient-files td:nth-child(2) {
    width: 38%;
}

#patient-files th:nth-child(3),
#patient-files td:nth-child(3) {
    width: 100px;
}

#patient-files th:nth-child(4),
#patient-files td:nth-child(4) {
    width: 240px;
}

#patient-files td:nth-child(2) {
    width: auto;
    min-width: 0;
}

.patient-file-name {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.patient-file-name-button {
    max-width: 100%;
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--red);
    text-align: left;
}

#patient-files td:last-child {
    white-space: normal;
}

.patient-file-cards {
    display: none;
}

.patient-file-card {
    display: grid;
    gap: 10px;
    min-width: 0;
    border: 1px solid var(--line);
    background: white;
    padding: 12px;
}

.patient-file-card-label {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 750;
}

.patient-file-card-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
}

.patient-file-card-meta div {
    min-width: 0;
}

.patient-file-card-meta dt {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 750;
}

.patient-file-card-meta dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.patient-files-back-button {
    width: 100%;
}

@container (max-width: 720px) {
    .patient-files-table {
        display: none;
    }

    .patient-file-cards {
        display: grid;
        gap: 10px;
    }

    .patient-file-name {
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .patient-file-name-button {
        width: 100%;
    }

    .patient-file-actions {
        flex-wrap: wrap;
    }

    .patient-file-action {
        flex-basis: 100%;
    }
}

@media (max-width: 760px) {
    .patient-files-table {
        display: none !important;
    }

    .patient-file-cards {
        display: grid;
        gap: 10px;
    }
}

.auth-logo {
    width: 82px;
    height: 82px;
    object-fit: contain;
    background: rgba(255, 255, 255, .94);
    border: 1px solid rgba(33, 29, 31, .12);
    padding: 8px;
}

.auth-card h1 {
    margin: 0;
    font-size: 2rem;
    letter-spacing: 0;
}

.auth-card p {
    margin: 0 0 6px;
    color: var(--muted);
    line-height: 1.55;
}

.preview-modal {
    width: min(980px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    border: 0;
    padding: 0;
    background: white;
}

.preview-modal::backdrop {
    background: rgba(0, 0, 0, .55);
}

.preview-body {
    min-height: 320px;
    max-height: calc(100vh - 110px);
    overflow: auto;
    padding: 16px;
    background: #f7f7f8;
}

.preview-frame {
    width: 100%;
    height: min(760px, calc(100vh - 150px));
    border: 1px solid var(--line);
    background: white;
}

.preview-image,
.preview-dicom-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
    background: #111;
}

.app-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    min-height: 100vh;
    background: #231f20;
    color: white;
    padding: 24px 16px;
}

.sidebar-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin: 0 0 24px 8px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(255, 255, 255, .22);
    padding: 8px;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.nav-button {
    justify-content: flex-start;
    text-align: left;
    background: transparent;
    color: white;
    border: 1px solid transparent;
}

.nav-button.active {
    background: var(--red);
}

.workspace {
    min-width: 0;
}

.topbar {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 28px;
    background: white;
    border-bottom: 1px solid var(--line);
}

.topbar strong {
    display: block;
    font-size: 1.08rem;
}

.topbar span {
    color: var(--muted);
    font-size: .88rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
}

.topbar-user span {
    font-weight: 700;
    white-space: nowrap;
}

.view {
    padding: 28px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.panel,
.metric {
    background: white;
    border: 1px solid var(--line);
    padding: 18px;
}

.panel h2,
.panel h3,
.metric h3 {
    margin: 0 0 14px;
    letter-spacing: 0;
}

.metric strong {
    display: block;
    font-size: 2rem;
}

.dashboard-chart {
    display: grid;
    gap: 16px;
}

.dashboard-chart p {
    margin: 0;
    color: var(--muted);
}

.dashboard-graphs {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(260px, .9fr);
    gap: 18px;
    align-items: stretch;
}

.dashboard-graph {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.dashboard-graph h3 {
    margin: 0;
}

.dashboard-svg {
    display: block;
    width: 100%;
    max-width: 100%;
}

.chart-axis {
    stroke: var(--text);
    stroke-width: 1.5;
}

.chart-grid {
    stroke: var(--line);
    stroke-width: 1;
}

.chart-column {
    fill: var(--red);
}

.chart-value,
.chart-label,
.chart-tick,
.donut-total,
.donut-caption {
    fill: var(--text);
    font-family: inherit;
}

.chart-value {
    font-size: 15px;
    font-weight: 800;
}

.chart-label,
.chart-tick,
.donut-caption {
    font-size: 13px;
}

.dashboard-donut-wrap {
    display: grid;
    grid-template-columns: minmax(150px, 220px) minmax(120px, 1fr);
    gap: 14px;
    align-items: center;
}

.dashboard-donut {
    max-width: 220px;
}

.donut-backdrop,
.donut-empty,
.donut-segment {
    fill: none;
    stroke-width: 26;
    transform: rotate(-90deg);
    transform-origin: 110px 110px;
}

.donut-backdrop {
    stroke: var(--soft);
}

.donut-empty {
    stroke: var(--line);
}

.donut-segment {
    stroke-linecap: butt;
}

.donut-total {
    font-size: 26px;
    font-weight: 850;
}

.dashboard-legend {
    display: grid;
    gap: 10px;
}

.dashboard-legend span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--text);
}

.dashboard-legend i {
    width: 12px;
    height: 12px;
    flex: 0 0 12px;
}

.dashboard-legend strong {
    margin-left: auto;
}

.dashboard-storage {
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

@media (max-width: 760px) {
    .dashboard-graphs,
    .dashboard-donut-wrap {
        grid-template-columns: 1fr;
    }
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}

.form-grid small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.35;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.info-grid div {
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--soft);
}

.info-grid span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: .86rem;
}

.two-factor-form {
    margin-top: 14px;
}

.authenticator-setup {
    display: grid;
    gap: 12px;
    margin-top: 14px;
}

.authenticator-setup[hidden] {
    display: none;
}

.authenticator-qr {
    width: 180px;
    height: 180px;
    padding: 10px;
    border: 1px solid var(--line);
    background: white;
    image-rendering: pixelated;
}

.upload-progress {
    grid-column: 1 / -1;
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--soft);
}

.upload-progress[hidden] {
    display: none;
}

.upload-progress-bar {
    height: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: white;
}

.upload-progress-bar span {
    display: block;
    width: 0%;
    height: 100%;
    background: var(--red);
    transition: width .2s ease;
}

.upload-progress strong {
    font-size: .9rem;
}

.upload-dropzone {
    grid-column: 1 / -1;
    display: grid;
    gap: 8px;
    justify-items: start;
    padding: 18px;
    border: 2px dashed var(--line);
    background: white;
}

.upload-dropzone.is-dragging {
    border-color: var(--red);
    background: #fff6f7;
}

.upload-dropzone span {
    color: var(--muted);
}

.upload-selection {
    grid-column: 1 / -1;
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--soft);
}

.upload-selection[hidden] {
    display: none;
}

.upload-selection ul {
    margin: 0;
    padding-left: 18px;
}

.upload-selection li {
    margin: 4px 0;
}

.upload-selection li span {
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.form-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
}

#user-form .actions,
#user-edit-form .actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
    margin-top: 4px;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.patient-file-actions {
    flex-wrap: nowrap;
    width: 100%;
}

.patient-file-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    min-width: 0;
    min-height: 38px;
    padding: 0 10px;
    border: 0;
    background: var(--red);
    color: white;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

.patient-file-action:visited,
.patient-file-action:hover {
    color: white;
}

.folder-back-row td {
    background: #f7f7f8;
}

.folder-back-button {
    justify-content: flex-start;
    border: 2px solid #231f20;
    background: #231f20;
    color: white;
    font-weight: 800;
    text-align: left;
}

.folder-back-button:hover {
    background: #231f20;
    color: white;
}

.folder-open-button {
    background: var(--red);
    color: white;
}

.pagination {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
    color: var(--muted);
    font-weight: 650;
}

.pagination button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.danger {
    background: #8f1d1d;
}

dialog {
    width: min(720px, calc(100vw - 32px));
    border: 1px solid var(--line);
    padding: 0;
    background: white;
    color: var(--ink);
    overflow: visible;
}

[hidden] {
    display: none !important;
}

.flatpickr-calendar {
    z-index: 2147483647;
}

dialog::backdrop {
    background: rgba(33, 29, 31, .48);
}

.modal-body {
    padding: 22px;
    overflow: visible;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    padding: 16px 22px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.icon-button {
    width: 38px;
    padding: 0;
    background: white;
    border: 1px solid var(--line);
    color: var(--ink);
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: .84rem;
}

.stack {
    display: grid;
    gap: 16px;
}

.folder-empty {
    color: var(--muted);
    font-weight: 650;
}

.opened-folder {
    display: grid;
    gap: 8px;
}

.opened-folder strong {
    font-size: 1.05rem;
}

.opened-folder span {
    color: var(--muted);
    font-weight: 650;
}

.link-button {
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--red);
    font: inherit;
    font-weight: 700;
    text-align: left;
    text-decoration: underline;
}

.link-button:hover {
    background: transparent;
    color: var(--red);
}

.status-ok {
    color: var(--ok);
}

.status-warn {
    color: var(--warn);
}

@media (max-width: 860px) {
    .app-page {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
    }

    .sidebar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .auth-shell,
    .view {
        padding: 20px;
    }
}

@media (max-width: 640px) {
    .auth-shell {
        align-items: start;
        padding: 16px;
    }

    .auth-card {
        gap: 14px;
        padding: 20px;
    }

    .auth-card h1 {
        font-size: 1.55rem;
    }

    .auth-logo {
        width: 68px;
        height: 68px;
    }

    #patient-files-path p {
        overflow-wrap: anywhere;
    }

    .patient-files-table {
        display: none !important;
    }

    .patient-file-cards {
        display: grid;
        gap: 10px;
    }

    .patient-file-name {
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .patient-file-name-button {
        width: 100%;
    }

    .patient-file-actions {
        flex-wrap: wrap;
    }

    .patient-file-action {
        flex-basis: 100%;
    }

    .patient-folder-back-row {
        padding: 0;
        border: 0;
        background: transparent;
    }

    .patient-folder-back-row button {
        width: 100%;
    }
}
