:root {
    --bg-app: #0f0f11;
    --bg-panel: #18181b;
    --bg-hover: #27272a;
    --border-color: #27272a;
    --accent: #6366f1;
    --text-main: #e4e4e7;
    --text-muted: #a1a1aa;
    --glass-bg: rgba(24, 24, 27, 0.6);
    --glass-border: rgba(255, 255, 255, 0.05);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.glass-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: relative;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 18px;
    color: var(--text-main);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

/* Main Layout */
.main-layout {
    flex: 1;
    display: grid;
    /* Columns: Patients | Splitter | Studies | Splitter | Viewer */
    grid-template-columns: 240px 4px 280px 4px 1fr;
    gap: 0;
    background: var(--bg-app);
    overflow: hidden;
}

.splitter {
    background: var(--border-color);
    cursor: col-resize;
    transition: background 0.2s;
    z-index: 10;
}

.splitter:hover,
.splitter.active {
    background: var(--accent);
}

.panel {
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.02);
}

.panel-header h2 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* Collapsible patients panel */
.panel-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.panel-header-row h2 {
    margin-bottom: 0;
}

.collapse-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    width: 24px;
    height: 24px;
    font-size: 11px;
    line-height: 1;
    flex-shrink: 0;
    transition: all 0.15s;
}

.collapse-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
    border-color: var(--accent);
}

.sidebar-patients.collapsed .panel-header {
    padding: 12px 6px;
}

.sidebar-patients.collapsed .panel-header-row {
    justify-content: center;
}

.sidebar-patients.collapsed .panel-header h2,
.sidebar-patients.collapsed #patientSearch,
.sidebar-patients.collapsed .patient-list {
    display: none;
}

/* Search Input */
input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: var(--accent);
}

/* Lists */
.patient-list,
.studies-container {
    flex: 1;
    overflow-y: auto;
}

.patient-item,
.study-item,
.series-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.patient-item:hover,
.study-item:hover,
.series-item:hover {
    background: var(--bg-hover);
}

.patient-item.active,
.study-item.active,
.series-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--accent);
}

.item-title {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
}

.item-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

/* Components Helper */
.loading-spinner,
.empty-state {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Middle Panel: Studies Hierarchy */
.series-group {
    padding-left: 20px;
}

.study-item {
    background: #202025;
}

/* Viewer */
.right-viewer {
    background: #000;
    display: flex;
    flex-direction: column;
}

/* Viewer Toolbar */
.right-viewer .panel-header {
    background: var(--bg-panel);
}

.tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    padding: 6px 14px;
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
    border-color: #3f3f46;
}

.tool-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

.tool-btn-reset {
    margin-left: auto;
    color: #f87171;
}

.tool-sep {
    width: 1px;
    align-self: stretch;
    min-height: 20px;
    background: var(--border-color);
    margin: 0 2px;
}

.viewer-canvas {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.viewer-canvas img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.film-strip {
    height: 100px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    overflow-x: auto;
}

.thumbnail {
    height: 80px;
    width: 80px;
    background: #000;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    flex-shrink: 0;
    cursor: pointer;
    overflow: hidden;
}

.thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.thumbnail:hover img,
.thumbnail.active img {
    opacity: 1;
}

.thumbnail.active {
    border-color: var(--accent);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}


::-webkit-scrollbar-thumb:hover {
    background: #52525b;
}

/* Magnifier Lens */
.magnifier-lens {
    position: absolute;
    width: 200px;
    height: 200px;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: none;
    pointer-events: none;
    /* Allows clicks to pass through if needed, though we track mouse */
    background-repeat: no-repeat;
    background-color: #000;
    /* Fallback */
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    /* Hidden by default */
}

/* Measurements (length / angle / ROI) */
.measure-line {
    stroke: #00ff00;
    stroke-width: 2px;
    vector-effect: non-scaling-stroke;
    /* Keep line width constant on zoom */
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 1));
}

.measure-roi {
    stroke: #00ff00;
    stroke-width: 2px;
    vector-effect: non-scaling-stroke;
    fill: rgba(0, 255, 0, 0.08);
    filter: drop-shadow(0 0 2px rgba(0, 0, 0, 1));
}

.measure-text {
    fill: #00ff00;
    font-size: 14px;
    font-weight: bold;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, 0.9);
    stroke-width: 3px;
    pointer-events: none;
}

/* --- oturum --- */
.logout-btn { margin-left: 10px; font-size: 12px; color: #cbd5e1; text-decoration: none; padding: 4px 10px; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; }
.logout-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); backdrop-filter: blur(14px); border-radius: 18px; padding: 2rem 1.75rem; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.login-card .logo { justify-content: center; margin-bottom: .4rem; }
.login-card .logo span { font-size: 1.15rem; }
.login-card .sub { text-align: center; color: #94a3b8; font-size: .82rem; margin-bottom: 1.5rem; }
.login-card label { display: block; font-size: .78rem; color: #cbd5e1; margin: .8rem 0 .3rem; font-weight: 500; }
.login-card input { width: 100%; padding: .65rem .8rem; border-radius: 10px; border: 1px solid rgba(255,255,255,.15); background: rgba(0,0,0,.25); color: #fff; font: inherit; box-sizing: border-box; }
.login-card input:focus { outline: none; border-color: #818cf8; box-shadow: 0 0 0 3px rgba(129,140,248,.25); }
.login-card button { width: 100%; margin-top: 1.3rem; padding: .7rem; border: 0; border-radius: 10px; background: linear-gradient(135deg, #4f46e5, #6366f1); color: #fff; font-weight: 600; font: inherit; cursor: pointer; }
.login-card button:hover { filter: brightness(1.1); }
.login-card .err { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.35); color: #fecaca; font-size: .8rem; padding: .55rem .8rem; border-radius: 10px; margin-top: .9rem; }
.login-card .hint { margin-top: 1.2rem; font-size: .74rem; color: #94a3b8; text-align: center; }
.login-card .hint a { color: #c7d2fe; }

/* ===================== Gelişmiş viewer (viewer.js) ===================== */
.glass-header { padding: 0 16px; }
.header-mid { flex: 1; text-align: center; font-size: 12px; color: var(--text-muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 12px; }
.hdr-btn { background: transparent; border: 1px solid rgba(255,255,255,.15); color: #cbd5e1; border-radius: 8px; width: 30px; height: 28px; cursor: pointer; font-size: 13px; }
.hdr-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.right-viewer { position: relative; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--glass-border); background: rgba(255,255,255,.02); }
.tb-group { display: flex; align-items: center; gap: 3px; padding-right: 10px; border-right: 1px solid var(--border-color); }
.tb-group:last-child { border-right: 0; }
.tb-label { font-size: 11px; color: var(--text-muted); min-width: 44px; }
.toolbar input[type=range] { width: 70px; accent-color: var(--accent); }
.tool-btn { font-size: 12px; padding: 5px 9px; }
.tool-btn.on { background: rgba(99,102,241,.25); border-color: var(--accent); color: #c7d2fe; }
.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; top: 110%; left: 0; z-index: 40; background: #1f1f23; border: 1px solid var(--border-color); border-radius: 10px; padding: 6px; min-width: 230px; box-shadow: 0 12px 30px rgba(0,0,0,.5); }
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button { display: flex; justify-content: space-between; width: 100%; background: transparent; border: 0; color: var(--text-main); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; text-align: left; }
.dropdown-menu button:hover { background: var(--bg-hover); }
.dropdown-menu button span { color: var(--text-muted); font-family: ui-monospace, monospace; font-size: 11px; }
.dropdown-menu .dd-title { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); padding: 6px 10px 2px; }

.viewports { flex: 1; display: grid; gap: 2px; background: #000; overflow: hidden; min-height: 0; }
.viewports[data-layout="1x1"] { grid-template-columns: 1fr; }
.viewports[data-layout="1x2"] { grid-template-columns: 1fr 1fr; }
.viewports[data-layout="2x2"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.viewports[data-layout="mpr"] { grid-template-columns: 1fr 1fr 1fr; }
.vp { position: relative; background: #000; overflow: hidden; border: 1px solid #1f1f23; cursor: crosshair; user-select: none; }
.vp.active { border-color: var(--accent); }
.vp canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.vp .corner { position: absolute; font-size: 11px; line-height: 1.45; color: #d4d4d8; text-shadow: 0 0 3px #000, 0 0 2px #000; pointer-events: none; font-family: 'Inter', sans-serif; white-space: pre; }
.vp .tl { top: 6px; left: 8px; } .vp .tr { top: 6px; right: 8px; text-align: right; }
.vp .bl { bottom: 6px; left: 8px; } .vp .br { bottom: 6px; right: 8px; text-align: right; }
.vp .corner b { color: #fff; font-weight: 600; }
.vp .plane-tag { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 600; letter-spacing: .5px; color: #a5b4fc; text-shadow: 0 0 3px #000; pointer-events: none; }
.vp .vp-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: 13px; pointer-events: none; }
.vp .vp-loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 12px; color: #c7d2fe; background: rgba(0,0,0,.5); padding: 6px 12px; border-radius: 8px; pointer-events: none; }
.vp .note-input { position: absolute; z-index: 5; background: #18181b; color: #fff; border: 1px solid var(--accent); border-radius: 6px; padding: 4px 8px; font-size: 12px; outline: none; }
.magnifier { position: absolute; width: 180px; height: 180px; border-radius: 50%; border: 2px solid var(--accent); box-shadow: 0 8px 24px rgba(0,0,0,.6); overflow: hidden; pointer-events: none; z-index: 6; background: #000; }
.magnifier canvas { width: 100%; height: 100%; }

.film-strip { min-height: 92px; }
.viewports[data-layout="mpr"] ~ .film-strip { display: none; }

.modal[hidden], .vp-empty[hidden] { display: none; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 100; }
.modal-card { width: min(860px, 94vw); max-height: 86vh; background: #18181b; border: 1px solid var(--border-color); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; }
.modal-card.small { width: min(680px, 94vw); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-color); font-weight: 600; }
.modal-head span { flex: 1; }
.modal-head input { background: #0f0f11; border: 1px solid var(--border-color); color: #fff; border-radius: 6px; padding: 4px 8px; font-size: 12px; }
.modal-body { overflow: auto; padding: 8px 14px; font-size: 12px; }
.modal-body table { width: 100%; border-collapse: collapse; }
.modal-body td { padding: 3px 6px; border-bottom: 1px solid #202024; vertical-align: top; font-family: ui-monospace, monospace; font-size: 11px; }
.modal-body td:nth-child(2) { color: #a5b4fc; font-family: 'Inter', sans-serif; }
.modal-body td:nth-child(4) { word-break: break-all; }
.modal-body.help div { padding: 6px 0; border-bottom: 1px solid #202024; line-height: 1.6; }
.modal-body.help b { color: #c7d2fe; }
.toast { position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); background: rgba(24,24,27,.95); border: 1px solid var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 12px; z-index: 120; }
