/* ============================================================
   CPR Quality Evaluation — PACS-Style Medical Imaging Theme
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --bg-primary: #000000;
    --bg-panel: #0a0a0a;
    --bg-header: rgba(10, 10, 10, 0.92);
    --bg-toolbar: #111111;
    --border: #1a1a1a;
    --border-active: #333333;
    --text-primary: #e0e0e0;
    --text-secondary: #888888;
    --text-muted: #555555;
    --color-axial: #22b8cf;
    --color-coronal: #51cf66;
    --color-sagittal: #be4bdb;
    --color-cpr: #fcc419;
    --crosshair-h: rgba(34, 184, 207, 0.5);
    --crosshair-v: rgba(81, 207, 102, 0.5);
    --crosshair-3: rgba(190, 75, 219, 0.5);
    --accent-blue: #4dabf7;
    --accent-red: #ff6b6b;
    --accent-green: #51cf66;
    --shadow: 0 2px 8px rgba(0,0,0,0.5);
    --radius: 4px;
    --transition: all 0.2s ease;
    --gap: 2px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.4;
    user-select: none;
}

/* ── Top Toolbar ─────────────────────────────────────── */
.toolbar {
    height: 36px;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 4px;
    z-index: 100;
}

.toolbar-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-right: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.toolbar-title .icon {
    font-size: 1rem;
}

.btn {
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    background: #1a1a1a;
    color: var(--text-primary);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1.4;
}

.btn:hover {
    background: #252525;
    border-color: var(--border-active);
}

.btn:active { opacity: 0.8; }

.btn-primary {
    background: #1864ab;
    border-color: #1971c2;
    color: white;
}

.btn-primary:hover {
    background: #1971c2;
}

.btn-danger {
    color: var(--accent-red);
    border-color: #462020;
}

.btn-danger:hover {
    background: #2a1515;
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.toolbar-input {
    font-family: inherit;
    font-size: 0.7rem;
    padding: 2px 6px;
    background: #1a1a1a;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    width: 55px;
    outline: none;
}

.toolbar-input:focus {
    border-color: var(--accent-blue);
}

.toolbar-select {
    font-family: inherit;
    font-size: 0.7rem;
    padding: 2px 18px 2px 6px;
    background: #1a1a1a;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 4l3 3 3-3' stroke='%23888' fill='none' stroke-width='1.2'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 4px center;
}

.point-badge {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--color-cpr);
    padding: 2px 8px;
    background: rgba(252,196,25,0.1);
    border-radius: 10px;
    border: 1px solid rgba(252,196,25,0.2);
}

/* ── Main PACS Layout ────────────────────────────────── */
/*
   ┌──────────┬─────────────────┬──────────┐
   │  Axial   │                 │          │
   │  (small) │    Coronal      │   CPR    │
   ├──────────┤    (large)      │  Result  │
   │ Sagittal │                 │          │
   │  (small) │                 │          │
   └──────────┴─────────────────┴──────────┘
*/
.pacs-layout {
    display: grid;
    grid-template-columns: 28% 1fr 28%;
    grid-template-rows: 1fr 1fr;
    gap: var(--gap);
    height: calc(100vh - 36px);
    background: var(--bg-primary);
}

.panel-axial {
    grid-column: 1;
    grid-row: 1;
}

.panel-sagittal {
    grid-column: 1;
    grid-row: 2;
}

.panel-coronal {
    grid-column: 2;
    grid-row: 1 / 3;
}

.panel-cpr {
    grid-column: 3;
    grid-row: 1 / 3;
}

/* ── Viewport Panel ──────────────────────────────────── */
.viewport {
    background: #000;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.viewport:hover {
    border-color: var(--border-active);
}

/* Viewport overlay info — positioned at corners like PACS */
.vp-overlay {
    position: absolute;
    z-index: 10;
    pointer-events: none;
    font-size: 0.68rem;
    font-weight: 500;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.7);
    line-height: 1.5;
}

.vp-overlay-tl {
    top: 6px;
    left: 8px;
}

.vp-overlay-tr {
    top: 6px;
    right: 8px;
    text-align: right;
}

.vp-overlay-bl {
    bottom: 30px;
    left: 8px;
}

.vp-overlay-br {
    bottom: 30px;
    right: 8px;
    text-align: right;
}

/* Color-coded viewport labels */
.vp-label-axial { color: var(--color-axial); }
.vp-label-coronal { color: var(--color-coronal); }
.vp-label-sagittal { color: var(--color-sagittal); }
.vp-label-cpr { color: var(--color-cpr); }

.vp-text-dim { color: var(--text-muted); }
.vp-text { color: #aaa; }

/* Letter annotations (R, L, A, P, S, I) */
.vp-letter {
    position: absolute;
    z-index: 10;
    font-size: 0.75rem;
    font-weight: 700;
    pointer-events: none;
    text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}

.vp-letter-left   { left: 6px;  top: 50%; transform: translateY(-50%); color: var(--accent-red); }
.vp-letter-right  { right: 6px; top: 50%; transform: translateY(-50%); color: var(--accent-red); }
.vp-letter-top    { top: 6px;   left: 50%; transform: translateX(-50%); color: var(--accent-green); }
.vp-letter-bottom { bottom: 30px; left: 50%; transform: translateX(-50%); color: var(--accent-green); }

/* Canvas container */
.vp-canvas-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.vp-canvas {
    max-width: 100%;
    max-height: 100%;
    image-rendering: pixelated;
    cursor: crosshair;
    display: block;
}

.vp-canvas.cpr-canvas {
    image-rendering: auto;
    cursor: default;
}

/* Crosshair lines */
.crosshair-h {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    pointer-events: none;
    z-index: 5;
    opacity: 0.6;
}

.crosshair-v {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    pointer-events: none;
    z-index: 5;
    opacity: 0.6;
}

/* Axial crosshairs: blue horizontal, green vertical */
.panel-axial .crosshair-h { background: #4dabf7; }
.panel-axial .crosshair-v { background: #51cf66; }

/* Coronal crosshairs: blue horizontal, red vertical */
.panel-coronal .crosshair-h { background: #4dabf7; }
.panel-coronal .crosshair-v { background: #ff6b6b; }

/* Sagittal crosshairs: green horizontal, red vertical */
.panel-sagittal .crosshair-h { background: #51cf66; }
.panel-sagittal .crosshair-v { background: #ff6b6b; }

/* ── Bottom slider bar ───────────────────────────────── */
.vp-slider-bar {
    height: 24px;
    background: rgba(17,17,17,0.9);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.vp-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 3px;
    background: #222;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.vp-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: var(--transition);
}

.vp-slider::-webkit-slider-thumb:hover {
    background: #fff;
    transform: scale(1.3);
}

.vp-slider-label {
    font-size: 0.62rem;
    color: var(--text-secondary);
    min-width: 44px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.vp-slider-bar .vp-text-dim {
    font-size: 0.6rem;
}

/* ── Empty State ─────────────────────────────────────── */
.vp-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
    padding: 16px;
    width: 100%;
    height: 100%;
}

.vp-empty-icon {
    font-size: 2rem;
    opacity: 0.4;
}

/* ── Loading Overlay ─────────────────────────────────── */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: #ccc;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ── Upload Modal ────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 24px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.modal h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.upload-zone {
    border: 2px dashed #333;
    border-radius: 8px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 14px;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-blue);
    background: rgba(77,171,247,0.05);
}

.upload-zone .upload-icon {
    font-size: 2rem;
    margin-bottom: 6px;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
}

/* ── Toast Notifications ─────────────────────────────── */
.toast-container {
    position: fixed;
    top: 42px;
    right: 12px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.toast {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: var(--radius);
    padding: 8px 14px;
    font-size: 0.75rem;
    box-shadow: var(--shadow);
    animation: slideIn 0.25s ease;
    max-width: 300px;
}

.toast.error { border-left: 3px solid var(--accent-red); color: var(--accent-red); }
.toast.success { border-left: 3px solid var(--accent-green); color: var(--accent-green); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1000px) {
    .pacs-layout {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
    }
    .panel-coronal { grid-column: 2; grid-row: 1; }
    .panel-cpr { grid-column: 2; grid-row: 2; }
}
