:root {
    --ink: #12212a;
    --muted: #58707d;
    --paper: #f4fbff;
    --green: #3fb47f;
    --coral: #e9695f;
    --line: rgba(18, 33, 42, .12);
    --shadow: 0 24px 70px rgba(26, 60, 76, .18);
    --display-scale: 1;
    --display-height: 1080px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    background: #d9eff7;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

body {
    overflow-x: auto;
}

.sound-toggle {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 20;
    border: 0;
    border-radius: 8px;
    padding: 12px 16px;
    background: #31576a;
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(18, 33, 42, .22);
}

.sound-toggle.is-on {
    background: var(--green);
}

.tv-frame {
    display: grid;
    grid-template-columns: 1280px 640px;
    grid-template-rows: 840px 240px;
    width: 1920px;
    height: 1080px;
    margin: 0 auto;
    background: var(--paper);
}

.grid-one,
.grid-two {
    position: relative;
    overflow: hidden;
}

.grid-one {
    grid-column: 1;
    grid-row: 1;
    background: #e9f8fb;
}

.grid-two {
    grid-column: 1;
    grid-row: 2;
    background: #152b38;
    border-top: 1px solid var(--line);
}

.grid-three {
    grid-column: 2;
    grid-row: 1 / span 2;
    overflow: hidden;
    border-left: 1px solid var(--line);
    background: #f8fdff;
}

.slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity .8s ease;
}

.slide.is-active {
    opacity: 1;
    z-index: 1;
}

.image-slide {
    background: #12212a;
}

.image-slide img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.empty-slide {
    background: #152b38;
}

.patient-board {
    position: relative;
    display: flex;
    min-height: 100%;
    flex-direction: column;
    padding: 28px 30px;
    background: linear-gradient(180deg, #ffffff, #edf9fb);
}

.current-watermark {
    position: absolute;
    right: 24px;
    bottom: 12px;
    z-index: 0;
    color: rgba(18, 33, 42, .055);
    font-size: 360px;
    font-weight: 900;
    line-height: .8;
    pointer-events: none;
}

.patient-board > *:not(.current-watermark) {
    position: relative;
    z-index: 1;
}

.patient-board h1 {
    margin: 0;
    font-size: 50px;
    line-height: 1.03;
    letter-spacing: 0;
}

.patient-board .doctor-name {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 27px;
    line-height: 1.25;
}

.date-time-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-top: 0;
    padding: 15px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.date-stack {
    display: grid;
    min-width: 0;
    gap: 3px;
}

.date-time-box span {
    display: block;
    color: var(--ink);
    font-size: 26px;
    font-weight: 900;
    line-height: 1;
}

.date-time-box small {
    display: block;
    color: var(--muted);
    font-size: 18px;
    font-weight: 750;
    line-height: 1.15;
}

.date-time-box strong {
    display: block;
    flex: 0 0 auto;
    margin-top: 0;
    font-size: 42px;
    white-space: nowrap;
    line-height: 1;
}

.current-card {
    display: grid;
    gap: 10px;
    margin-top: 20px;
    padding: 22px 26px;
    border-radius: 8px;
    background: var(--coral);
    color: #ffffff;
    box-shadow: var(--shadow);
}

.current-card.mode-hold {
    background: #f5b84b;
    color: #12212a;
}

.current-card.mode-emergency {
    background: #c92828;
}

.current-card span {
    font-size: 24px;
    font-weight: 800;
    text-transform: uppercase;
}

.current-card strong {
    display: block;
    font-size: 150px;
    line-height: 1;
}

.patient-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 22px;
}

.serial-cell {
    min-height: 118px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.serial-cell span {
    display: block;
    color: var(--muted);
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
}

.serial-cell strong {
    display: block;
    margin-top: 14px;
    font-size: 36px;
    line-height: 1;
}

.queue-list {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    margin-top: 22px;
}

.queue-list h2 {
    margin: 0;
    color: var(--muted);
    font-size: 21px;
    text-transform: uppercase;
}

.queue-table {
    width: 100%;
    margin-top: 10px;
    table-layout: fixed;
    border-collapse: collapse;
    overflow: hidden;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: inset 0 0 0 1px var(--line);
}

.queue-table th,
.queue-table td {
    border-bottom: 1px solid var(--line);
    padding: 11px 8px;
    text-align: left;
    font-size: 22px;
    line-height: 1.15;
}

.queue-table th {
    color: var(--muted);
    font-size: 15px;
    text-transform: uppercase;
}

.queue-table .serial-column {
    width: 9%;
}

.queue-table .patient-column {
    width: 38%;
}

.queue-table .mobile-column {
    width: 28%;
}

.queue-table .category-column {
    width: 25%;
}

.queue-table th:first-child,
.queue-table td:first-child {
    padding-right: 12px;
    padding-left: 8px;
}

.queue-table th:nth-child(2),
.queue-table td:nth-child(2) {
    padding-left: 12px;
}

.queue-table th + th {
    border-left: 1px solid #e8eff2;
}

.queue-table td:first-child {
    color: #24555d;
    font-size: 26px;
    font-weight: 800;
}

.queue-table td:nth-child(4) {
    color: var(--muted);
    font-size: 20px;
    font-weight: 700;
}

.queue-table th:nth-child(2),
.queue-table td:nth-child(2) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-badge {
    display: inline-flex;
    min-width: 66px;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 9px;
    background: #e4f5ee;
    color: #1e7855;
    font-size: 15px;
    font-weight: 900;
    line-height: 1;
}

.category-badge.category-fibroscan {
    background: #fff0d5;
    color: #915b00;
}

.queue-table tr:last-child td {
    border-bottom: 0;
}

.empty-queue {
    margin-top: 14px;
    color: var(--muted);
    font-size: 22px;
}

.admin-page {
    padding: 28px 0 60px;
    overflow-x: hidden;
}

.admin-panel {
    width: min(1100px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
}

.admin-panel h1 {
    margin: 0 0 18px;
    font-size: 32px;
}

.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f8fdff;
    color: var(--muted);
    font-weight: 700;
}

.admin-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.admin-form + .admin-form {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 2px solid var(--line);
}

.admin-form label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
}

.admin-form input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
    color: var(--ink);
    font-size: 18px;
}

.admin-form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 14px;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 18px;
    line-height: 1.4;
    resize: vertical;
}

.admin-form input[type="file"] {
    min-height: 52px;
    background: #f8fdff;
}

.patient-entry-table {
    display: grid;
    gap: 8px;
}

.patient-entry-row {
    display: grid;
    grid-template-columns: 74px minmax(0, 1fr) 210px auto;
    align-items: center;
    gap: 10px;
}

.patient-entry-row span {
    display: grid;
    height: 48px;
    place-items: center;
    border-radius: 8px;
    background: #e7f6f3;
    color: #24555d;
    font-size: 20px;
    font-weight: 800;
}

.admin-section {
    grid-column: 1 / -1;
    display: grid;
    gap: 14px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.date-filter {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
}

.login-panel {
    width: min(520px, calc(100% - 32px));
    margin: 60px auto;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
}

.login-panel h1 {
    margin: 0 0 18px;
}

.notice.error {
    background: #fde8e6;
    color: #8f231b;
}

.admin-section h2 {
    margin: 0;
    font-size: 22px;
}

.admin-block {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fdff;
}

.admin-note {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.4;
}

.slide-manager {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.slide-thumb {
    display: grid;
    gap: 8px;
    align-content: start;
    position: relative;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fdff;
    transition: opacity 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.slide-thumb.is-dragging {
    opacity: 0.55;
    transform: scale(0.98);
    border-color: var(--green);
}

.slide-thumb img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 6px;
    background: #d9eff7;
}

.slide-thumb.bottom img {
    aspect-ratio: 16 / 3;
}

.slide-thumb label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    text-transform: none;
}

.slide-thumb input[type="checkbox"] {
    width: 18px;
    height: 18px;
    padding: 0;
}

.icon-button,
button.icon-button {
    display: inline-grid;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    place-items: center;
    padding: 0;
    line-height: 1;
}

.icon-button span {
    display: block;
    font-size: 21px;
    line-height: 1;
}

.remove-item-button,
button.remove-item-button,
.remove-all-button,
button.remove-all-button {
    background: #c92828;
}

button.serial-delete-button {
    border: 1px solid #efb5b0;
    border-radius: 10px;
    background: #fff1f0;
    color: #b42318;
    transition: color .15s ease, background .15s ease, border-color .15s ease, transform .15s ease;
}

button.serial-delete-button:hover {
    border-color: #c92828;
    background: #c92828;
    color: #ffffff;
    transform: translateY(-1px);
}

button.serial-delete-button:active {
    transform: translateY(0);
}

.serial-delete-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.drag-handle,
button.drag-handle {
    background: #31576a;
    cursor: grab;
}

.drag-handle:active {
    cursor: grabbing;
}

.slide-card-controls {
    display: flex;
    gap: 6px;
    position: absolute;
    z-index: 2;
    top: 16px;
    right: 16px;
}

.slider-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.empty-state {
    margin: 0;
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: #f8fdff;
    color: var(--muted);
    text-align: center;
}

.admin-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
}

button,
.admin-link {
    border: 0;
    border-radius: 8px;
    padding: 13px 18px;
    background: var(--green);
    color: #ffffff;
    font-size: 16px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

button.secondary,
.admin-link.secondary {
    background: #31576a;
}

button.hold {
    background: #c78317;
}

button.emergency {
    background: #c92828;
}

.notice {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #e7f6f3;
    color: #20534b;
    font-weight: 700;
}

body:not(.admin-page) {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
    background: #0d1f2a;
}

body:not(.admin-page) .tv-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    margin: 0;
    transform: translate(-50%, -50%) scale(var(--display-scale));
    transform-origin: center center;
}

/* Simplified backend */
.admin-page {
    min-height: 100vh;
    padding: 32px 0 64px;
    overflow-x: hidden;
    background:
        radial-gradient(circle at top left, rgba(63, 180, 127, .18), transparent 34%),
        linear-gradient(180deg, #eef9fc 0%, #f7fbfd 100%);
}

.backend-shell {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto;
}

.backend-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 14px;
    padding: 28px;
    border: 1px solid rgba(18, 33, 42, .08);
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 18px 55px rgba(26, 60, 76, .11);
}

.backend-header h1 {
    margin: 3px 0 8px;
    font-size: clamp(30px, 4vw, 46px);
    line-height: 1;
}

.backend-header p {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
}

.eyebrow {
    margin: 0;
    color: #25805d !important;
    font-size: 12px !important;
    font-weight: 900;
    letter-spacing: .13em;
    text-transform: uppercase;
}

.backend-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.admin-link.quiet {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
}

.user-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 2px 14px;
    color: var(--muted);
    font-weight: 800;
}

.role-badge {
    padding: 5px 9px;
    border-radius: 999px;
    background: #dff5ec;
    color: #1f7655;
    font-size: 12px;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.backend-shell > .notice {
    position: sticky;
    z-index: 20;
    top: 10px;
    margin-bottom: 14px;
    border: 1px solid rgba(32, 83, 75, .13);
    box-shadow: 0 12px 30px rgba(26, 60, 76, .1);
}

.serial-form {
    display: grid;
    gap: 18px;
}

.serial-control-panel {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 20px;
    position: sticky;
    z-index: 10;
    top: 10px;
    padding: 20px;
    border: 1px solid rgba(18, 33, 42, .09);
    border-radius: 18px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 18px 55px rgba(26, 60, 76, .15);
    backdrop-filter: blur(12px);
}

.running-serial-card {
    display: grid;
    min-height: 154px;
    place-items: center;
    align-content: center;
    padding: 14px;
    border-radius: 14px;
    background: linear-gradient(145deg, #2f9f72, #237756);
    color: #ffffff;
    text-align: center;
}

.running-serial-card.mode-hold {
    background: linear-gradient(145deg, #d39932, #a86b0d);
}

.running-serial-card.mode-emergency {
    background: linear-gradient(145deg, #dd4b45, #a71e1e);
}

.running-serial-card > span {
    font-size: 14px;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.running-serial-card strong {
    font-size: 72px;
    line-height: .95;
}

.running-serial-card small {
    margin-top: 8px;
    font-weight: 700;
}

.serial-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: 10px;
    align-content: center;
}

.serial-actions button {
    min-height: 54px;
}

.serial-actions .save-action {
    background: #176c95;
}

.live-meta {
    display: flex;
    grid-column: 2;
    gap: 18px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 13px;
}

.backend-card {
    display: grid;
    gap: 20px;
    padding: 24px;
    border: 1px solid rgba(18, 33, 42, .09);
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 14px 40px rgba(26, 60, 76, .08);
}

.section-title {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.section-title h2 {
    margin: 3px 0 5px;
    font-size: 25px;
}

.section-title p {
    margin: 0;
    color: var(--muted);
}

.field-grid,
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.settings-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid label,
.settings-grid label,
.serial-form label,
.auto-upload-form label {
    display: grid;
    gap: 7px;
    color: #35505f;
    font-size: 13px;
    font-weight: 900;
    letter-spacing: .03em;
}

.field-grid input,
.settings-grid input,
.serial-form input,
.serial-form select {
    width: 100%;
    min-height: 48px;
    border: 1px solid #ccdae1;
    border-radius: 10px;
    padding: 11px 13px;
    background: #fbfdfe;
    color: var(--ink);
    font-size: 17px;
    outline: none;
}

.field-grid input:focus,
.settings-grid input:focus,
.serial-form input:focus,
.serial-form select:focus {
    border-color: #3fb47f;
    box-shadow: 0 0 0 3px rgba(63, 180, 127, .14);
}

.settings-grid small,
.upload-dropzone small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.settings-actions {
    display: flex;
    grid-column: 1 / -1;
    gap: 10px;
    flex-wrap: wrap;
}

.compact-filter {
    max-width: 740px;
    grid-template-columns: minmax(220px, 1fr) auto auto;
}

.print-date-button {
    background: #237756;
}

.add-row-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 2px;
}

.add-row-footer button {
    min-width: 190px;
}

.patient-entry-table {
    gap: 10px;
}

.patient-entry-row {
    grid-template-columns: 58px minmax(0, 1fr) 140px minmax(180px, 240px) 42px;
    padding: 8px;
    border: 1px solid #e0eaee;
    border-radius: 12px;
    background: #fbfdfe;
}

.patient-entry-row > span {
    height: 48px;
    border-radius: 10px;
}

.file-field {
    max-width: 620px;
    padding-top: 4px;
}

.slider-workspace + .slider-workspace {
    margin-top: 18px;
}

.backend-card + .backend-card {
    margin-top: 18px;
}

.upload-dropzone {
    position: relative;
    padding: 24px;
    border: 2px dashed #9ecab9;
    border-radius: 14px;
    background: #f4fbf8;
    text-align: center;
    cursor: pointer;
}

.upload-dropzone > span {
    color: #216e51;
    font-size: 18px;
}

.upload-dropzone input {
    width: 100%;
    margin-top: 10px;
}

.slide-order-form {
    display: grid;
    gap: 14px;
}

.slide-manager {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.slide-thumb {
    min-width: 0;
    padding: 10px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(26, 60, 76, .08);
}

.slide-card-controls {
    top: 16px;
    right: 16px;
}

.empty-state {
    padding: 30px;
    border-radius: 12px;
}

button:disabled {
    opacity: .55;
    cursor: wait;
}

button:focus-visible,
.admin-link:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(23, 108, 149, .25);
    outline-offset: 2px;
}

@media (max-width: 900px) {
    .backend-header,
    .section-title {
        align-items: stretch;
        flex-direction: column;
    }

    .backend-nav {
        justify-content: flex-start;
    }

    .serial-control-panel {
        grid-template-columns: 1fr;
        position: static;
    }

    .live-meta {
        grid-column: 1;
    }

    .serial-actions,
    .settings-grid,
    .field-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .patient-entry-row {
        grid-template-columns: 48px minmax(0, 1fr) 42px;
    }

    .patient-entry-row select[name="patient_categories[]"] {
        grid-column: 2;
    }

    .patient-entry-row input[name="patient_mobiles[]"] {
        grid-column: 2;
    }

    .patient-entry-row .icon-button {
        grid-column: 3;
        grid-row: 1 / span 3;
    }

    .compact-filter {
        max-width: none;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .compact-filter label {
        grid-column: 1 / -1;
    }

    .compact-filter button {
        width: 100%;
    }
}

@media (max-width: 560px) {
    .admin-page {
        padding-top: 14px;
    }

    .backend-shell {
        width: min(100% - 20px, 1280px);
    }

    .backend-header,
    .backend-card,
    .serial-control-panel {
        padding: 16px;
        border-radius: 14px;
    }

    .serial-actions,
    .settings-grid,
    .field-grid,
    .slide-manager {
        grid-template-columns: 1fr;
    }

    .backend-nav .admin-link {
        flex: 1 1 auto;
        text-align: center;
    }

    .add-row-footer button {
        width: 100%;
    }
}
