:root {
  --bg: #0f172a;      /* slate-900 */
  --panel: #0b1020;   /* deep panel */
  --muted: #94a3b8;   /* slate-400 */
  --text: #e2e8f0;    /* slate-200 */
  --accent: #22d3ee;  /* cyan-400 */
  --accent-2: #06b6d4;/* cyan-500 */
  --error: #f87171;   /* red-400 */
  --ok: #4ade80;      /* green-400 */
  --border: #1f2937;  /* gray-800 */
  --focus: 0 0 0 3px rgba(34,211,238,0.35);
  --sidebar-w: 300px;
}
/* Light mode palette */
@media (prefers-color-scheme: light){
  :root{
    --bg:#f8fafc;           /* slate-50 */
    --panel:#ffffff;         /* white */
    --muted:#475569;         /* slate-600 */
    --text:#0f172a;          /* slate-900 */
    --border:#e2e8f0;        /* slate-200 */
  }
}

* { box-sizing: border-box; }
html:focus-within { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(1200px 800px at 10% 0%, #0b1220, var(--bg));
  color: var(--text);
}
@media (prefers-color-scheme: light){
  body{ background: radial-gradient(1200px 800px at 10% 0%, #e2e8f0, var(--bg)); }
}

/* App shell */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
@media (max-width: 960px){ .app { grid-template-columns: 1fr; } }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100dvh;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.00));
  padding: 16px; display: flex; flex-direction: column; gap: 14px;
}
.brand { display:flex; align-items:center; gap:10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 16px; height: 16px; border-radius: 4px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 24px rgba(34,211,238,.35); }
.brand-text { display:flex; flex-direction:column; line-height:1.1; }
.icon-btn { appearance:none; border:1px solid var(--border); background: #0b1220; color: var(--text); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.icon { font-size: 16px; }

.tabs { display:flex; flex-direction: column; gap: 8px; }
.tab { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); cursor: pointer; user-select: none; display:flex; align-items:center; gap:8px; background: transparent; }
.tab:focus-visible { outline: none; box-shadow: var(--focus); }
.tab.active { border-color: rgba(34,211,238,.5); background: linear-gradient(180deg, rgba(34,211,238,.12), rgba(34,211,238,.06)); }
/* Also style by ARIA state so JS doesn't have to manage classes for a11y */
.tab[aria-selected="true"]{ border-color: rgba(34,211,238,.5); background: linear-gradient(180deg, rgba(34,211,238,.12), rgba(34,211,238,.06)); }

.sidebar-section { display:flex; flex-direction:column; gap:10px; }
.sidebar-section.actions { gap:8px; }
.sidebar-footer { margin-top: auto; opacity: .9; }

/* Mobile sidebar behavior */
@media (max-width: 960px){
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(92vw, var(--sidebar-w)); transform: translateX(-100%); transition: transform .25s ease; z-index: 40; background: #0b1220; }
  body.sidebar-open .sidebar { transform: translateX(0); box-shadow: 20px 0 40px rgba(0,0,0,.4); }
}

/* Sticky header */
.page-header { position: sticky; top: 0; z-index: 60; display:block; backdrop-filter: saturate(1.2) blur(8px); background: linear-gradient(180deg, rgba(8,13,24,0.75), rgba(8,13,24,0.55)); border-bottom: 1px solid var(--border); }
.header-inner { display:flex; align-items:center; gap: 14px; padding: 10px clamp(12px, 3vw, 20px); }
.title-wrap { display:flex; flex-direction:column; gap: 2px; }
.header-actions { margin-left: auto; display:flex; gap:8px; align-items:center; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
.page-header .sub { margin: 0; color: var(--muted); font-size: 12px; }
@media (max-width: 520px){ .page-header .sub { display:none; } }
@media (max-width: 960px){ #openSidebar { display:inline-flex; } }
@media (min-width: 961px){ #openSidebar { display:none; } }

.page-header { display:flex; align-items:flex-start; gap: 12px; justify-content:flex-start; margin-bottom: 16px; }
.page-header .sub { color: var(--muted); margin: 0; }
@media (max-width: 960px){ #openSidebar { display:inline-flex; } }
@media (min-width: 961px){ #openSidebar { display:none; } }

/* Card & form controls */
.card { background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01)); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: 0 10px 30px rgba(0,0,0,0.25); }
.row { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 16px; }
@media (min-width: 900px){ .row.cols-2 { grid-template-columns: 1.2fr 1fr; } }
label { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin-bottom: 8px; color: var(--muted); }
textarea, input[type="password"], input[type="text"], input[type="file"] { width: 100%; resize: vertical; min-height: 120px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 12px 14px; font-size: 14px; line-height: 1.5; outline: none; transition: border-color .2s, box-shadow .2s, background .2s; }
input[type="password"], input[type="text"], input[type="file"] { min-height: auto; }
textarea::placeholder, input::placeholder { color: #7b8794; }
textarea:focus, input:focus { border-color: var(--accent-2); box-shadow: var(--focus); }
.input-row { position: relative; }
.toggle-eye { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 6px 8px; border-radius: 8px; }
.toggle-eye:focus-visible { outline: none; box-shadow: var(--focus); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
button { appearance: none; border: 1px solid var(--border); background: linear-gradient(180deg, #0e182a, #0b1220); color: var(--text); padding: 10px 14px; border-radius: 12px; cursor: pointer; font-weight: 600; font-size: 14px; letter-spacing: .2px; transition: transform .02s ease, box-shadow .2s, border-color .2s, background .2s, opacity .2s; }
button.primary { border-color: rgba(34,211,238,.5); background: linear-gradient(180deg, rgba(34,211,238,.18), rgba(34,211,238,.08)); }
button.ghost { background: transparent; }
button.danger { border-color: rgba(248,113,113,.5); background: linear-gradient(180deg, rgba(248,113,113,.18), rgba(248,113,113,.08)); }
button:hover { border-color: var(--accent); box-shadow: 0 5px 18px rgba(34,211,238,0.15); }
button.danger:hover { border-color: var(--error); box-shadow: 0 5px 18px rgba(248,113,113,0.2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .6; cursor: not-allowed; box-shadow: none; }
.badge { display:inline-flex; align-items:center; gap:6px; padding: 3px 8px; border-radius: 999px; background: rgba(34,211,238,.12); border:1px solid rgba(34,211,238,.35); color: var(--text); font-size: 12px; white-space: nowrap; }
.small { font-size: 12px; color: var(--muted); }
.status { margin-top: 8px; min-height: 18px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--error); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; }
.output { min-height: 120px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.krow { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 680px){ .krow { grid-template-columns: 1fr auto; align-items: end; } }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 16px; background: #0e1628; color: var(--text); width: min(680px, 92vw); }
dialog::backdrop { background: rgba(2,6,23,.6); }
.dlg-actions { display:flex; gap:10px; justify-content:flex-end; margin-top:12px; }

/* Scanner UI */
.scan-wrap { display:grid; grid-template-columns: 1fr; gap:12px; }
.scan-video { width:100%; max-height: 60vh; background:#000; border-radius: 12px; }
.scan-row { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }

/* Switch & check styling */
.switch { display: inline-flex; gap: 8px; align-items: center; user-select: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { width: 38px; height: 22px; background: #101826; border: 1px solid var(--border); border-radius: 999px; position: relative; transition: background .2s, border-color .2s; }
.switch-ui::after { content: ""; position: absolute; top: 50%; left: 3px; transform: translateY(-50%); width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .switch-ui { background: rgba(34,211,238,.25); border-color: rgba(34,211,238,.5); }
.switch input:checked + .switch-ui::after { transform: translate(16px, -50%); }
.switch-label { color: var(--text); font-weight: 600; }
.check { display:flex; gap:10px; align-items:center; font-weight:500; }
.check input { width: 16px; height: 16px; }

/* Drag & Drop visual */
.dragging .card { outline: 2px dashed var(--accent); outline-offset: 6px; }

/* Panels respect [hidden] for better a11y; .active kept for legacy JS */
.panel { display:block; }
.panel[hidden] { display:none !important; }
.panel.active { display:block; }

/* Print styles */
@media print {
  body { background: #fff; color: #000; }
  .noprint { display: none !important; }
  .content { padding: 0; }
  .card { border: 0; box-shadow: none; }
  textarea { border: 1px solid #999; background: #fff; color: #000; }
  .page-header { display:block; }
}

/* Accessibility & helpers */
.skip-link { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.skip-link:focus { left: 12px; top: 12px; width: auto; height: auto; padding: 8px 12px; background: #111827; color: #fff; border-radius: 8px; z-index: 1000; }

/* Subtle scrollbar polish */
* { scrollbar-width: thin; scrollbar-color: #1f2a44 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #1f2a44; border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }

/* Reduced motion: cut heavy blurs/transitions for users who prefer it */
@media (prefers-reduced-motion: reduce){
  * { transition: none !important; animation: none !important; }
  .page-header { backdrop-filter: none; }
}

/* Screen-reader only utility */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 1px, 1px); white-space: nowrap; border: 0; }

/* NoScript banner */
.noscript{ background:#7f1d1d; color:#fff; padding:10px 14px; text-align:center; }
