/* ============================================================
   CoinLens — Design System
   Currency-inspired premium UI with dark mode support
   ============================================================ */

:root {
    /* Surface & background */
    --bg: #faf8f2;
    --surface: #ffffff;
    --surface-2: #f5f1e8;
    --surface-3: #ede8db;
    --border: #e2ddd0;

    /* Text */
    --text: #2d2a24;
    --text-muted: #8a8477;

    /* Brand — gold (primary accent) */
    --gold: #d4a017;
    --gold-light: #f0d060;
    --gold-dim: rgba(212, 160, 23, 0.10);
    --gold-glow: rgba(240, 208, 96, 0.25);

    /* Semantic */
    --green: #2e9e5a;
    --green-light: #e8f5ee;
    --green-dim: rgba(46, 158, 90, 0.10);
    --blue: #4a7ff7;
    --blue-dim: rgba(74, 127, 247, 0.10);
    --error: #d94040;
    --error-dim: rgba(217, 64, 64, 0.08);

    /* Tokens */
    --radius: 14px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.10);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

    /* Camera action bar */
    --cam-bar-bg: var(--surface);
}

/* === Dark Mode === */
[data-theme="dark"] {
    --bg: #141416;
    --surface: #1e1e22;
    --surface-2: #26262c;
    --surface-3: #303038;
    --border: #3a3a44;
    --text: #e8e6e1;
    --text-muted: #8a8880;
    --gold-dim: rgba(212, 160, 23, 0.12);
    --gold-glow: rgba(240, 208, 96, 0.18);
    --green-light: rgba(46, 158, 90, 0.12);
    --green-dim: rgba(46, 158, 90, 0.12);
    --blue-dim: rgba(74, 127, 247, 0.12);
    --error-dim: rgba(217, 64, 64, 0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.15);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.3);
    --cam-bar-bg: #1a1a1e;
    --camera-bg: #1a1a1a;
    --toggle-knob: #ffffff;
}

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

body {
    background: var(--bg);
    background-image:
        radial-gradient(circle at 20% 50%, rgba(46, 100, 56, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(46, 100, 56, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(212, 160, 23, 0.02) 0%, transparent 40%),
        url("data:image/svg+xml,%3Csvg width='200' height='200' viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='g' width='200' height='200' patternUnits='userSpaceOnUse'%3E%3Cpath d='M0 100 Q25 80 50 100 T100 100 T150 100 T200 100' fill='none' stroke='%23507850' stroke-opacity='0.04' stroke-width='0.8'/%3E%3Cpath d='M0 110 Q25 90 50 110 T100 110 T150 110 T200 110' fill='none' stroke='%23507850' stroke-opacity='0.03' stroke-width='0.6'/%3E%3Cpath d='M0 90 Q25 70 50 90 T100 90 T150 90 T200 90' fill='none' stroke='%23507850' stroke-opacity='0.03' stroke-width='0.6'/%3E%3Cpath d='M100 0 Q80 25 100 50 T100 100 T100 150 T100 200' fill='none' stroke='%23507850' stroke-opacity='0.04' stroke-width='0.8'/%3E%3Cpath d='M110 0 Q90 25 110 50 T110 100 T110 150 T110 200' fill='none' stroke='%23507850' stroke-opacity='0.03' stroke-width='0.6'/%3E%3Cpath d='M90 0 Q70 25 90 50 T90 100 T90 150 T90 200' fill='none' stroke='%23507850' stroke-opacity='0.03' stroke-width='0.6'/%3E%3Cline x1='0' y1='0' x2='200' y2='200' stroke='%23507850' stroke-opacity='0.015' stroke-width='0.5'/%3E%3Cline x1='200' y1='0' x2='0' y2='200' stroke='%23507850' stroke-opacity='0.015' stroke-width='0.5'/%3E%3Cline x1='0' y1='50' x2='200' y2='50' stroke='%23507850' stroke-opacity='0.02' stroke-width='0.3'/%3E%3Cline x1='0' y1='150' x2='200' y2='150' stroke='%23507850' stroke-opacity='0.02' stroke-width='0.3'/%3E%3Ccircle cx='100' cy='100' r='60' fill='none' stroke='%23507850' stroke-opacity='0.02' stroke-width='0.5'/%3E%3Ccircle cx='100' cy='100' r='70' fill='none' stroke='%23507850' stroke-opacity='0.015' stroke-width='0.5'/%3E%3C/pattern%3E%3C/defs%3E%3Crect width='200' height='200' fill='url(%23g)'/%3E%3C/svg%3E");
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

[data-theme="dark"] body {
    background-image: none;
    background-color: var(--bg);
}

/* === Layout === */
.layout { display: flex; flex-direction: column; min-height: 100vh; }

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 54px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.logo {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--gold), #e6b422, var(--gold-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    text-decoration: none;
}
.logo span { font-weight: 400; opacity: 0.6; }

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

.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover { color: var(--gold); border-color: var(--gold); }

main {
    flex: 1;
    padding: 20px 20px 100px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    animation: pageIn 0.3s ease-out;
}

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

/* === Bottom Tab Bar === */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    padding: 6px 0 calc(env(safe-area-inset-bottom, 0px) + 6px);
    z-index: 100;
    box-shadow: 0 -1px 8px rgba(0,0,0,0.04);
}
[data-theme="dark"] .tab-bar { box-shadow: 0 -1px 8px rgba(0,0,0,0.2); }

.tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    padding: 4px 12px;
    min-width: 56px;
    min-height: 44px;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
    position: relative;
}
.tab svg { transition: transform var(--transition); }
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); font-weight: 700; }
.tab.active svg { transform: scale(1.1); }
.tab.active::after {
    content: "";
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--gold);
    border-radius: 0 0 3px 3px;
}

/* Scan FAB */
.tab-scan { position: relative; }
.scan-fab {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -22px;
    box-shadow: 0 4px 16px var(--gold-glow);
    transition: transform var(--transition), box-shadow var(--transition);
}
.scan-fab svg { color: var(--text); }
.tab-scan:hover .scan-fab { transform: scale(1.06); }
.tab-scan.active .scan-fab { box-shadow: 0 4px 24px rgba(212, 160, 23, 0.5); }
.tab-scan.active::after { display: none; }
.tab-scan span { margin-top: 2px; }

/* === Hero Banner === */
.hero-banner {
    background: linear-gradient(135deg, var(--gold-dim), var(--gold-glow), var(--gold-dim));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 28px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
[data-theme="dark"] .hero-banner {
    background: linear-gradient(135deg, rgba(212,160,23,0.12), rgba(212,160,23,0.06));
}
.hero-banner::after {
    content: "";
    position: absolute;
    top: -30px;
    right: -20px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--gold-glow) 0%, transparent 70%);
    pointer-events: none;
}
.hero-icon { font-size: 48px; flex-shrink: 0; }
.hero-text h2 { font-size: 20px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.hero-text p { font-size: 14px; color: var(--text-muted); }

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--gold), var(--gold-light));
}
.stat-card .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    margin-bottom: 8px;
}
.stat-card .value {
    font-size: 30px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -1px;
    line-height: 1.1;
}
.stat-card .value.money { color: var(--green); }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.stat-card-link {
    text-decoration: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}
.stat-card-link:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card-link:active { transform: scale(0.97); }

/* === Section === */
.section { margin-bottom: 32px; }
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}
.section-title { font-size: 18px; font-weight: 700; color: var(--text); }

/* === Cards === */
.scan-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}
.scan-card-idle {
    text-align: center;
    padding: 40px 20px;
}
.coin-icon-ring {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gold-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    border: 2px dashed var(--gold);
    transition: all var(--transition);
}
.scan-card:hover .coin-icon-ring {
    background: var(--gold-glow);
    transform: scale(1.05);
}

/* === Table === */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; }

th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 12px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-weight: 700;
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

.thumb {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-2);
    border: 2px solid var(--gold-dim);
}
.thumb-placeholder {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold-dim), var(--gold-glow));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-espcam { background: var(--green-dim); color: var(--green); }
.badge-camera { background: var(--blue-dim); color: var(--blue); }
.badge-upload { background: var(--gold-dim); color: var(--gold); }

/* Confidence bar */
.conf-bar {
    width: 80px;
    height: 6px;
    background: var(--surface-3);
    border-radius: 3px;
    overflow: hidden;
}
.conf-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--green));
    border-radius: 3px;
    transition: width 0.6s ease-out;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    min-height: 44px;
    transition: all var(--transition);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: linear-gradient(135deg, var(--gold), #e6b422);
    color: #2d2a24;
}
.btn-primary:hover { box-shadow: 0 4px 16px var(--gold-glow); }

.btn-success {
    background: linear-gradient(135deg, var(--green), var(--green));
    color: var(--bg);
}

.btn-ghost {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

/* === Drop Zone === */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--gold);
    background: var(--gold-dim);
}
.drop-zone p { color: var(--text-muted); font-size: 14px; margin-top: 8px; }

/* === Mode Switcher === */
.mode-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 4px;
    margin-bottom: 20px;
}
.mode-tab {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--radius-xs);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-muted);
    border: none;
    background: transparent;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.mode-tab.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* === Camera === */
.camera-container {
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--camera-bg);
    box-shadow: var(--shadow-lg);
}

.camera-wrap {
    position: relative;
    background: var(--camera-bg);
    aspect-ratio: 4/3;
}
.camera-wrap video, .camera-wrap canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.camera-ring {
    width: 260px;
    height: 260px;
    border: 3px dashed rgba(212, 160, 23, 0.5);
    border-radius: 50%;
    animation: pulse-ring 2s ease-in-out infinite;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.15);
}
.camera-hint {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    font-weight: 600;
    margin-top: 12px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
@keyframes pulse-ring {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.02); }
}

/* Top controls — overlaid on viewfinder */
.camera-controls-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    pointer-events: none;
}
.camera-controls-overlay > * { pointer-events: auto; }
.camera-top-controls {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
}

/* Action bar — BELOW viewfinder for easy thumb reach */
.camera-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px 24px;
    background: var(--cam-bar-bg);
    border-top: 1px solid var(--border);
}

.cam-btn-overlay {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.cam-btn-overlay:hover { background: rgba(0,0,0,0.65); }
.cam-btn-overlay.torch-on { background: var(--gold); color: #2d2a24; }

/* Capture button in action bar — styled to match its new context */
.cam-btn-action {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.cam-btn-action:hover { background: var(--surface-3); color: var(--text); }

.capture-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    border: 4px solid var(--border);
    box-shadow: 0 2px 12px var(--gold-glow), inset 0 -2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
.capture-btn-inner {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid var(--gold);
    transition: background 0.1s;
}
[data-theme="dark"] .capture-btn { border-color: rgba(255,255,255,0.2); }
[data-theme="dark"] .capture-btn-inner { background: var(--surface-2); }
.capture-btn:hover { transform: scale(1.05); }
.capture-btn:active { transform: scale(0.92); }
.capture-btn:active .capture-btn-inner { background: var(--gold-dim); }

/* === Scanning Animation === */
.scanning-state { text-align: center; padding: 48px 20px; }
.scan-anim { position: relative; width: 140px; height: 140px; margin: 0 auto 24px; }
.scan-coin-spin {
    width: 120px;
    height: 120px;
    margin: 10px auto;
    border-radius: 50%;
    overflow: hidden;
    background: linear-gradient(135deg, var(--gold-dim), var(--gold-glow));
    animation: coin-wobble 1.2s ease-in-out infinite;
    box-shadow: 0 4px 20px var(--gold-glow);
}
.scan-coin-spin img { display: block; }
.scan-ring-pulse {
    position: absolute;
    inset: 0;
    border: 2px solid var(--gold);
    border-radius: 50%;
    animation: scan-pulse 1.5s ease-out infinite;
}
@keyframes coin-wobble {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.02) rotate(1deg); }
    75% { transform: scale(0.98) rotate(-1deg); }
}
@keyframes scan-pulse {
    0% { transform: scale(0.85); opacity: 1; }
    100% { transform: scale(1.3); opacity: 0; }
}
.scan-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

/* === Results === */
.results-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    animation: resultsIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes resultsIn {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.results-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.results-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.added-badge {
    background: var(--green-dim);
    color: var(--green);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 14px;
    animation: resultsIn 0.3s ease-out;
}
.auto-saved-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--green-dim);
    color: var(--green);
    padding: 6px 12px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    margin-top: 8px;
    animation: resultsIn 0.4s ease-out;
}
.value-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 2px;
    color: var(--text-muted);
}

/* Match rows */
.match-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    border-left: 4px solid transparent;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    transition: background var(--transition);
}
.match-row:last-child { border-bottom: none; }
.match-row.value-high { border-left-color: var(--green); background: var(--green-dim); }
.match-row.value-face { border-left-color: var(--error); background: var(--error-dim); }
.match-row.value-mid { border-left-color: var(--gold); background: var(--gold-dim); }

.match-rank {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface-2);
    flex-shrink: 0;
}
.match-rank.top {
    background: linear-gradient(135deg, var(--gold-dim), var(--gold-glow));
    color: var(--gold);
}
.match-info { flex: 1; min-width: 0; }
.match-name { font-weight: 700; font-size: 15px; }
.match-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.match-value { font-weight: 800; color: var(--green); font-size: 18px; white-space: nowrap; }

/* Value indicator dot */
.value-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}
.value-indicator.high { background: var(--green); box-shadow: 0 0 6px var(--green); }
.value-indicator.face { background: var(--error); box-shadow: 0 0 6px var(--error); }
.value-indicator.mid { background: var(--gold); box-shadow: 0 0 6px var(--gold); }

/* === Scan List (Dashboard recent scans) === */
.scan-list { display: flex; flex-direction: column; gap: 10px; }

.scan-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: box-shadow var(--transition), transform var(--transition);
}
.scan-item:hover { box-shadow: var(--shadow); }
.scan-item:active { transform: scale(0.99); }

.scan-item-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
}
.scan-item-info { flex: 1; min-width: 0; }

.scan-item-detail {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
    animation: slideDown 0.25s ease-out;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.scan-detail-img {
    width: 100%;
    max-width: 300px;
    border-radius: var(--radius-sm);
    margin: 0 auto 12px;
    display: block;
    border: 2px solid var(--gold-dim);
}
.scan-detail-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}
.scan-detail-meta strong {
    color: var(--text);
    font-weight: 600;
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

/* === Collection Card View (Mobile) === */
.collection-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.collection-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: box-shadow var(--transition), transform var(--transition);
}
.collection-card:hover { box-shadow: var(--shadow); }
.collection-card-info { flex: 1; min-width: 0; }
.collection-card-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.collection-card-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin-bottom: 6px;
}
.collection-card-value {
    font-weight: 800;
    font-size: 18px;
    color: var(--green);
}

/* Coin card (grid) */
.coin-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 4px solid transparent;
    transition: border-color var(--transition);
}
.coin-card.value-high { border-color: var(--green); }
.coin-card.value-face { border-color: var(--error); }
.coin-card.value-mid { border-color: var(--gold); }

/* === Station === */
.station-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.station-stream {
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--camera-bg);
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.station-stream img { width: 100%; height: 100%; object-fit: contain; }
.station-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 13px;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); animation: dotPulse 2s ease-in-out infinite; }
.status-dot.offline { background: var(--error); }
@keyframes dotPulse {
    0%, 100% { box-shadow: 0 0 6px var(--green); }
    50% { box-shadow: 0 0 12px var(--green); }
}

/* === Result Panel (Station) === */
.result-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 20px;
    padding: 20px;
    box-shadow: var(--shadow);
    animation: resultsIn 0.3s ease-out;
}
.result-panel h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
    margin-bottom: 16px;
}

/* === Settings === */
.settings-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.settings-group-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 14px 20px 8px;
}
.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
    min-height: 56px;
    -webkit-tap-highlight-color: transparent;
}
.settings-row:hover { background: var(--surface-2); }
.settings-row.no-hover { cursor: default; }
.settings-row.no-hover:hover { background: transparent; }
.settings-label { flex: 1; min-width: 0; }
.settings-name { font-size: 15px; font-weight: 600; color: var(--text); }
.settings-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.settings-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    min-height: 44px;
    cursor: pointer;
}
.settings-input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    min-height: 44px;
    width: 180px;
}

/* Toggle switch */
.toggle {
    width: 48px;
    height: 28px;
    border-radius: 14px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    position: relative;
    transition: background var(--transition);
    flex-shrink: 0;
}
.toggle.on { background: var(--green); border-color: var(--green); }
.toggle-knob {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--toggle-knob);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
}
.toggle.on .toggle-knob { transform: translateX(20px); }

/* === Guide Accordion === */
.guide-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.guide-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition);
    user-select: none;
}
.guide-section-header:hover { background: var(--surface-2); }
.guide-section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}
.guide-section-icon { font-size: 20px; }
.guide-chevron {
    transition: transform var(--transition);
    color: var(--text-muted);
    flex-shrink: 0;
}
.guide-chevron.open { transform: rotate(180deg); }

.guide-item {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}
.guide-item-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.guide-item-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* === Empty State === */
.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }
.empty a { color: var(--gold); font-weight: 600; text-decoration: none; }
.empty a:hover { text-decoration: underline; }

/* === Toast === */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--green);
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    animation: toastIn 0.3s ease-out;
}
@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, 12px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* === Loading === */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }

.spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Search Input === */
.search-input {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    min-height: 44px;
    width: 220px;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
    font-family: var(--font);
}
.search-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}

/* === Utility === */
.text-muted { color: var(--text-muted); }
.text-gold { color: var(--gold); }
.text-green { color: var(--green); }
.text-error { color: var(--error); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-bold { font-weight: 700; }
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-md { font-size: 15px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }
.text-2xl { font-size: 20px; }
.text-800 { font-weight: 800; }
.font-italic { font-style: italic; }
.mt-2 { margin-top: 2px; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-2 { margin-bottom: 2px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.ml-6 { margin-left: 6px; }
.p-0 { padding: 0; }
.px-20 { padding-left: 20px; padding-right: 20px; }
.py-32 { padding-top: 32px; padding-bottom: 32px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.flex-col { flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-shrink-0 { flex-shrink: 0; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.max-w-sm { max-width: 640px; }
.max-w-md { max-width: 800px; }
.line-height-2 { line-height: 2; }
.border-error { border-color: var(--error); }
.border-green { border-color: var(--green); }
.no-pad { padding: 0; }
.cursor-pointer { cursor: pointer; }
.spinner-sm { width: 16px; height: 16px; }
.spinner-xs { width: 14px; height: 14px; }
.mb-24 { margin-bottom: 24px; }
.pb-32 { padding-bottom: 32px; }

/* Inline code snippets */
.code-inline {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* Result preview image */
.result-preview-img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--gold);
    box-shadow: 0 2px 8px var(--gold-glow);
}

/* Scan icon inline with margin */
.icon-mr { margin-right: 4px; vertical-align: -2px; }

/* Settings seed button compact */
.btn-compact {
    font-size: 13px;
    padding: 6px 14px;
    min-height: 44px;
    flex-shrink: 0;
}

/* Scan coin spinner */
.scan-coin-img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
}

/* Ordered list for setup guides */
.setup-list {
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 2;
}

/* Spacer element (for camera action bar alignment) */
.spacer-48 { width: 48px; }

input[type="file"] { display: none; }
[x-cloak] { display: none !important; }

/* === Responsive === */
@media (max-width: 640px) {
    header { padding: 0 16px; }
    main { padding: 16px 16px 110px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px 16px; }
    .stat-card .value { font-size: 24px; }
    .hero-banner { flex-direction: column; text-align: center; padding: 20px; gap: 12px; }
    .hero-banner::after { display: none; }
    .camera-ring { width: 200px; height: 200px; }
    .camera-action-bar { padding: 16px 24px 20px; }

    /* Collection: hide table, show cards */
    .table-wrap.desktop-only { display: none; }
    .collection-cards.mobile-only { display: grid; }

    /* Results on mobile */
    .results-header { flex-direction: column; text-align: center; gap: 12px; }
    .results-actions { flex-direction: column; }
    .results-actions .btn { width: 100%; justify-content: center; }

    /* Settings responsive */
    .settings-row { flex-wrap: wrap; }
    .settings-input { width: 100%; }
    .settings-select { min-width: 120px; }

    /* Search */
    .search-input { width: 100%; }
    .section-header { flex-direction: column; align-items: stretch; }
}

@media (min-width: 641px) {
    .collection-cards.mobile-only { display: none; }
}

/* === Clickable Table Rows === */
.clickable-row { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.clickable-row:hover td { background: var(--surface-2); }
.clickable-row:active td { background: var(--surface-3); }

/* === Collection Card Links === */
.collection-card-link {
    text-decoration: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}
.collection-card-link:active { transform: scale(0.98); }

/* === Coin Detail Page === */
.detail-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 16px;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.detail-back:hover { color: var(--text); }

.detail-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.detail-image-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}
.detail-image {
    width: 100%;
    max-width: 320px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 3px solid var(--gold-dim);
    box-shadow: 0 4px 16px var(--gold-glow);
}
.detail-placeholder {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold-dim), var(--gold-glow));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    border: 3px dashed var(--gold);
}

.detail-name {
    font-size: 22px;
    font-weight: 800;
    color: var(--text);
    text-align: center;
    margin-bottom: 12px;
}

.detail-tags {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.detail-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.detail-tag-gold {
    background: var(--gold-dim);
    color: var(--gold);
    border-color: transparent;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.detail-field-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.detail-field-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.detail-notes {
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-bottom: 16px;
}
.detail-notes-text {
    font-size: 14px;
    color: var(--text);
    line-height: 1.6;
    white-space: pre-wrap;
}

.detail-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* === Value Disclaimer === */
.value-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    background: var(--gold-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 16px;
}
.value-disclaimer svg { flex-shrink: 0; margin-top: 1px; color: var(--gold); }
.value-disclaimer strong { color: var(--text); }
.value-disclaimer a { color: var(--gold); text-decoration: none; font-weight: 600; }
.value-disclaimer a:hover { text-decoration: underline; }

/* === Edit Form === */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
}
.edit-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.edit-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: var(--text-muted);
}
.edit-input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text);
    font-family: var(--font);
    min-height: 44px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.edit-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}
.edit-textarea {
    min-height: 80px;
    resize: vertical;
}
