*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif; background: #080c16; color: #e2e8f0; overflow: hidden; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; }

/* ── Header — glassmorphism ── */
#header { position: fixed; top: 0; left: 0; right: 0; height: 52px; background: rgba(17,24,39,.82); backdrop-filter: blur(20px) saturate(1.5); -webkit-backdrop-filter: blur(20px) saturate(1.5); display: flex; align-items: center; padding: 0 16px; gap: 12px; z-index: 100; border-bottom: 1px solid rgba(30,45,74,.6); }
#header h1 { font-size: 17px; font-weight: 800; color: #10b981; flex-shrink: 0; letter-spacing: -.02em; }
#project-select { flex: 1; background: rgba(30,41,59,.7); color: #e2e8f0; border: 1px solid rgba(51,65,85,.5); border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 500; -webkit-appearance: none; }

/* ── Screens ── */
.screen { position: fixed; top: 52px; left: 0; right: 0; bottom: 0; display: none; }
.screen.active { display: flex; }
#scan-screen, #search-screen, #interchange-screen, #test-screen { background: #080c16; }

/* ── Home — big touch targets ── */
#scan-screen { flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; background: radial-gradient(ellipse at 50% 30%, rgba(16,185,129,.04) 0%, transparent 70%); }
.home-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; width: min(92vw, 420px); }
.home-btn { min-height: 180px; border-radius: 24px; border: 1.5px solid rgba(51,65,85,.6); background: rgba(17,24,39,.8); backdrop-filter: blur(8px); color: #e2e8f0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; cursor: pointer; transition: transform .2s cubic-bezier(.34,1.56,.64,1), background .25s, border-color .25s, box-shadow .25s; -webkit-tap-highlight-color: transparent; }
.home-btn span { font-size: 14px; font-weight: 800; letter-spacing: .05em; }
.home-btn:active { transform: scale(0.94); }
.home-btn svg { transition: transform .25s; }
.home-btn:active svg { transform: scale(1.1); }
.scan-home-btn { border-color: rgba(16,185,129,.35); background: rgba(16,185,129,.06); color: #10b981; }
.scan-home-btn:active { background: rgba(16,185,129,.15); box-shadow: 0 0 40px rgba(16,185,129,.15); }
.search-home-btn { border-color: rgba(56,189,248,.3); background: rgba(56,189,248,.05); color: #38bdf8; }
.search-home-btn:active { background: rgba(56,189,248,.12); box-shadow: 0 0 40px rgba(56,189,248,.12); }
.hint { color: #64748b; font-size: 13px; text-align: center; max-width: 280px; line-height: 1.5; }

/* ── Search & Forms ── */
#search-screen, #interchange-screen, #test-screen { overflow-y: auto; align-items: flex-start; justify-content: center; }
.search-container, .form-container { width: min(100%, 560px); margin: 0 auto; padding: 16px; }
.search-container { display: flex; flex-direction: column; min-height: 100%; gap: 12px; }
.search-header, .form-header { display: flex; align-items: center; gap: 12px; }
.form-header { margin-bottom: 20px; }
.form-header h2 { font-size: 20px; font-weight: 800; color: #f1f5f9; letter-spacing: -.02em; }
.back-btn-inline { width: 40px; height: 40px; border-radius: 12px; border: 1px solid rgba(51,65,85,.5); background: rgba(30,41,59,.6); backdrop-filter: blur(8px); color: #e2e8f0; font-size: 18px; cursor: pointer; flex-shrink: 0; transition: all .15s; display: flex; align-items: center; justify-content: center; }
.back-btn-inline:active { transform: scale(.92); background: rgba(30,41,59,.9); }
.search-input-wrap, .ic-replacement-input { display: flex; align-items: center; gap: 8px; width: 100%; background: rgba(17,24,39,.7); border: 1px solid rgba(51,65,85,.5); border-radius: 16px; padding: 0 14px; transition: border-color .2s; }
.search-input-wrap:focus-within, .ic-replacement-input:focus-within { border-color: rgba(16,185,129,.5); }
.search-icon { flex-shrink: 0; opacity: .5; }
#search-input, #ic-replacement-sr, .test-field input, .form-container textarea { width: 100%; background: transparent; border: none; color: #f1f5f9; outline: none; font-size: 15px; font-weight: 500; }
#search-input, #ic-replacement-sr, .test-field input { height: 50px; }
#search-input::placeholder, #ic-replacement-sr::placeholder, .test-field input::placeholder, .form-container textarea::placeholder { color: #475569; }
.form-container textarea { min-height: 92px; resize: vertical; padding: 14px 16px; background: rgba(17,24,39,.7); border: 1px solid rgba(51,65,85,.5); border-radius: 16px; transition: border-color .2s; font-size: 14px; }
.form-container textarea:focus { border-color: rgba(16,185,129,.5); }
.search-clear-btn, .ic-scan-btn { width: 36px; height: 36px; border-radius: 10px; border: none; background: rgba(51,65,85,.5); color: #e2e8f0; cursor: pointer; flex-shrink: 0; transition: all .15s; }
.search-clear-btn:active, .ic-scan-btn:active { transform: scale(.9); background: rgba(51,65,85,.8); }
.ic-scan-btn { display: inline-flex; align-items: center; justify-content: center; }
.search-results { flex: 1; overflow-y: auto; padding-bottom: 18px; }
.search-results.compact-results { max-height: 240px; margin-top: 10px; padding-bottom: 0; }
.search-empty { padding: 24px 16px; border: 1px dashed rgba(51,65,85,.5); border-radius: 16px; color: #64748b; text-align: center; background: rgba(17,24,39,.4); font-size: 13px; line-height: 1.5; }
.search-result-item { width: 100%; text-align: left; background: rgba(26,34,54,.7); border: 1px solid rgba(51,65,85,.4); border-radius: 16px; padding: 14px 16px; color: #e2e8f0; cursor: pointer; margin-bottom: 8px; transition: transform .2s cubic-bezier(.34,1.56,.64,1), border-color .2s, background .2s; }
.search-result-item:active { transform: scale(0.97); }
.search-result-item:hover { border-color: rgba(16,185,129,.4); background: rgba(16,185,129,.04); }
.search-result-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.search-result-sr { font-size: 15px; font-weight: 800; color: #f1f5f9; letter-spacing: -.01em; }
.search-result-type { font-size: 12px; color: #94a3b8; margin-top: 3px; font-weight: 500; }
.search-result-meta { margin-top: 8px; font-size: 12px; color: #64748b; font-weight: 500; }
.search-result-badge { padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.search-result-badge.installed { background: #064e3b; color: #6ee7b7; }
.search-result-badge.in_warehouse { background: #172554; color: #93c5fd; }
.search-result-badge.on_site { background: #451a03; color: #fcd34d; }
.search-result-badge.not_delivered { background: #1e293b; color: #94a3b8; }
.search-result-badge.damaged { background: #450a0a; color: #fca5a5; }

/* ── Scanner — animated targeting frame ── */
#scanner-overlay { background: #000; flex-direction: column; align-items: center; justify-content: center; z-index: 200; }
#scanner-video { width: 100%; height: 100%; object-fit: cover; }
.scanner-frame { position: absolute; width: 260px; height: 260px; border: 2.5px solid rgba(16,185,129,.7); border-radius: 20px; box-shadow: 0 0 0 9999px rgba(0,0,0,.55), 0 0 60px rgba(16,185,129,.15) inset; animation: scanner-pulse 2s ease-in-out infinite; }
.scanner-frame::before { content: ''; position: absolute; top: -6px; left: 50%; width: 50px; height: 3px; background: #10b981; border-radius: 2px; transform: translateX(-50%); box-shadow: 0 0 12px rgba(16,185,129,.6); }
@keyframes scanner-pulse { 0%, 100% { border-color: rgba(16,185,129,.7); } 50% { border-color: rgba(16,185,129,.35); } }
.close-btn { position: absolute; top: env(safe-area-inset-top, 12px); right: 12px; width: 44px; height: 44px; border-radius: 50%; background: rgba(0,0,0,.5); backdrop-filter: blur(8px); color: #fff; border: 1px solid rgba(255,255,255,.15); font-size: 22px; cursor: pointer; z-index: 210; display: flex; align-items: center; justify-content: center; }

/* ── Result Screen + Info Card ── */
#result-screen { flex-direction: column; }
#viewer-container { flex: 1; width: 100%; background: #0a0f1a; }
#info-card { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(17,24,39,.92); backdrop-filter: blur(24px) saturate(1.6); -webkit-backdrop-filter: blur(24px) saturate(1.6); border-radius: 22px 22px 0 0; padding: 6px 18px calc(env(safe-area-inset-bottom, 16px) + 16px); z-index: 50; max-height: 62vh; overflow-y: auto; box-shadow: 0 -8px 40px rgba(0,0,0,.5); }
.card-handle { width: 36px; height: 4px; background: rgba(71,85,105,.6); border-radius: 2px; margin: 4px auto 12px; }
.card-sr { font-size: 30px; font-weight: 800; color: #10b981; text-align: center; letter-spacing: -.02em; text-shadow: 0 0 40px rgba(16,185,129,.2); }
.card-type { font-size: 13px; color: #94a3b8; text-align: center; margin-bottom: 14px; font-weight: 500; }
.card-route { display: flex; justify-content: center; align-items: center; gap: 6px; margin-bottom: 16px; font-size: 13px; }
.route-prev, .route-next { color: #e2e8f0; cursor: pointer; padding: 7px 12px; background: rgba(51,65,85,.5); border-radius: 10px; border: 1px solid rgba(51,65,85,.4); font-weight: 600; font-size: 12px; transition: all .15s; min-width: 44px; text-align: center; }
.route-prev:active, .route-next:active { transform: scale(.95); background: rgba(51,65,85,.8); }
.route-current { color: #10b981; font-weight: 800; padding: 7px 14px; background: rgba(16,185,129,.12); border-radius: 10px; border: 1px solid rgba(16,185,129,.25); font-size: 12px; }
.card-details { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.detail { text-align: center; background: rgba(30,41,59,.4); border-radius: 10px; padding: 8px 4px; }
.detail label { display: block; font-size: 9px; color: #64748b; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; font-weight: 600; }
.detail span { font-size: 14px; font-weight: 700; }
.status-badge { display: inline-flex; align-items: center; justify-content: center; padding: 4px 10px; border-radius: 999px; font-size: 11px !important; font-weight: 700; min-width: 80px; }
.status-badge.installed { background: #064e3b; color: #6ee7b7; }
.status-badge.in_warehouse { background: #172554; color: #93c5fd; }
.status-badge.on_site { background: #451a03; color: #fcd34d; }
.status-badge.not_delivered { background: #1e293b; color: #94a3b8; }
.status-badge.damaged { background: #450a0a; color: #fca5a5; }
.card-storage, .card-meta-block { background: rgba(30,41,59,.5); border: 1px solid rgba(51,65,85,.3); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.card-storage label, .card-meta-block label { font-size: 11px; color: #64748b; display: block; margin-bottom: 4px; font-weight: 600; }
.card-storage span { font-size: 14px; font-weight: 700; margin-right: 12px; }
.card-meta-block { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.interchange-badge, .test-badge { padding: 4px 12px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.interchange-badge.pending { background: #451a03; color: #fcd34d; }
.interchange-badge.approved { background: #064e3b; color: #6ee7b7; }
.interchange-badge.rejected { background: #450a0a; color: #fca5a5; }
.test-badge.pass { background: #064e3b; color: #6ee7b7; }
.test-badge.fail { background: #450a0a; color: #fca5a5; }
.test-badge.not-tested { background: #1e293b; color: #64748b; }
.card-actions, .card-actions-row2 { display: grid; gap: 8px; }
.card-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-actions-row2 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 8px; }
.action-btn { width: 100%; padding: 14px 8px; border: none; border-radius: 14px; font-size: 13px; font-weight: 700; cursor: pointer; -webkit-tap-highlight-color: transparent; background: rgba(51,65,85,.5); color: #e2e8f0; transition: transform .15s cubic-bezier(.34,1.56,.64,1), background .2s; letter-spacing: .01em; }
.action-btn.green { background: #10b981; color: #fff; box-shadow: 0 4px 20px rgba(16,185,129,.25); }
.action-btn.green:active:not(:disabled) { background: #059669; box-shadow: 0 2px 10px rgba(16,185,129,.3); }
.action-btn.orange { background: #f97316; color: #fff; box-shadow: 0 4px 20px rgba(249,115,22,.2); }
.action-btn.orange:active:not(:disabled) { background: #ea580c; }
.action-btn.purple { background: #8b5cf6; color: #fff; box-shadow: 0 4px 20px rgba(139,92,246,.2); }
.action-btn.purple:active:not(:disabled) { background: #7c3aed; }
.action-btn:active:not(:disabled) { transform: scale(0.96); }
.action-btn:disabled { opacity: .4; cursor: not-allowed; }
.full-width { width: 100%; }
.center { text-align: center; }

.route-panel { position: absolute; top: 8px; right: 0; width: 240px; background: rgba(30,41,59,0.95); border-radius: 8px 0 0 8px; z-index: 50; transition: transform .3s; }
.route-panel.collapsed { transform: translateX(200px); }
.route-toggle-btn { position: absolute; left: -1px; top: 0; padding: 8px 10px; background: rgba(30,41,59,0.95); color: #94a3b8; border: none; border-radius: 8px 0 0 8px; font-size: 12px; cursor: pointer; writing-mode: vertical-rl; }
.route-list { padding: 8px 10px; max-height: 60vh; overflow-y: auto; }
.route-item { padding: 8px 10px; border-radius: 6px; font-size: 13px; color: #cbd5e1; cursor: pointer; margin-bottom: 4px; display: flex; justify-content: space-between; align-items: center; transition: all .15s; -webkit-tap-highlight-color: transparent; border: 1px solid transparent; }
.route-item:hover { background: #334155; border-color: #475569; }
.route-item:active { transform: scale(0.98); }
.route-item.current { background: rgba(16,185,129,0.18); color: #10b981; font-weight: 700; border-color: #10b981; }
.route-item .seq { color: #94a3b8; font-size: 11px; }
.route-item .arrow { color: #64748b; font-size: 16px; margin-left: 4px; }

/* ── Forms ── */
.form-section { margin-bottom: 18px; }
.form-label { display: block; font-size: 11px; font-weight: 700; color: #64748b; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .07em; }
.form-readonly { background: rgba(17,24,39,.7); border: 1px solid rgba(51,65,85,.4); border-radius: 14px; padding: 14px 16px; font-size: 16px; font-weight: 800; color: #f1f5f9; letter-spacing: -.01em; }
.form-hint { margin-top: 8px; font-size: 12px; color: #475569; font-weight: 500; }
.form-actions { margin-top: 12px; }
.test-inputs { display: grid; gap: 10px; }
.test-field { background: rgba(17,24,39,.7); border: 1px solid rgba(51,65,85,.4); border-radius: 14px; padding: 14px 16px; transition: border-color .2s; }
.test-field:focus-within { border-color: rgba(16,185,129,.4); }
.test-field > label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 700; color: #94a3b8; }
.test-result { display: inline-flex; margin-top: 6px; font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 6px; }
.test-result.pass { color: #6ee7b7; background: rgba(16,185,129,.1); }
.test-result.fail { color: #fca5a5; background: rgba(239,68,68,.1); }
.test-overall { padding: 16px; border-radius: 16px; text-align: center; font-size: 17px; font-weight: 800; margin-bottom: 16px; letter-spacing: -.01em; }
.test-overall.pass { background: rgba(16,185,129,.1); color: #6ee7b7; border: 1px solid rgba(16,185,129,.2); }
.test-overall.fail { background: rgba(239,68,68,.1); color: #fca5a5; border: 1px solid rgba(239,68,68,.2); }
.test-history { display: grid; gap: 10px; }
.test-history-entry { background: rgba(17,24,39,.6); border: 1px solid rgba(51,65,85,.3); border-radius: 14px; padding: 14px 16px; }
.test-history-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.test-history-meta { font-size: 12px; color: #475569; font-weight: 500; }
.test-history-values { display: grid; gap: 4px; font-size: 13px; color: #cbd5e1; }

/* ── Back / Loading ── */
.back-btn { position: absolute; top: 10px; left: 10px; background: rgba(17,24,39,.7); backdrop-filter: blur(12px); color: #e2e8f0; border: 1px solid rgba(51,65,85,.4); padding: 8px 16px; border-radius: 12px; font-size: 13px; font-weight: 600; cursor: pointer; z-index: 50; transition: all .15s; }
.back-btn:active { transform: scale(.95); background: rgba(17,24,39,.9); }
#loading-overlay { position: absolute; inset: 0; background: rgba(8,12,22,.88); backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; z-index: 60; }
#loading-overlay.active { display: flex; }
.spinner { width: 36px; height: 36px; border: 2.5px solid rgba(51,65,85,.5); border-top-color: #10b981; border-radius: 50%; animation: spin .65s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: #94a3b8; font-size: 13px; font-weight: 500; }
.adsk-viewing-viewer { background: #0a0f1a !important; }

/* ── Responsive ── */
@media (max-width: 480px) {
  .home-buttons { grid-template-columns: 1fr; width: min(88vw, 340px); }
  .home-btn { min-height: 140px; }
  .card-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-actions { grid-template-columns: 1fr; }
  .card-actions-row2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .route-panel { width: 220px; }
  .route-panel.collapsed { transform: translateX(182px); }
  #info-card { max-height: 70vh; }
  .card-sr { font-size: 26px; }
}

/* ── Safe area padding for notched phones ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #info-card { padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
  #scan-screen { padding-bottom: env(safe-area-inset-bottom); }
}
