/* ===================================
   CED-Deck Analyzer - CSS Styles
   Modern, Clean Design
   =================================== */

:root {
    --primary-color: #1f6fb2;
    --primary-hover: #195b93;
    --primary-light: #e6f0fb;
    --primary-border: #b7d1ee;
    --secondary-color: #5b6b7a;
    --secondary-hover: #455463;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #fef2f2;
    --success-color: #10b981;
    --success-light: #ecfdf5;
    --warning-color: #f59e0b;
    --warning-light: #fffbeb;
    --bg-primary: #ffffff;
    --bg-secondary: #eef2f6;
    --bg-tertiary: #e6edf5;
    --bg-toolbar: linear-gradient(180deg, #ffffff 0%, #f4f8fc 100%);
    --bg-dark: #0f172a;
    --border-color: #d6dee8;
    --border-hover: #c4cfdc;
    --text-primary: #1b2430;
    --text-secondary: #4b5a6a;
    --text-muted: #7b8a9b;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    --font-sans: 'Source Sans 3', "Segoe UI", "Helvetica Neue", sans-serif;
    --toolbar-height: 52px;
    --sidebar-width: 260px;
}

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

body {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* ==================== TOOLBAR ==================== */

.toolbar {
    height: var(--toolbar-height);
    flex-shrink: 0;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    box-shadow: var(--shadow-xs);
    position: relative;
    z-index: 100;
}

.toolbar-left,
.toolbar-center,
.toolbar-right { display: flex; align-items: center; gap: var(--spacing-sm); }
.toolbar-center { flex: 1; justify-content: center; }

.logo {
    display: flex; align-items: center;
    white-space: nowrap; flex-shrink: 0;
    user-select: none;
}
.toolbar-logo-img {
    height: 30px;
    width: auto;
    background: #ffffff;
    border-radius: 8px;
    padding: 3px 8px;
    display: block;
    object-fit: contain;
}
.toolbar-left { flex-shrink: 0; }
.toolbar-right { flex-shrink: 0; }
.toolbar-divider { width: 1px; height: 22px; background: var(--border-color); margin: 0 3px; flex-shrink: 0; }

.search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    box-shadow: var(--shadow-xs);
    min-width: 360px;
    position: relative;
}

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

.search-input {
    border: none;
    padding: 6px 6px;
    min-width: 240px;
    font-weight: 500;
}

.search-input:focus {
    outline: none;
    box-shadow: none;
}

.search-status {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 90px;
    text-align: right;
}

/* ====== Bluebeam-style Search Results Panel ====== */
.toolbar-center {
    position: relative;
}

.search-results-panel {
    position: fixed;
    top: var(--toolbar-height);
    left: 50%;
    transform: translateX(-50%);
    width: 680px;
    max-height: 520px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    margin-top: 2px;
}

.search-results-header {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

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

.search-nav-info {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 6px;
    font-weight: 500;
}

.search-results-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
    font-size: 12.5px;
}

.search-results-footer {
    padding: 6px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: 11px;
    color: var(--text-muted);
}

/* Document node */
.search-doc-node {
    padding: 0;
}

.search-doc-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    cursor: default;
}

.search-doc-icon {
    color: var(--primary-color);
    flex-shrink: 0;
}

.search-doc-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Page group */
.search-page-group {
    border-bottom: 1px solid color-mix(in srgb, var(--border-color) 50%, transparent);
}

.search-page-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px 5px 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 11.5px;
    color: var(--text-secondary);
    background: var(--bg-primary);
    user-select: none;
    transition: background 0.15s;
}

.search-page-header:hover {
    background: var(--bg-tertiary, var(--bg-secondary));
}

.search-page-toggle {
    font-size: 9px;
    transition: transform 0.15s;
    color: var(--text-muted);
    flex-shrink: 0;
    width: 12px;
    text-align: center;
}

.search-page-group.collapsed .search-page-toggle {
    transform: rotate(-90deg);
}

.search-page-group.collapsed .search-snippet-list {
    display: none;
}

.search-page-label {
    flex: 1;
}

/* Snippet list */
.search-snippet-list {
    padding: 0;
}

/* Individual result item */
.search-result-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 5px 12px 5px 38px;
    cursor: pointer;
    line-height: 1.5;
    transition: background 0.12s;
    border-left: 3px solid transparent;
}

.search-result-item:hover {
    background: color-mix(in srgb, var(--primary-color) 8%, var(--bg-primary));
}

.search-result-item.active {
    background: color-mix(in srgb, var(--primary-color) 14%, var(--bg-primary));
    border-left-color: var(--primary-color);
}

.search-result-page {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    min-width: 80px;
    flex-shrink: 0;
    padding-top: 1px;
}

.search-result-text {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.5;
    word-break: break-word;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Highlighted match keyword */
.search-highlight {
    background: transparent;
    color: #2196F3;
    font-weight: 700;
}

/* Searching / no results */
.search-searching,
.search-no-results {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.search-no-results strong {
    color: var(--text-secondary);
}

/* ==================== BUTTONS ==================== */

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    background: var(--bg-primary); color: var(--text-primary); font-size: 13px;
    font-weight: 500; cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
    font-family: var(--font-sans);
}
.btn:hover { background: var(--bg-tertiary); border-color: var(--border-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-primary { background: var(--primary-color); border-color: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger-color); border-color: var(--danger-color); color: white; }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-accent { background: #8b5cf6; border-color: #8b5cf6; color: white; }
.btn-accent:hover { background: #7c3aed; border-color: #7c3aed; }
.btn-accent:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn-success { background: #16a34a; border-color: #16a34a; color: white; font-weight: 600; }
.btn-success:hover { background: #15803d; border-color: #15803d; }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.btn-icon { padding: 6px; min-width: 32px; justify-content: center; }
.btn-icon:hover { background: var(--primary-light); border-color: var(--primary-border); color: var(--primary-color); }
.btn-icon.active { background: var(--primary-light); border-color: var(--primary-color); color: var(--primary-color); }
.btn-lg { padding: 10px 20px; font-size: 14px; }
.btn-block { width: 100%; justify-content: center; }
.btn-outline { background: transparent; border-color: var(--primary-border); color: var(--primary-color); }
.btn-outline:hover { background: var(--primary-light); border-color: var(--primary-color); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ==================== MAIN LAYOUT ==================== */

.main-container {
    display: flex;
    flex: 1;
    min-height: 0;   /* allow flex child to shrink below content size */
    overflow: hidden;
}

/* ==================== SIDEBARS ==================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.25s ease, opacity 0.25s ease;
}
.sidebar-right { border-right: none; border-left: 1px solid var(--border-color); }

/* Sidebar hidden state */
.sidebar.hidden {
    width: 0;
    border: none;
    overflow: hidden;
    min-width: 0;
    opacity: 0;
}

.sidebar-section {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-title {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: var(--spacing-md);
}

.tool-group { display: flex; flex-direction: column; gap: 6px; }

.tool-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border: 1px solid transparent; border-radius: var(--radius-md);
    background: linear-gradient(180deg, #ffffff 0%, #f7f9fc 100%);
    color: var(--text-secondary); font-size: 13px;
    font-weight: 500; cursor: pointer; transition: all 0.15s ease;
    text-align: left; width: 100%; font-family: var(--font-sans);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.6), var(--shadow-xs);
}
.tool-btn:hover { background: #eef4fb; color: var(--text-primary); border-color: var(--primary-border); }
.tool-btn.active {
    background: #e4f0ff; border-color: var(--primary-border);
    color: var(--primary-color); font-weight: 600; box-shadow: var(--shadow-sm);
}
.tool-btn svg { flex-shrink: 0; }

/* ==================== FORM ELEMENTS ==================== */

.input {
    width: 100%; padding: 7px 10px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    background: var(--bg-primary); color: var(--text-primary); font-size: 13px;
    font-family: var(--font-sans); transition: all 0.15s ease;
}
.input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }

.scale-input-group { display: flex; flex-direction: column; gap: 6px; }
.scale-input-group label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.custom-scale { margin-top: var(--spacing-xs); }
.custom-scale small { display: block; margin-top: var(--spacing-xs); color: var(--text-muted); font-size: 11px; }
.scale-info {
    margin-top: 6px; padding: 6px 8px; background: var(--bg-tertiary);
    border-radius: var(--radius-sm); border: 1px solid var(--border-color);
}
.scale-info small { font-size: 12px; color: var(--text-secondary); }
.scale-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.scale-status { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--spacing-md); margin-bottom: var(--spacing-md);
}
.setting-row:last-child { margin-bottom: 0; }
.setting-row label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

.color-input {
    width: 36px; height: 28px; border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); cursor: pointer; padding: 2px;
}

.slider {
    flex: 1; height: 4px; border-radius: 2px; background: var(--bg-tertiary); outline: none;
    -webkit-appearance: none; appearance: none;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 14px; height: 14px; border-radius: 50%; background: var(--primary-color);
    cursor: pointer; border: 2px solid white; box-shadow: var(--shadow-sm);
}
.slider::-moz-range-thumb {
    width: 14px; height: 14px; border-radius: 50%; background: var(--primary-color);
    cursor: pointer; border: 2px solid white; box-shadow: var(--shadow-sm);
}

/* ==================== VIEWER CONTAINER ==================== */

.viewer-container {
    flex: 1; display: flex; flex-direction: column;
    background:
        radial-gradient(circle at 10% 10%, rgba(31,111,178,0.08), transparent 40%),
        radial-gradient(circle at 90% 20%, rgba(16,185,129,0.08), transparent 45%),
        repeating-linear-gradient(0deg, rgba(0,0,0,0.04), rgba(0,0,0,0.04) 1px, transparent 1px, transparent 18px),
        #eef2f6;
    position: relative; overflow: hidden; min-width: 0;
}

/* Empty State */
.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text-secondary); padding: var(--spacing-xl); text-align: center;
}
.empty-state svg { margin-bottom: var(--spacing-xl); opacity: 0.2; color: var(--text-muted); }
.empty-state h2 { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.empty-state p { font-size: 14px; margin-bottom: var(--spacing-xl); max-width: 360px; color: var(--text-secondary); }

/* PDF Container */
.pdf-container {
    flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden;
}

/* Scrollable area holding all pages - scrolls BOTH directions */
.pdf-viewport {
    flex: 1;
    overflow: auto;
    padding: var(--spacing-xl);
    padding-bottom: 80px;
}

/* Inner wrapper to center pages but allow horizontal scroll when zoomed */
.pdf-viewport-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    min-width: min-content;
}

/* Each page */
.page-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.page-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow-lg);
    background: white;
    border-radius: 2px;
}

.canvas-wrapper .pdf-canvas {
    display: block;
    image-rendering: auto;           /* smooth downscale for crisp text */
    -webkit-font-smoothing: antialiased;
    backface-visibility: hidden;     /* force GPU compositing */
    transform: translateZ(0);        /* hardware acceleration for smooth render */
}

.canvas-wrapper .drawing-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ==================== FLOATING BOTTOM CONTROLS ==================== */

.floating-controls {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    padding: 5px 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    z-index: 50;
}

.float-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.float-divider {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.15);
    margin: 0 4px;
}

.float-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    transition: all 0.15s ease;
}

.float-btn:hover {
    background: rgba(255,255,255,0.12);
    color: white;
}

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

.float-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    min-width: 40px;
    text-align: center;
    user-select: none;
}

/* ==================== AREA LIST ==================== */

.area-list {
    display: flex; flex-direction: column; gap: 6px;
    max-height: 280px; overflow-y: auto;
}

.no-areas { padding: var(--spacing-lg); text-align: center; color: var(--text-muted); }
.no-areas p { font-size: 13px; margin-bottom: var(--spacing-xs); }
.no-areas small { font-size: 11px; }

.area-item {
    padding: 10px; background: var(--bg-secondary); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); display: flex; justify-content: space-between; align-items: center;
    transition: all 0.15s ease; animation: fadeIn 0.2s ease; cursor: pointer;
}
.area-item:hover { border-color: var(--primary-border); background: var(--primary-light); }

.area-item-info { flex: 1; }
.area-item-name { font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 1px; }
.area-item-value { font-size: 14px; font-weight: 700; color: var(--primary-color); }

.area-item-delete {
    padding: 4px; background: none; border: none; color: var(--text-muted);
    cursor: pointer; border-radius: 4px; transition: all 0.15s ease;
}
.area-item-delete:hover { background: var(--danger-light); color: var(--danger-color); }

.total-area {
    margin-top: var(--spacing-md); padding: 10px var(--spacing-md);
    background: var(--primary-light); border: 1px solid var(--primary-border);
    border-radius: var(--radius-md); display: flex;
    justify-content: space-between; align-items: center; font-size: 13px;
}
.total-area strong { color: var(--text-primary); font-weight: 600; }
.total-area span { font-size: 16px; font-weight: 800; color: var(--primary-color); }

/* ==================== NOTES ==================== */

.notes-container { display: flex; flex-direction: column; gap: 6px; }

.notes-textarea {
    width: 100%; min-height: 160px; padding: 10px;
    border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    background: var(--bg-primary); color: var(--text-primary); font-size: 12px;
    font-family: var(--font-sans); line-height: 1.6; resize: vertical; transition: all 0.15s ease;
}
.notes-textarea:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.notes-textarea::placeholder { color: var(--text-muted); }

.notes-meta { display: flex; justify-content: space-between; align-items: center; }
.notes-meta small { font-size: 11px; color: var(--text-muted); }

/* ==================== TOAST ==================== */

.toast-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 10px 18px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; color: white;
    box-shadow: var(--shadow-xl); opacity: 0; transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success-color); }
.toast-error   { background: var(--danger-color); }
.toast-warning { background: var(--warning-color); }
.toast-info    { background: var(--secondary-color); }

/* ==================== SCROLLBARS ==================== */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); }

/* ==================== ANIMATIONS ==================== */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 1200px) { :root { --sidebar-width: 220px; } }

@media (max-width: 768px) {
    .main-container { flex-direction: column; }
    .sidebar { width: 100%; max-height: 250px; }
}

/* ====================================================
   PHASE 2 – AI Detection / Extraction Panels
   ==================================================== */

/* ── Backend status indicator ────────────────────────── */
.backend-status {
    font-size: 12px;
    cursor: default;
    user-select: none;
    line-height: 1;
}

/* ── Shared detect panel ─────────────────────────────── */
.detect-panel {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    animation: fadeIn 0.25s ease;
}

.detect-panel-header {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-xs);
    border-bottom: 1px solid var(--border-color);
}

/* ── Progress bar / text ─────────────────────────────── */
.detect-progress {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: 6px;
}
.detect-progress::before {
    content: '';
    width: 14px; height: 14px;
    border: 2px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.detect-progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: var(--spacing-sm);
}
.detect-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    border-radius: 2px;
    transition: width 0.35s ease;
}

/* ── No-result message ───────────────────────────────── */
.detect-no-result {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.6;
}
.detect-no-result p { margin-bottom: 4px; }
.detect-no-result small { font-size: 11px; opacity: 0.7; }

/* ── Confidence badges ───────────────────────────────── */
.confidence-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 10px;
    line-height: 1;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.conf-high   { background: var(--success-light); color: #047857; }
.conf-medium { background: var(--warning-light); color: #92400e; }
.conf-low    { background: var(--danger-light);  color: #b91c1c; }

/* ── Bulk actions row ────────────────────────────────── */
.detect-bulk-actions {
    display: flex;
    gap: 6px;
    margin-top: var(--spacing-sm);
    padding-top: var(--spacing-sm);
    border-top: 1px solid var(--border-color);
}
.detect-bulk-actions .btn { flex: 1; }

/* ====================================================
   Scale Detection Items
   ==================================================== */
.scale-detect-item {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    animation: fadeIn 0.2s ease;
    transition: border-color 0.15s ease;
}
.scale-detect-item:hover { border-color: var(--primary-border); }

.scale-detect-info { margin-bottom: 4px; }

.scale-detect-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.scale-detect-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.scale-detect-match {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 2px;
    word-break: break-word;
}

.scale-detect-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

/* ====================================================
   Deck Detection Items
   ==================================================== */
.deck-detect-item {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    animation: fadeIn 0.2s ease;
    cursor: pointer;
    transition: all 0.15s ease;
}
.deck-detect-item:hover { border-color: var(--primary-border); background: var(--primary-light); }

.deck-detect-info { margin-bottom: 4px; }

.deck-detect-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.deck-detect-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.deck-detect-text {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 2px;
    word-break: break-word;
}

.deck-detect-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

/* ====================================================
   Notes Extraction Items
   ==================================================== */
.extracted-notes-list {
    max-height: 320px;
    overflow-y: auto;
}

.extract-category {
    margin-bottom: var(--spacing-md);
}

.extract-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    padding: 4px 0;
    margin-bottom: 4px;
    border-bottom: 1px dashed var(--border-color);
}

.extract-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 18px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 700;
    background: var(--primary-light);
    color: var(--primary-color);
    border-radius: 10px;
}

.extract-note-item {
    padding: 6px var(--spacing-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 12px;
    line-height: 1.5;
    animation: fadeIn 0.2s ease;
    transition: border-color 0.15s ease;
}
.extract-note-item:hover { border-color: var(--primary-border); }

.extract-note-text {
    color: var(--text-primary);
    word-break: break-word;
    margin-bottom: 4px;
}
.extract-note-text mark {
    background: #fef08a;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.extract-note-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    flex-wrap: wrap;
}

.extract-page-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}
.extract-page-link:hover { text-decoration: underline; }

.extract-note-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}
.extract-note-actions .btn { padding: 3px 8px; font-size: 11px; }

/* ====================================================
   Project Info Panel
   ==================================================== */
.project-info-placeholder {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.project-analyzing {
    padding: var(--spacing-md);
    text-align: center;
}

.project-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.project-info-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    font-size: 12px;
    gap: 8px;
}
.project-info-row:last-child { border-bottom: none; }

.project-info-row label {
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    min-width: 70px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.project-info-row span {
    text-align: right;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    white-space: nowrap;
}

.project-info-row span:hover {
    white-space: normal;
    word-break: break-word;
    overflow: visible;
}

/* ==================== TAKEOFF CHECKLIST ==================== */
.checklist {
    list-style: disc;
    padding-left: 16px;
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.checklist li {
    margin: 6px 0;
}

.badge-highlight {
    background: var(--primary-light);
    color: var(--primary-color) !important;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700 !important;
    font-size: 12px;
}

/* ====================================================
   Takeoff Extras
   ==================================================== */
.takeoff-extras {
    margin-top: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.takeoff-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 12px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.takeoff-row:last-child { border-bottom: none; }

.takeoff-row label {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 11px;
}

.takeoff-row span {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 12px;
}

/* ====================================================
   Note Added State
   ==================================================== */
.btn-added {
    background: #d1fae5 !important;
    color: #065f46 !important;
    border-color: #6ee7b7 !important;
    cursor: default;
    opacity: 0.8;
}
.btn-added:hover {
    background: #d1fae5 !important;
}

/* ==================== GLOBAL ANALYSIS PROGRESS BAR ==================== */
.global-progress {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 16px 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.global-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.global-progress-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}
.global-progress-pct {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-color);
}
.global-progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}
.global-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), var(--success-color));
    border-radius: 3px;
    transition: width 0.4s ease;
}
.global-progress-steps {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.gp-step {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    transition: all 0.3s ease;
}
.gp-step[data-status="active"] {
    background: var(--primary-color);
    color: #fff;
    animation: gpPulse 1.5s ease-in-out infinite;
}
.gp-step[data-status="done"] {
    background: var(--success-color);
    color: #fff;
}
.gp-step[data-status="error"] {
    background: var(--danger-color);
    color: #fff;
}
@keyframes gpPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ─── Training Panel ─── */
.training-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.training-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    padding: 3px 0;
    border-bottom: 1px solid var(--border-color);
}
.training-stat-row:last-child { border-bottom: none; }
.training-stat-row span { color: var(--text-secondary); }
.training-stat-row strong { color: var(--text-primary); font-weight: 600; }

.training-accuracy-bar {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}
.training-accuracy-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger-color) 0%, #f59e0b 50%, var(--success-color) 100%);
    border-radius: 4px;
    transition: width 0.5s ease;
}
.training-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
/* ═════════════════════════════════════════════════════════════════
   Training Data Manager Dashboard Modal Styles
   ═════════════════════════════════════════════════════════════════ */

.training-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.training-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.training-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.training-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.training-modal-content {
    position: relative;
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    background: white;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.training-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xl);
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.training-modal-header h2 {
    font-size: 22px;
    font-weight: 600;
    margin: 0;
}

.training-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-xl);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

.training-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-md);
    padding: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

/* Statistics Grid */
.training-stats-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.stat-card {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border: 1px solid #667eea30;
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    text-align: center;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #667eea60;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: var(--spacing-sm);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Upload Section */
.training-upload-section h3,
.training-extraction-section h3,
.training-status-section h3,
.training-table-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.upload-box {
    border: 2px dashed #667eea;
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9ff;
}

.upload-box:hover {
    border-color: #764ba2;
    background: #f3f4ff;
}

.upload-box svg {
    color: #667eea;
    margin-bottom: var(--spacing-md);
    transition: transform 0.3s ease;
}

.upload-box:hover svg {
    transform: scale(1.1);
}

.upload-box p {
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: var(--spacing-md);
}

#uploadProgressFill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px;
    width: 0;
    transition: width 0.3s ease;
}

#uploadStatus {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

/* Extraction Results */
.extraction-results {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    max-height: 500px;
    overflow-y: auto;
}

.extraction-group {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    border: 1px solid #e2e8f0;
}

.extraction-group h4 {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: 14px;
    color: #667eea;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: var(--spacing-sm);
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
}

.result-row:nth-child(even) {
    background: #f8fafc;
}

.result-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
}

.result-value {
    font-weight: 700;
    color: #667eea;
    font-size: 14px;
    text-align: right;
    max-width: 60%;
    word-break: break-word;
}

.result-value.highlight-value {
    font-size: 16px;
    color: #10b981;
}

/* Training Status */
.training-status {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

.status-message {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    background: white;
    border-left: 4px solid #667eea;
}

.training-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-md);
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md);
    background: white;
    border-radius: var(--radius-md);
    border-left: 3px solid #764ba2;
}

.metric-row span:last-child {
    font-weight: 700;
    color: #764ba2;
}

/* Training Table */
.training-table-container {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

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

.training-table thead {
    background: linear-gradient(135deg, #f8f9ff 0%, #f3f4ff 100%);
    border-bottom: 2px solid var(--border-color);
}

.training-table th {
    padding: var(--spacing-md);
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.training-table td {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 14px;
}

.training-table tbody tr:hover {
    background: #f8f9ff;
}

/* Responsive Design */
@media (max-width: 768px) {
    .training-modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .training-modal-header {
        padding: var(--spacing-lg);
    }

    .training-modal-header h2 {
        font-size: 18px;
    }

    .training-modal-body {
        padding: var(--spacing-lg);
        gap: var(--spacing-lg);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .training-table {
        font-size: 12px;
    }

    .training-table th,
    .training-table td {
        padding: var(--spacing-sm);
    }
}

/* ==================== EXCLUDE ZONE TOOL ==================== */

.tool-btn.exclude-tool { border-color: #fca5a5; }
.tool-btn.exclude-tool:hover { background: #fef2f2; color: var(--danger-color); border-color: var(--danger-color); }
.tool-btn.exclude-tool.active { background: #fef2f2; border-color: var(--danger-color); color: var(--danger-color); }

.exclude-hint {
    padding: 5px 8px;
    background: #fef2f2;
    border: 1px dashed #fca5a5;
    border-radius: var(--radius-sm);
    color: var(--danger-color);
    font-size: 11px;
    line-height: 1.4;
    margin-top: 4px;
}

/* Exclusion zone items in the area list */
.area-item-exclusion {
    border-left: 3px solid var(--danger-color) !important;
    background: #fff8f8 !important;
}
.exclusion-label { color: var(--danger-color); }
.exclusion-value { color: var(--danger-color); font-weight: 600; }
.excl-badge {
    display: inline-block;
    background: var(--danger-color);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    margin-right: 4px;
    vertical-align: middle;
}

/* Exclusion breakdown summary */
.exclusion-summary {
    margin-top: 8px;
    padding: 8px 10px;
    background: #fff8f8;
    border: 1px solid #fca5a5;
    border-radius: var(--radius-sm);
    font-size: 12px;
}
.excl-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    color: var(--text-secondary);
}
.excl-minus { color: var(--danger-color); }
.excl-net { color: var(--text-primary); font-size: 13px; padding-top: 4px; }
.excl-divider {
    border: none;
    border-top: 1px solid #fca5a5;
    margin: 4px 0;
}

/* ==================== FRAMING PLAN PAGES ==================== */

.framing-pages-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.framing-page-chip {
    padding: 7px 9px;
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.framing-chip-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.framing-chip-page {
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.framing-chip-kw {
    margin-top: 3px;
    font-size: 10px;
    color: var(--text-muted);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== DECK SPEC CARD ==================== */

.deck-spec-card {
    margin-bottom: 10px;
    border: 1px solid var(--primary-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    font-size: 12px;
}

.spec-card-header {
    padding: 6px 10px;
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 700;
    font-size: 12px;
    border-bottom: 1px solid var(--primary-border);
}

.spec-row {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-bottom: 1px solid var(--bg-tertiary);
}
.spec-row:last-of-type { border-bottom: none; }

.spec-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.spec-value {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 12px;
}

.spec-page {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 1px 4px;
}

.spec-conflict-icon {
    cursor: help;
    margin-left: 3px;
}

.spec-conflict-banner {
    padding: 6px 10px;
    background: var(--warning-light);
    border-top: 1px solid #fde68a;
    color: #92400e;
    font-size: 11px;
    line-height: 1.5;
}

/* ==================== CALIBRATION MODAL ==================== */

.cal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cal-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg, 10px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    width: 380px;
    max-width: 95vw;
    overflow: hidden;
    animation: calSlideIn 0.18s ease;
}

@keyframes calSlideIn {
    from { transform: translateY(-16px) scale(0.97); opacity: 0; }
    to   { transform: translateY(0)     scale(1);    opacity: 1; }
}

.cal-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 18px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
}

.cal-body {
    padding: 18px 18px 10px;
}

.cal-distance-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 14px;
}

.cal-px-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.cal-px-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

.cal-field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.cal-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cal-input {
    flex: 1;
    font-size: 15px;
    padding: 8px 12px;
    font-weight: 600;
}

.cal-unit-hint {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.cal-preview {
    min-height: 22px;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    transition: color 0.15s;
}

.cal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 18px 16px;
    border-top: 1px solid var(--border-color);
    margin-top: 6px;
}

.cal-section-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 14px 0 8px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.cal-section-divider::before,
.cal-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.cal-section-divider:first-child {
    margin-top: 4px;
}

.cal-preset-row {
    margin-bottom: 4px;
}

.cal-preset-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s;
    outline: none;
}

.cal-preset-select:hover {
    border-color: var(--primary-color);
}

.cal-preset-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb, 59,130,246), 0.15);
}

/* ==================== CALIBRATE TOOL BUTTON ==================== */
.tool-btn.calibrate-tool {
    border-color: #93c5fd;
    color: var(--primary-color);
}
.tool-btn.calibrate-tool:hover,
.tool-btn.calibrate-tool.active {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* ==================== EXCLUSION COLOR ROW ==================== */
.excl-color-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 8px;
    background: #fef2f2;
    border: 1px dashed #fca5a5;
    border-radius: var(--radius-sm);
    margin-top: 6px;
    font-size: 12px;
    color: var(--danger-color);
}
.excl-color-row label { font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }

/* ==================== COLOR PRESETS ==================== */
.color-preset-row {
    display: flex;
    gap: 5px;
    margin: 6px 0 2px;
    flex-wrap: wrap;
}

.color-preset-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s ease;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    flex: 1;
    justify-content: center;
    min-width: 0;
}
.color-preset-btn:hover {
    border-color: var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.color-preset-btn.active {
    border-color: currentColor;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.color-preset-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.15);
    flex-shrink: 0;
}

/* ==================== PROFILE DROPDOWN ==================== */
.profile-dropdown-wrap {
    position: relative;
}

.profile-dropdown {
    position: fixed;   /* fixed so toolbar overflow never clips it */
    width: 240px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
    z-index: 9999;
    overflow: hidden;
    animation: profileDropIn 0.15s ease;
}

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

.profile-dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--primary-light);
    border-bottom: 1px solid var(--primary-border);
}

.profile-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.profile-meta { min-width: 0; }
.profile-name  { font-weight: 700; font-size: 13px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-email { font-size: 11px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.profile-role-badge {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px; font-weight: 700;
    background: var(--primary-color); color: #fff;
    text-transform: uppercase; letter-spacing: 0.4px;
}
.profile-role-badge[data-role="admin"]       { background: #8b5cf6; }
.profile-role-badge[data-role="super_admin"] { background: #ef4444; }

.profile-dropdown-divider { height: 1px; background: var(--border-color); }

.profile-dropdown-item {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 9px 14px;
    background: none; border: none;
    font-family: var(--font-sans); font-size: 13px;
    color: var(--text-primary); cursor: pointer;
    transition: background 0.12s ease;
    text-align: left;
}
.profile-dropdown-item:hover { background: var(--bg-tertiary); }
.profile-dropdown-item--danger { color: var(--danger-color, #ef4444); }
.profile-dropdown-item--danger:hover { background: rgba(239,68,68,0.08); }

/* Profile pill button in toolbar */
.profile-pill-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 8px 4px 4px;
    border-radius: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    max-width: 160px;
}
.profile-pill-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-border);
}
.profile-pill-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700; font-size: 12px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.profile-pill-name {
    overflow: hidden; text-overflow: ellipsis;
    max-width: 90px;
}

/* Toolbar responsive overflow */
.toolbar {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
}
.toolbar::-webkit-scrollbar { height: 3px; }
.toolbar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }
.toolbar-right { flex-shrink: 0; }

/* ==================== PDF TAB BAR ==================== */
.pdf-tab-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 34px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 8px;
    flex-shrink: 0;
    z-index: 90;
}

.pdf-tab-list {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
    min-width: 0;
}
.pdf-tab-list::-webkit-scrollbar { height: 3px; }
.pdf-tab-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 2px; }

.pdf-tab {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--bg-tertiary);
    font-size: 12px; font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.12s ease;
    white-space: nowrap;
    max-width: 200px;
    user-select: none;
    flex-shrink: 0;
}
.pdf-tab:hover { background: var(--bg-primary); color: var(--text-primary); }
.pdf-tab.active {
    background: var(--bg-primary);
    border-color: var(--border-color);
    border-bottom-color: var(--bg-primary);
    color: var(--primary-color);
    font-weight: 600;
}

.pdf-tab-name { overflow: hidden; text-overflow: ellipsis; max-width: 140px; }

.pdf-tab-close {
    display: flex; align-items: center; justify-content: center;
    width: 14px; height: 14px; border-radius: 2px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); padding: 0; flex-shrink: 0;
    transition: all 0.1s ease;
}
.pdf-tab-close:hover { background: rgba(239,68,68,0.12); color: var(--danger-color); }

.pdf-tab-add {
    flex-shrink: 0;
    font-size: 11px;
    height: 26px;
    padding: 0 8px;
    white-space: nowrap;
}

/* ==================== HOW TO USE MODAL ==================== */
.htu-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9200;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}

.htu-modal {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    width: 100%; max-width: 640px;
    max-height: 88vh;
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: calSlideIn 0.18s ease;
}

.htu-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700; font-size: 15px;
    flex-shrink: 0;
}

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

.htu-close { color: #fff !important; }
.htu-close:hover { background: rgba(255,255,255,0.15) !important; }

.htu-body {
    overflow-y: auto;
    padding: 16px 18px 20px;
    display: flex; flex-direction: column; gap: 16px;
}

.htu-steps { display: flex; flex-direction: column; gap: 8px; }

.htu-step {
    display: flex; gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}

.htu-step-num {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--primary-color); color: #fff;
    font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 1px;
}

.htu-step-title { font-weight: 700; font-size: 13px; margin-bottom: 3px; color: var(--text-primary); }
.htu-step-desc  { font-size: 12px; color: var(--text-secondary); line-height: 1.55; }

.htu-tips-title {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.8px; color: var(--text-muted); margin-bottom: 8px;
}

.htu-tip-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 6px;
}

.htu-tip {
    display: flex; align-items: center; gap: 6px;
    font-size: 11px; color: var(--text-secondary);
    background: var(--bg-secondary); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); padding: 5px 8px;
}

kbd {
    display: inline-block;
    padding: 1px 4px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background: var(--bg-primary);
    font-family: monospace; font-size: 10px; font-weight: 600;
    box-shadow: 0 1px 0 var(--border-color);
    white-space: nowrap; flex-shrink: 0;
    color: var(--text-primary);
}