/* ============================================================
   VISIONLAB — styles.css
   OpenCV.js Browser Image Processing Toolkit
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;700&family=IBM+Plex+Sans:wght@300;400;600;700&display=swap');

/* ── VARIABLES ─────────────────────────────────────────────── */
:root {
  --bg:        #060a0f;
  --bg2:       #0a1018;
  --bg3:       #0e1520;
  --panel:     #111a24;
  --panel2:    #152030;
  --border:    #1c2c3c;
  --border2:   #243444;
  --accent:    #00d4f0;
  --accent-dim:#00d4f022;
  --green:     #00e896;
  --green-dim: #00e89618;
  --orange:    #f06030;
  --orange-dim:#f0603018;
  --red:       #f04050;
  --text:      #b8ccd8;
  --text-dim:  #506070;
  --text-mid:  #7898a8;
  --text-bright:#e0eef8;
  --mono:      'IBM Plex Mono', monospace;
  --sans:      'IBM Plex Sans', sans-serif;
  --radius:    6px;
  --transition: 0.15s ease;
}

/* ── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle grid texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0,212,240,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,212,240,0.018) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── LOADING ────────────────────────────────────────────────── */
.loading {
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 50% 35%, rgba(0, 212, 240, 0.12), transparent 56%),
    radial-gradient(circle at 80% 70%, rgba(0, 232, 150, 0.08), transparent 44%),
    var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  overflow: hidden;
  isolation: isolate;
  transition: opacity 0.45s ease, transform 0.45s ease, filter 0.45s ease;
  gap: 20px;
}
.loading::before,
.loading::after {
  content: '';
  position: absolute;
  pointer-events: none;
}
.loading::before {
  top: 50%;
  left: 50%;
  width: min(65vmax, 700px);
  aspect-ratio: 1;
  border: 1px solid rgba(0, 212, 240, 0.2);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: loaderOrbit 2.2s linear infinite;
}
.loading::after {
  inset: -35%;
  background: linear-gradient(
    120deg,
    transparent 30%,
    rgba(0, 212, 240, 0.09) 50%,
    transparent 70%
  );
  mix-blend-mode: screen;
  animation: loaderSweep 2.6s linear infinite;
}
.loading.hidden {
  opacity: 0;
  transform: scale(1.02);
  filter: blur(10px);
  pointer-events: none;
}
.loading-logo {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 36px;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--text-bright);
  text-shadow: 0 0 0 rgba(0, 212, 240, 0.0);
  animation: logoPulse 1.1s ease-in-out infinite;
  position: relative;
  z-index: 1;
}
.loading-logo span {
  color: var(--accent);
  text-shadow: 0 0 24px rgba(0, 212, 240, 0.45);
}
.loading-sub {
  font-size: 10px;
  letter-spacing: 3px;
  color: var(--text-dim);
  text-transform: uppercase;
  animation: subFlicker 1.1s ease-in-out infinite;
  position: relative;
  z-index: 1;
}
.loading-bar {
  width: min(300px, 68vw);
  height: 3px;
  border-radius: 999px;
  background: rgba(36, 52, 68, 0.7);
  box-shadow: inset 0 0 0 1px rgba(0, 212, 240, 0.1);
  overflow: hidden;
  position: relative;
  z-index: 1;
}
.loading-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    rgba(0, 212, 240, 0.8) 0%,
    rgba(0, 232, 150, 0.95) 45%,
    rgba(0, 212, 240, 0.8) 100%
  );
  background-size: 220% 100%;
  animation: barload 1s cubic-bezier(0.4,0,0.2,1) forwards, barShimmer 0.75s linear infinite;
  width: 0;
  box-shadow: 0 0 16px rgba(0, 212, 240, 0.4);
}
@keyframes barload { to { width: 100%; } }
@keyframes barShimmer { to { background-position: 220% 0; } }
@keyframes loaderOrbit {
  0% { transform: translate(-50%, -50%) rotate(0deg) scale(0.9); opacity: 0.2; }
  50% { opacity: 0.55; }
  100% { transform: translate(-50%, -50%) rotate(360deg) scale(1.08); opacity: 0.2; }
}
@keyframes loaderSweep {
  0% { transform: translateX(-18%) rotate(0deg); }
  100% { transform: translateX(18%) rotate(360deg); }
}
@keyframes logoPulse {
  0%, 100% {
    transform: translateY(1px) scale(0.995);
    text-shadow: 0 0 0 rgba(0, 212, 240, 0);
  }
  50% {
    transform: translateY(-3px) scale(1.018);
    text-shadow: 0 0 24px rgba(0, 212, 240, 0.32);
  }
}
@keyframes subFlicker {
  0%, 100% { opacity: 0.65; letter-spacing: 3px; }
  50% { opacity: 1; letter-spacing: 3.6px; }
}

header, .mobile-nav, .app {
  transition: opacity 0.45s ease, transform 0.45s ease, filter 0.45s ease;
}
body.loader-active header,
body.loader-active .mobile-nav,
body.loader-active .app {
  opacity: 0.02;
  transform: translateY(12px) scale(0.996);
  filter: blur(8px);
}
body.page-ready header,
body.page-ready .mobile-nav,
body.page-ready .app {
  opacity: 1;
  transform: none;
  filter: none;
}

@media (prefers-reduced-motion: reduce) {
  .loading,
  .loading::before,
  .loading::after,
  .loading-logo,
  .loading-sub,
  .loading-bar-fill,
  header,
  .mobile-nav,
  .app {
    animation: none !important;
    transition: none !important;
  }
}

/* ── HEADER ─────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(6,10,15,0.96);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
}
.logo {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-bright);
  white-space: nowrap;
  flex-shrink: 0;
}
.logo span { color: var(--accent); }
.logo-sep {
  width: 1px; height: 24px;
  background: var(--border2);
  flex-shrink: 0;
}

/* GLOBAL UPLOAD STRIP */
.global-upload-strip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.global-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg3);
  color: var(--text-mid);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--transition);
  letter-spacing: 0.5px;
}
.global-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.global-upload-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.global-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}
.global-file-name {
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.global-file-meta {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}
.global-badge {
  font-size: 9px;
  padding: 2px 7px;
  border-radius: 2px;
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid #00e89630;
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}
.no-image-hint {
  font-size: 11px;
  color: var(--text-dim);
}

/* STATUS */
.cv-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.cv-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1.4s ease-in-out infinite;
}
.cv-dot.ready { background: var(--green); animation: none; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

/* ── MOBILE NAV ─────────────────────────────────────────────── */
.mobile-nav {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  scrollbar-width: none;
}
.mobile-nav::-webkit-scrollbar { display: none; }
.mobile-nav-item {
  white-space: nowrap;
  padding: 5px 11px;
  border-radius: 20px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
  transition: all var(--transition);
  flex-shrink: 0;
}
.mobile-nav-item.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── APP LAYOUT ─────────────────────────────────────────────── */
.app {
  display: flex;
  min-height: calc(100vh - 56px);
  align-items: flex-start;
  position: relative;
  z-index: 1;
}

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-width: 220px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  z-index: 10;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-label {
  padding: 0 16px 10px;
  font-size: 9px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.nav-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text-dim);
  border-left: 2px solid transparent;
  transition: all var(--transition);
  font-size: 11px;
  line-height: 1.4;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}
.nav-num {
  font-size: 9px;
  color: var(--text-dim);
  background: var(--border);
  border-radius: 3px;
  padding: 2px 5px;
  flex-shrink: 0;
  margin-top: 1px;
  letter-spacing: 0.5px;
  font-family: var(--mono);
}
.nav-item.active .nav-num {
  background: var(--accent);
  color: #000;
  font-weight: 700;
}

/* ── CONTENT ────────────────────────────────────────────────── */
.content {
  flex: 1;
  min-width: 0;
  width: 0;
  padding: 28px 28px 60px;
  overflow-x: hidden;
}

/* ── SECTIONS ───────────────────────────────────────────────── */
.section { display: none; animation: fadeUp 0.25s ease; }
.section.active { display: block; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.section-tag {
  display: inline-block;
  font-size: 9px;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid #00d4f030;
  margin-bottom: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.section-header h2 {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 24px;
  color: var(--text-bright);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}
.section-header p {
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--sans);
}

/* No-image notice per section */
.no-img-notice {
  display: none;
  padding: 18px 20px;
  background: var(--bg3);
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 20px;
  text-align: center;
  line-height: 1.7;
}
.no-img-notice strong { color: var(--accent); }
.no-img-notice.visible { display: block; }

/* ── GRIDS ──────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.compare-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── PANEL ──────────────────────────────────────────────────── */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: var(--mono);
}
.panel-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.panel-dot.g { background: var(--green); }
.panel-dot.o { background: var(--orange); }
.panel-body { padding: 14px; }

/* ── CANVAS WRAP ────────────────────────────────────────────── */
.canvas-wrap {
  background: #02060a;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  border: 1px solid var(--border);
}
.canvas-wrap canvas { max-width: 100%; display: block; }
.canvas-placeholder {
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
  padding: 28px 20px;
  line-height: 2;
}
.canvas-placeholder .ph-icon {
  display: block;
  width: 32px; height: 32px;
  margin: 0 auto 10px;
  opacity: 0.3;
}

/* ── CONTROLS ───────────────────────────────────────────────── */
.control-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.control-label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 90px;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}
input[type="range"] {
  flex: 1;
  min-width: 80px;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--bg), 0 0 8px rgba(0,212,240,0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px rgba(0,212,240,0.4);
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
}
.control-value {
  font-size: 11px;
  color: var(--accent);
  min-width: 44px;
  text-align: right;
  font-family: var(--mono);
}

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text-mid);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  transition: all var(--transition);
  white-space: nowrap;
  letter-spacing: 0.3px;
}
.btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { background: #00bee8; border-color: #00bee8; color: #000; }
.btn.danger { border-color: #f0405030; color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: #f0405012; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

/* ── SELECT ─────────────────────────────────────────────────── */
select {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 12px;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
select:focus { border-color: var(--accent); }

/* ── STATS GRID ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.stat-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat-label {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 5px;
}
.stat-value {
  font-size: 20px;
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 500;
  line-height: 1.2;
}
.stat-value.green  { color: var(--green); }
.stat-value.orange { color: var(--orange); }

/* ── CODE BLOCK ─────────────────────────────────────────────── */
.code-block {
  background: #020608;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.8;
  overflow-x: auto;
  margin-top: 14px;
  white-space: pre;
  tab-size: 2;
  color: var(--text);
}
.code-block .kw { color: #5b9bd5; }
.code-block .fn { color: #d4b896; }
.code-block .st { color: #c08060; }
.code-block .cm { color: #486858; font-style: italic; }
.code-block .nu { color: #88b888; }

/* ── INFO BOX ───────────────────────────────────────────────── */
.info-box {
  background: rgba(0,212,240,0.04);
  border: 1px solid rgba(0,212,240,0.12);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 14px;
  line-height: 1.8;
  font-family: var(--sans);
}
.info-box strong { color: var(--accent); font-family: var(--mono); }

/* ── PIXEL TABLE ────────────────────────────────────────────── */
.pixel-table {
  border-collapse: collapse;
  font-size: 11px;
  width: 100%;
  min-width: 560px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.pixel-table td, .pixel-table th {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
}
.pixel-table td { color: var(--text-bright); }
.pixel-table th {
  background: var(--bg3);
  color: var(--text-dim);
  font-size: 9px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.pixel-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.pixel-cell-value { color: var(--text-bright); }
.pixel-cell-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(224, 238, 248, 0.35);
  box-shadow: 0 0 0 1px rgba(6, 10, 15, 0.7);
  flex-shrink: 0;
}

/* ── CHART ──────────────────────────────────────────────────── */
.chart-container { position: relative; height: 200px; }

/* ── SECTION DIVIDER ────────────────────────────────────────── */
.sub-divider {
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 10px;
  margin-top: 2px;
}

/* ── FACE CARDS ─────────────────────────────────────────────── */
.face-card {
  text-align: center;
}
.face-card canvas {
  width: 80px; height: 80px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  display: block;
}
.face-card-label {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 5px;
  letter-spacing: 0.5px;
  line-height: 1.5;
}

/* ── UPLOAD ZONE (section 01 main) ─────────────────────────── */
.upload-zone {
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg3);
  display: block;
}
.upload-zone:hover, .upload-zone.drag {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-zone input { display: none; }
.upload-zone-icon {
  width: 36px; height: 36px;
  color: var(--text-dim);
  margin: 0 auto 12px;
  display: block;
}
.upload-zone h3 {
  font-family: var(--sans);
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 4px;
  font-size: 14px;
}
.upload-zone p { color: var(--text-dim); font-size: 11px; }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 960px) {
  .sidebar { display: none; }
  .mobile-nav { display: flex; }
  .grid-2, .grid-3, .compare-row { grid-template-columns: 1fr; }
  .content { padding: 16px 16px 40px; }
  header { padding: 0 14px; gap: 12px; }
  .global-file-name { max-width: 120px; }
}
@media (max-width: 600px) {
  .global-file-meta, .no-image-hint { display: none; }
  .global-file-name { max-width: 90px; }
}
