/* ==========================================================================
   VascularClick Web – Dark-Mode Design System
   ========================================================================== */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Core palette */
    --bg-primary:     #0d1117;
    --bg-secondary:   #161b22;
    --bg-tertiary:    #1c2128;
    --bg-elevated:    #21262d;
    --bg-hover:       #292e36;

    --text-primary:   #e6edf3;
    --text-secondary: #8b949e;
    --text-muted:     #484f58;

    --border:         #30363d;
    --border-light:   #21262d;

    /* Accent colors */
    --accent:         #58a6ff;
    --accent-hover:   #79c0ff;
    --accent-dim:     rgba(88, 166, 255, 0.15);

    /* Semantic */
    --success:        #3fb950;
    --success-dim:    rgba(63, 185, 80, 0.15);
    --warning:        #d29922;
    --warning-dim:    rgba(210, 153, 34, 0.15);
    --danger:         #f85149;
    --danger-dim:     rgba(248, 81, 73, 0.15);

    /* Zone colors */
    --zone-rim:       #f97583;
    --zone-a:         #ff7b72;
    --zone-b:         #ffa657;
    --zone-c:         #79c0ff;
    --quadrant-line:  #f0e68c;

    /* Vessel */
    --artery-color:   #f97583;
    --vein-color:     #79c0ff;
    --marker-papilla: #ff6b6b;
    --marker-rim:     #6cb4ee;
    --marker-macula:  #3fb950;
    --marker-vessel:  #f0e68c;

    /* Sizes */
    --header-h:       56px;
    --sidebar-w:      280px;
    --toolbar-h:      52px;
    --radius:         8px;
    --radius-sm:      6px;
    --radius-lg:      12px;

    /* Fonts */
    --font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:      'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

    /* Transitions */
    --transition:     0.2s ease;
    --transition-slow: 0.35s ease;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---------- Login Overlay ---------- */
#login-overlay,
#users-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
}
#login-overlay { background: var(--bg-primary); }
#login-overlay.hidden,
#users-overlay.hidden { display: none !important; }
.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 360px;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    animation: fadeUp 0.4s ease;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}
.login-logo { color: var(--accent); margin-bottom: 16px; }
.login-card h2 { font-size: 20px; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-field { text-align: left; margin-bottom: 14px; }
.login-field label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-secondary); margin-bottom: 4px; }
.login-field input {
    width: 100%; padding: 10px 12px;
    background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); font-family: var(--font); font-size: 14px; outline: none;
    transition: border-color var(--transition);
}
.login-field input:focus { border-color: var(--accent); }
.login-field input::placeholder { color: var(--text-muted); }
.login-error { color: var(--danger); font-size: 12px; margin-bottom: 10px; padding: 6px; background: var(--danger-dim); border-radius: var(--radius-sm); }
.login-btn { width: 100%; padding: 10px; font-size: 14px; margin-top: 4px; }

/* ---------- Header ---------- */
#app-header {
    height: var(--header-h);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    position: relative;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    color: var(--accent);
    display: flex;
    align-items: center;
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { filter: drop-shadow(0 0 4px rgba(88,166,255,0.3)); }
    50%      { filter: drop-shadow(0 0 12px rgba(88,166,255,0.6)); }
}

#app-header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

#app-header h1 .accent {
    color: var(--accent);
    font-weight: 700;
}

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

.header-badge {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.header-badge.eye-badge {
    font-weight: 700;
    text-transform: uppercase;
}

.header-badge.eye-badge[data-eye="OD"] {
    color: var(--artery-color);
    border-color: var(--artery-color);
    background: rgba(249, 117, 131, 0.1);
}

.header-badge.eye-badge[data-eye="OS"] {
    color: var(--vein-color);
    border-color: var(--vein-color);
    background: rgba(121, 192, 255, 0.1);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hidden {
    display: none !important;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    user-select: none;
}

.btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

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

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 5px 8px;
}

/* Standalone toggle buttons (mode toggles) – highlight when active */
#btn-circle-mode.active,
#btn-coord-mode.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #0d1117;
    font-weight: 600;
}

.btn-outline {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}

.btn-outline:hover:not(:disabled) {
    background: var(--accent-dim);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #0d1117;
    font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-dim);
}

.btn-artery.active {
    background: var(--artery-color);
    border-color: var(--artery-color);
    color: #0d1117;
}

.btn-vein.active {
    background: var(--vein-color);
    border-color: var(--vein-color);
    color: #0d1117;
}

.btn-group {
    display: flex;
    gap: 2px;
}

.btn-group .btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #0d1117;
}

.btn-group .btn-artery.active {
    background: var(--artery-color);
    border-color: var(--artery-color);
}

.btn-group .btn-vein.active {
    background: var(--vein-color);
    border-color: var(--vein-color);
}

/* ---------- Main Layout ---------- */
#app-main {
    display: flex;
    height: calc(100vh - var(--header-h));
}

/* ---------- Sidebar ---------- */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
    min-height: 0;
}

.sidebar-section:last-child {
    border-bottom: none;
    flex: 1;
}

#section-patients {
    flex: 0 0 auto;
    max-height: 40%;
}

#section-images {
    flex: 0 0 auto;
    max-height: 30%;
}

#section-measurements {
    flex: 1;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    flex-shrink: 0;
}

.section-header h2 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
}

.count-badge {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
}

/* ---------- Search ---------- */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 12px 8px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent);
}

.search-box svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    width: 100%;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* ---------- Item Lists ---------- */
.item-list {
    list-style: none;
    overflow-y: auto;
    padding: 0 8px 8px;
    flex: 1;
    min-height: 0;
}

.item-list li {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.item-list li:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.item-list li.active {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 500;
}

.item-list li.locked {
    opacity: 0.55;
    cursor: not-allowed;
}

.item-list li.locked:hover {
    background: transparent;
    color: inherit;
}

.item-list li .lock-badge {
    font-size: 11px;
    flex-shrink: 0;
}

.item-list li .eye-tag {
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.item-list li .eye-tag.od {
    background: rgba(249, 117, 131, 0.15);
    color: var(--artery-color);
}

.item-list li .eye-tag.os {
    background: rgba(121, 192, 255, 0.15);
    color: var(--vein-color);
}

/* Measurement items */
.measurement-items li {
    font-size: 12px;
    font-family: var(--font-mono);
    padding: 5px 10px;
    position: relative;
}

.measurement-items li .meas-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.measurement-items li .meas-type {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.measurement-items li .meas-type.artery {
    background: rgba(249, 117, 131, 0.2);
    color: var(--artery-color);
}

.measurement-items li .meas-type.vein {
    background: rgba(121, 192, 255, 0.2);
    color: var(--vein-color);
}

.measurement-items li .meas-type.landmark {
    background: rgba(63, 185, 80, 0.2);
    color: var(--success);
}

.measurement-items li .meas-detail {
    color: var(--text-muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.measurement-items li .meas-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    transition: all var(--transition);
    flex-shrink: 0;
}

.measurement-items li:hover .meas-delete {
    opacity: 1;
}

.measurement-items li .meas-delete:hover {
    background: var(--danger-dim);
}

.measurement-items li.selected {
    background: var(--accent-dim);
    border: 1px solid var(--accent);
}

.measurement-items li .meas-type.hemorrhage {
    background: rgba(210, 153, 34, 0.2);
    color: var(--warning);
}

.measurement-items li .meas-type.comment {
    background: rgba(139, 148, 158, 0.2);
    color: var(--text-secondary);
}

/* Comment area */
#comment-section { padding: 8px 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
#comment-section label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); display: block; margin-bottom: 4px; }
#image-comment {
    width: 100%; min-height: 50px; max-height: 100px; padding: 6px 8px;
    background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); font-family: var(--font); font-size: 12px; resize: vertical;
    outline: none; transition: border-color var(--transition);
}
#image-comment:focus { border-color: var(--accent); }
#image-comment::placeholder { color: var(--text-muted); }

/* ---------- Canvas Area ---------- */
#canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

/* Step Indicator */
#step-indicator {
    padding: 10px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.step-pills {
    display: flex;
    gap: 4px;
}

.step-pill {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    transition: all var(--transition);
    cursor: default;
}

.step-pill.active {
    color: var(--accent);
    background: var(--accent-dim);
    border-color: var(--accent);
}

.step-pill.done {
    color: var(--success);
    background: var(--success-dim);
    border-color: transparent;
}

/* Instruction Bar */
#instruction-bar {
    padding: 8px 20px;
    background: var(--accent-dim);
    border-bottom: 1px solid rgba(88, 166, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--accent);
    flex-shrink: 0;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Canvas Container */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 50%, rgba(88,166,255,0.03) 0%, transparent 70%),
        var(--bg-primary);
}

#canvas-image,
#canvas-overlay {
    position: absolute;
    top: 0;
    left: 0;
    cursor: crosshair;
}

#canvas-overlay {
    z-index: 2;
}

/* Welcome Screen */
#welcome-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.welcome-content {
    text-align: center;
    padding: 40px;
}

.welcome-icon {
    color: var(--text-muted);
    margin-bottom: 24px;
    animation: float 4s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-12px); }
}

.welcome-content h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.welcome-content p {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 360px;
    margin: 0 auto;
}

/* ---------- Toolbar ---------- */
#toolbar {
    height: var(--toolbar-h);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
}

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

.toolbar-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-right: 2px;
}

.toolbar-separator {
    width: 1px;
    height: 28px;
    background: var(--border);
}

.toolbar-spacer {
    flex: 1;
}

/* ---------- Toast Notifications ---------- */
#toast-container {
    position: fixed;
    bottom: 80px;
    right: 24px;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}

.toast {
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
}

.toast.success {
    border-color: var(--success);
    background: linear-gradient(135deg, var(--success-dim), var(--bg-elevated));
}

.toast.error {
    border-color: var(--danger);
    background: linear-gradient(135deg, var(--danger-dim), var(--bg-elevated));
}

.toast.info {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--accent-dim), var(--bg-elevated));
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* ---------- Measurement line preview ---------- */
.vessel-preview-line {
    stroke: var(--marker-vessel);
    stroke-width: 2;
    stroke-dasharray: 4 4;
}

/* ---------- Responsive (tablet) ---------- */
@media (max-width: 900px) {
    :root {
        --sidebar-w: 220px;
    }
}
