/* ============================================================
   ISP Inventory v1.3.0 — app.css
   Dark theme, fully responsive
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:        #0b0f19;
  --surface:   #111827;
  --surface2:  #1e293b;
  --t4:        #334155;
  --elevated:  #1a2035;
  --card:      #141d2e;
  --border:    #1e2d45;
  --accent:    #00c2ff;
  --accent-d:  #0090c0;
  --accent-a:  rgba(0,194,255,.13);
  --green:     #10b981;
  --green-a:   rgba(16,185,129,.14);
  --yellow:    #f59e0b;
  --yellow-a:  rgba(245,158,11,.14);
  --red:       #ef4444;
  --red-a:     rgba(239,68,68,.14);
  --blue:      #3b82f6;
  --blue-a:    rgba(59,130,246,.14);
  --t1:        #e2e8f0;
  --t2:        #94a3b8;
  --t3:        #64748b;
  --sans:      'Inter', system-ui, -apple-system, sans-serif;
  --mono:      'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --sw:        256px;
  --th:        60px;
  --r:         8px;
  --rl:        12px;
  --sh:        0 4px 24px rgba(0,0,0,.4);
}

/* ── Light theme ───────────────────────────────────────────── */
html.light {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --surface2:  #f8fafc;
  --elevated:  #f1f5f9;
  --card:      #ffffff;
  --border:    #e2e8f0;
  --accent:    #0284c7;
  --accent-d:  #0369a1;
  --accent-a:  rgba(2,132,199,.12);
  --green:     #059669;
  --green-a:   rgba(5,150,105,.12);
  --yellow:    #d97706;
  --yellow-a:  rgba(217,119,6,.12);
  --red:       #dc2626;
  --red-a:     rgba(220,38,38,.12);
  --blue:      #2563eb;
  --blue-a:    rgba(37,99,235,.12);
  --t1:        #0f172a;
  --t2:        #475569;
  --t3:        #94a3b8;
  --t4:        #cbd5e1;
  --sh:        0 4px 24px rgba(0,0,0,.08);
}
html.light .sidebar { box-shadow: 2px 0 12px rgba(0,0,0,.06); }
html.light .topbar  { box-shadow: 0 1px 8px rgba(0,0,0,.06); }
html.light .card    { box-shadow: 0 1px 4px rgba(0,0,0,.06); }

/* Smooth theme transition */
body, .sidebar, .topbar, .card, .btn, input, select, textarea {
  transition: background-color .2s ease, border-color .2s ease, color .15s ease;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--t1);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
button { font-family: var(--sans); }

/* ── Shell layout ──────────────────────────────────────────── */
.main {
  margin-left: var(--sw);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s ease;
}

.sb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--t1) !important;
  text-decoration: none !important;
  flex-shrink: 0;
}
.sb-logo:hover { text-decoration: none !important; }
.sb-logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent-d), var(--accent));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.15rem; flex-shrink: 0;
}
.sb-logo-name { font-weight: 700; font-size: .9rem; line-height: 1.2; }
.sb-logo-ver  { font-size: .62rem; color: var(--t3); font-family: var(--mono); }

.sb-nav { flex: 1; padding: 10px 8px; }
.sb-sec-title {
  font-size: .62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--t3); padding: 12px 10px 4px;
}
.nav-link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px;
  border-radius: var(--r);
  color: var(--t2);
  font-size: .875rem; font-weight: 500;
  transition: all .15s;
  border-left: 3px solid transparent;
  margin-bottom: 1px;
  cursor: pointer;
  text-decoration: none !important;
}
.nav-link i { width: 17px; text-align: center; font-size: .95rem; flex-shrink: 0; }
.nav-link:hover { background: var(--accent-a); color: var(--accent); }
.nav-link.active {
  background: var(--accent-a); color: var(--accent);
  border-left-color: var(--accent); font-weight: 600;
}

.sb-footer { padding: 14px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.sb-user { display: flex; align-items: center; gap: 9px; }
.sb-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-d), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem; color: #fff; flex-shrink: 0;
}
.sb-user-name { font-size: .8rem; font-weight: 600; }
.sb-user-role { font-size: .65rem; color: var(--t3); }
.sb-actions { display: flex; gap: 4px; margin-top: 7px; flex-wrap: wrap; }
.sb-actions a {
  display: flex; align-items: center; gap: 4px;
  font-size: .75rem; color: var(--t3);
  padding: 5px 9px; border-radius: 5px; transition: all .15s;
  text-decoration: none !important;
}
.sb-actions a:hover { color: var(--accent); background: var(--accent-a); }

/* Overlay (mobile) */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 199; display: none; }
.overlay.show { display: block; }

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: var(--th);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 22px; gap: 14px;
  position: sticky; top: 0; z-index: 100;
  flex-shrink: 0;
}
.topbar-toggle {
  display: none;
  background: none; border: none;
  color: var(--t2); font-size: 1.35rem;
  cursor: pointer; padding: 4px 6px;
  border-radius: var(--r);
  transition: color .15s;
}
.topbar-toggle:hover { color: var(--accent); }
.topbar-title { font-weight: 600; font-size: 1rem; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Content area ──────────────────────────────────────────── */
.content {
  padding: 24px;
  flex: 1;
  width: 100%;
  max-width: 1400px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 1.35rem; font-weight: 700;
  font-family: var(--mono);
  display: flex; align-items: center; gap: 9px;
  line-height: 1.3;
}
.page-head-actions { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: .9rem;
}
.card-body { padding: 18px; }
.card-foot {
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,.08);
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
}
.ms-auto { margin-left: auto; }

/* ── Stat cards ─────────────────────────────────────────────── */
.g-stat {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 18px 16px;
  position: relative; overflow: hidden;
  transition: transform .18s, border-color .18s, box-shadow .18s;
}
.stat-card::before {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--sc, var(--accent));
}
.stat-card:hover {
  border-color: var(--sc, var(--accent));
  transform: translateY(-2px);
  box-shadow: var(--sh);
}
.stat-icon { font-size: 1.9rem; color: var(--sc, var(--accent)); opacity: .8; }
.stat-val {
  font-size: 1.9rem; font-weight: 800;
  font-family: var(--mono); line-height: 1;
  margin: 6px 0 3px;
}
.stat-lbl { font-size: .7rem; color: var(--t3); text-transform: uppercase; letter-spacing: .05em; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: 4px;
  font-size: .7rem; font-weight: 600;
  font-family: var(--mono); white-space: nowrap;
}
.badge-success { background: var(--green-a); color: var(--green); }
.badge-warning { background: var(--yellow-a); color: var(--yellow); }
.badge-danger  { background: var(--red-a);   color: var(--red); }
.badge-info    { background: var(--blue-a);  color: var(--blue); }
.badge-muted   { background: rgba(100,116,139,.15); color: var(--t2); }
.badge-purple  { background: rgba(167,139,250,.15); color: #a78bfa; }
.badge-blue    { background: rgba(59,130,246,.15);  color: #3b82f6; }

/* ── Tables ─────────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .875rem; }
.tbl th {
  background: var(--elevated); color: var(--t3);
  font-size: .68rem; text-transform: uppercase; letter-spacing: .07em;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
  font-weight: 600; white-space: nowrap; text-align: left;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid rgba(30,45,69,.5); vertical-align: middle; }
.tbl tbody tr:hover { background: rgba(0,194,255,.025); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl code {
  font-family: var(--mono); font-size: .77rem;
  background: var(--accent-a); color: var(--accent);
  padding: 2px 6px; border-radius: 4px;
}

/* ── Forms ──────────────────────────────────────────────────── */
.fg { margin-bottom: 14px; }
.lbl { display: block; font-size: .82rem; font-weight: 500; color: var(--t2); margin-bottom: 5px; }
.req { color: var(--red); margin-left: 2px; }

.inp, .sel {
  width: 100%;
  padding: 9px 12px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--t1);
  font-size: .875rem;
  font-family: var(--sans);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.inp:focus, .sel:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,194,255,.1);
}
.inp::placeholder { color: var(--t3); }
.sel {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 34px;
}
textarea.inp { resize: vertical; min-height: 80px; }

.hint { font-size: .73rem; color: var(--t3); margin-top: 3px; }

/* Input group */
.ig { display: flex; width: 100%; min-width: 0; }
.ig .inp { border-radius: var(--r) 0 0 var(--r); flex: 1; min-width: 0; }
.ig .btn { border-radius: 0 var(--r) var(--r) 0; flex-shrink: 0; }
.ig-addon {
  padding: 9px 12px;
  background: var(--elevated);
  border: 1px solid var(--border); border-right: none;
  color: var(--t3);
  display: flex; align-items: center;
  border-radius: var(--r) 0 0 var(--r);
  font-size: .9rem; flex-shrink: 0;
}
.ig-addon + .inp { border-radius: 0 var(--r) var(--r) 0; }

/* Grid form rows */
.frow { display: grid; gap: 14px; }
.frow.c2 { grid-template-columns: 1fr 1fr; }
.frow.c3 { grid-template-columns: 1fr 1fr 1fr; }
.frow.c4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.fcheck { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .875rem; }
.fcheck input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r);
  font-size: .875rem; font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none !important;
  line-height: 1.4;
  white-space: nowrap;
  font-family: var(--sans);
}
.btn i { font-size: .95rem; flex-shrink: 0; }
.btn-sm { padding: 5px 11px; font-size: .78rem; }
.btn-sm i { font-size: .85rem; }
.btn-icon { padding: 7px; }
.btn-icon.btn-sm { padding: 5px 7px; }

.btn-primary   { background: var(--accent-d); border-color: var(--accent-d); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 14px rgba(0,194,255,.3); }
.btn-success   { background: #059669; border-color: #059669; color: #fff; }
.btn-success:hover { background: var(--green); border-color: var(--green); }
.btn-warning   { background: #d97706; border-color: #d97706; color: #fff; }
.btn-warning:hover { background: var(--yellow); border-color: var(--yellow); }
.btn-danger    { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger:hover { background: var(--red); border-color: var(--red); }
.btn-secondary { background: var(--elevated); border-color: var(--border); color: var(--t2); }
.btn-secondary:hover { color: var(--t1); border-color: var(--t3); }
.btn-ghost     { background: transparent; border-color: transparent; color: var(--t2); }
.btn-ghost:hover { background: var(--elevated); color: var(--t1); }
.btn-outline-accent { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-outline-accent:hover { background: var(--accent-a); }
.w-full { width: 100%; }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 11px 14px;
  border-radius: var(--r);
  font-size: .875rem;
  display: flex; align-items: flex-start; gap: 9px;
  border: 1px solid transparent;
  position: relative;
  margin-bottom: 14px;
}
.alert i { flex-shrink: 0; font-size: 1.05rem; margin-top: 1px; }
.alert-success { background: var(--green-a); border-color: var(--green); color: var(--green); }
.alert-warning { background: var(--yellow-a); border-color: var(--yellow); color: var(--yellow); }
.alert-danger  { background: var(--red-a);   border-color: var(--red);   color: var(--red); }
.alert-info    { background: var(--blue-a);  border-color: var(--blue);  color: var(--blue); }
.alert-close {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; cursor: pointer;
  color: inherit; font-size: 1.1rem; opacity: .7; line-height: 1;
}
.alert-close:hover { opacity: 1; }

/* ── Login page ─────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background-image:
    radial-gradient(ellipse at 20% 60%, rgba(0,144,192,.12) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 20%, rgba(16,185,129,.07) 0%, transparent 45%);
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--rl);
  padding: 44px 38px;
  width: 100%; max-width: 420px;
  box-shadow: var(--sh);
  overflow: hidden;
}
.login-card .fg { width: 100%; }
.login-card .inp, .login-card .ig { width: 100%; box-sizing: border-box; }

/* ── Scanner ─────────────────────────────────────────────────── */
.scan-box {
  background: #000; border-radius: var(--rl);
  aspect-ratio: 4/3; max-height: 360px;
  position: relative; overflow: hidden;
}
.scan-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scan-target { width: 190px; height: 190px; position: relative; }
.scan-target::before, .scan-target::after, .sc-tr, .sc-bl {
  position: absolute; width: 34px; height: 34px;
  border-color: var(--accent); border-style: solid;
}
.scan-target::before { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 3px 0 0 0; }
.scan-target::after  { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 3px 3px 0; }
.sc-tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 3px 0 0; }
.sc-bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 3px 0; }
.scan-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanline 1.8s ease-in-out infinite;
}
@keyframes scanline { 0%,100% { top: 10%; opacity: 1; } 50% { top: 90%; opacity: .8; } }

/* ── Barcode label print ────────────────────────────────────── */
.bc-label {
  background: #fff; color: #000;
  border: 1px solid #ccc; border-radius: 6px;
  padding: 12px; width: 240px; text-align: center;
  page-break-inside: avoid;
  font-family: var(--mono); display: inline-block;
}

/* ── Pagination ─────────────────────────────────────────────── */
nav .pagination { display: flex; gap: 4px; list-style: none; flex-wrap: wrap; }
.pagination li a, .pagination li span {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--elevated); color: var(--t2);
  font-size: .78rem; cursor: pointer; transition: all .15s;
  text-decoration: none;
}
.pagination li a:hover { background: var(--accent-a); color: var(--accent); border-color: var(--accent); }
.pagination li.active a,
.pagination li.active span { background: var(--accent-d); color: #fff; border-color: var(--accent-d); }

/* ── Grid helpers ───────────────────────────────────────────── */
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
.g4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── Utility ────────────────────────────────────────────────── */
.df   { display: flex; }
.df-c { display: flex; flex-direction: column; }
.ai-c { align-items: center; }
.jb   { justify-content: space-between; }
.fw   { flex-wrap: wrap; }
.f1   { flex: 1; }

.gap4  { gap: 4px; }
.gap8  { gap: 8px; }
.gap12 { gap: 12px; }
.gap16 { gap: 16px; }

.mt4  { margin-top: 4px; }
.mt8  { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.mt24 { margin-top: 24px; }
.mb8  { margin-bottom: 8px; }
.mb16 { margin-bottom: 16px; }
.mb24 { margin-bottom: 24px; }

.p16 { padding: 16px; }
.p20 { padding: 20px; }

.t1 { color: var(--t1); }
.t2 { color: var(--t2); }
.t3 { color: var(--t3); }
.ta { color: var(--accent); }

.mono { font-family: var(--mono); }
.bold { font-weight: 700; }
.semi { font-weight: 600; }
.sm   { font-size: .82rem; }
.xs   { font-size: .71rem; }

.empty { text-align: center; padding: 50px 20px; color: var(--t3); }
.empty i { font-size: 2.8rem; display: block; margin-bottom: 10px; opacity: .35; }

.divider { height: 1px; background: var(--border); margin: 18px 0; }
.overflow-auto { overflow: auto; }

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-head-actions, .topbar-actions,
  .no-print, .btn, .overlay { display: none !important; }
  .main { margin-left: 0 !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ccc; box-shadow: none; }
  .bc-label { border-color: #000; }
}

/* ── Tablet (≤ 1024px) ──────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sw: 220px; }
  .frow.c4 { grid-template-columns: 1fr 1fr; }
  .g4 { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile (≤ 768px) ───────────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar slides in */
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--sh); }

  /* Main takes full width */
  .main { margin-left: 0; }
  .topbar-toggle { display: flex; }
  .topbar { padding: 0 14px; }

  .content { padding: 14px; }

  /* Form grids collapse */
  .frow.c2, .frow.c3, .frow.c4 { grid-template-columns: 1fr; }

  /* Two-col grids go single on mobile */
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .g-stat { grid-template-columns: 1fr 1fr; }

  /* Page head stacks */
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head h1 { font-size: 1.15rem; }
  .page-head-actions { justify-content: flex-start; }

  /* Login card */
  .login-card { padding: 28px 20px; }

  /* Smaller stat values on mobile */
  .stat-val { font-size: 1.55rem; }

  /* Table scroll hint */
  .tbl-wrap::after {
    content: '';
    display: block;
    height: 0;
  }
}

/* ── Small mobile (≤ 480px) ─────────────────────────────────── */
@media (max-width: 480px) {
  .g-stat { grid-template-columns: 1fr 1fr; }
  .topbar-actions .btn span { display: none; }
  .btn-sm { padding: 5px 9px; }
}
