* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; transition: background 0.3s, color 0.3s; }
a { color: var(--primary); text-decoration: none; }
.container { max-width: 980px; margin: 0 auto; padding: 20px; }
.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.input { width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 16px; }
.button { background: var(--primary); color: white; border: 0; padding: 12px 16px; border-radius: 8px; cursor: pointer; font-size: 15px; min-height: 44px; }
.button:disabled { opacity: 0.6; cursor: default; }
.h1 { font-size: 22px; margin: 0 0 16px; }
nav { display: flex; gap: 12px; margin-bottom: 16px; }
.badge { display:inline-block; padding:2px 8px; background: var(--panel); border-radius:999px; font-size:12px; border:1px solid var(--border); }

/* Design system - Dark theme (default) */
:root{
  --bg: #0b1020;
  --panel: #0e1530;
  --panel-2: #121a33;
  --border: #1f2b56;
  --muted: #a7b4dc;
  --text: #e8eefc;
  --primary: #2a6bf2;
  --primary-600:#2158c7;
  --success:#2aa55a;
  --danger:#cc3344;
  --warning:#e7a23d;
  --radius: 12px;
}

/* Light theme */
[data-theme="light"]{
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --border: #d0d7de;
  --muted: #57606a;
  --text: #1f2328;
  --primary: #0969da;
  --primary-600:#0550ae;
  --success:#1a7f37;
  --danger:#cf222e;
  --warning:#d97706;
  --radius: 12px;
}

.app{ display:grid; grid-template-columns: 240px 1fr; grid-template-rows: 56px 1fr; grid-template-areas: 
  'sidebar topbar' 'sidebar content'; height:100vh; }
.topbar{ grid-area: topbar; display:flex; align-items:center; justify-content:space-between; padding:0 16px; border-bottom:1px solid var(--border); background:var(--panel); }
.topbar .brand{ font-weight:600; letter-spacing:.4px; }
.topbar .hamburger{ display:none; background:transparent; border:0; color:var(--text); font-size:24px; padding:8px; cursor:pointer; }
.sidebar{ grid-area: sidebar; border-right:1px solid var(--border); background: var(--panel); padding:12px; display:flex; flex-direction:column; gap:8px; }
.content{ grid-area: content; padding:20px; overflow:auto; }
.nav-group{ margin-top:10px; }
.nav-title{ font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.6px; padding:6px 10px; }
.nav-link{ display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:10px; color:var(--text); border:1px solid transparent; transition: background 0.2s, border-color 0.2s; }
.nav-link:hover{ background: var(--panel-2); border-color: var(--border); }
.nav-link.active{ background: var(--panel-2); border-color: var(--primary); }

.btn{ background:var(--primary); color:white; border:0; padding:12px 16px; border-radius:10px; cursor:pointer; font-size:15px; min-height:44px; transition: opacity 0.2s; white-space: nowrap; }
.btn.secondary{ background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.success{ background:var(--success); }
.btn.danger{ background:var(--danger); }
.btn:disabled{ opacity:.6; cursor:default; }

/* Button responsive adjustments */
@media (max-width: 768px) {
  .btn{ font-size: 14px; padding: 10px 12px; min-height: 40px; }
}

@media (max-width: 480px) {
  .btn{ font-size: 13px; padding: 8px 10px; min-height: 38px; white-space: normal; }
}

.table{ width:100%; border-collapse: collapse; }
.table th, .table td{ border-bottom:1px solid var(--border); padding:10px 8px; text-align:left; }
.table thead th{ position:sticky; top:0; background:var(--panel-2); z-index:1; }

/* Scan feedback animations */
@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.9; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeInScale {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.badge.success {
  background: var(--success);
  color: white;
  font-weight: 600;
  animation: fadeInScale 0.3s ease-out;
}

.badge.danger {
  background: var(--danger);
  color: white;
  font-weight: 600;
  animation: shake 0.5s ease-out;
}

.toast{ position:fixed; right:16px; bottom:16px; background:var(--panel-2); border:1px solid var(--border); padding:12px 14px; border-radius:12px; box-shadow:0 8px 24px rgba(0,0,0,.3); opacity:0; transform: translateY(8px); transition: all .2s ease; }
.toast.show{ opacity:1; transform: translateY(0); }
.mono{ font-family: ui-monospace, Menlo, Monaco, Consolas, 'Courier New', monospace; }

/* Scanner overlay */
.scanner-backdrop{ position:fixed; inset:0; background:rgba(0,0,0,.6); display:flex; align-items:center; justify-content:center; z-index:1000; }
.scanner-modal{ width: min(720px, 92vw); background:var(--panel-2); border:1px solid var(--border); border-radius:16px; overflow:hidden; box-shadow:0 16px 48px rgba(0,0,0,.5); }
.scanner-header{ display:flex; align-items:center; justify-content:space-between; padding:10px 12px; border-bottom:1px solid var(--border); }
.scanner-body{ position:relative; background:#000; }
.scanner-body video{ width:100%; height:auto; display:block; max-height: 70vh; object-fit:cover; }
.scanner-canvas{ position:absolute; top:0; left:0; width:100%; height:100%; display:none; }
.scanner-guide{ position:absolute; inset:10%; border:2px dashed rgba(255,255,255,.6); border-radius:12px; box-shadow: 0 0 0 200vmax rgba(0,0,0,.2) inset; pointer-events:none; }
.scanner-footer{ padding:10px 12px; border-top:1px solid var(--border); color:var(--muted); font-size:13px; display:flex; justify-content:space-between; align-items:center; }
.engine-badge{ font-size:11px; padding:2px 6px; background:rgba(42,107,242,.2); border:1px solid rgba(42,107,242,.4); border-radius:4px; }

/* Utility classes */
.toolbar{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.toolbar .btn{ min-width: 0; flex-shrink: 1; }
.auth-row{ margin-bottom:14px; }
.auth-row label{ display:block; margin-bottom:6px; font-size:14px; color:var(--muted); }
.auth-actions{ display:flex; gap:10px; align-items:center; margin-top:16px; }
.error{ color:var(--danger); font-size:14px; }

/* Stats cards */
.stats-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:12px; margin-bottom:16px; }
.stat-card{ background:var(--panel); padding:16px; border-radius:10px; border:1px solid var(--border); transition: all 0.2s; }
.stat-card:hover{ border-color:var(--primary); transform:translateY(-2px); }
.stat-label{ font-size:13px; color:var(--muted); margin-bottom:6px; text-transform:uppercase; letter-spacing:0.5px; }
.stat-value{ font-size:28px; font-weight:700; color:var(--text); line-height:1; }
.stat-value.primary{ color:var(--primary); }
.stat-value.success{ color:var(--success); }
.stat-value.warning{ color:var(--warning); }

/* Improved buttons */
.btn, .button{ 
  font-weight:500; 
  transition: all 0.2s; 
  border:1px solid transparent;
  white-space:nowrap;
}
.btn:hover:not(:disabled), .button:hover:not(:disabled){ 
  transform:translateY(-1px); 
  box-shadow:0 4px 12px rgba(42,107,242,0.3); 
}
.btn.secondary:hover:not(:disabled){ box-shadow:0 4px 12px rgba(32,56,115,0.3); }
.btn.success:hover:not(:disabled){ box-shadow:0 4px 12px rgba(42,165,90,0.3); }
.btn.danger:hover:not(:disabled){ box-shadow:0 4px 12px rgba(204,51,68,0.3); }
.btn:active:not(:disabled), .button:active:not(:disabled){ transform:translateY(0); }

/* Improved inputs */
.input{ 
  transition: all 0.2s; 
  font-family: inherit;
}
.input:focus{ 
  outline:none; 
  border-color:var(--primary); 
  box-shadow:0 0 0 3px rgba(42,107,242,0.1); 
}

/* Improved cards */
.card{ 
  box-shadow:0 2px 8px rgba(0,0,0,0.1); 
  transition: all 0.2s;
}
.card:hover{ box-shadow:0 4px 16px rgba(0,0,0,0.15); }

/* Better table on mobile */
.table-responsive{ overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table{ min-width:600px; }

/* Mobile responsive */
@media (max-width: 768px) {
  .app{ grid-template-columns: 1fr; grid-template-rows: 56px 1fr; grid-template-areas: 'topbar' 'content'; }
  .topbar .hamburger{ display:block; }
  .topbar .badge{ display:none; } /* Hide username on mobile */
  .sidebar{ 
    position:fixed; 
    left:0; 
    top:56px; 
    bottom:0; 
    width:280px; 
    transform:translateX(-100%); 
    transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1); 
    z-index:100; 
    border-right:1px solid var(--border);
    box-shadow: 4px 0 12px rgba(0,0,0,0.3);
  }
  .sidebar.open{ transform:translateX(0); }
  .sidebar-backdrop{ 
    display:none; 
    position:fixed; 
    inset:0; 
    background:rgba(0,0,0,.6); 
    z-index:99; 
    backdrop-filter:blur(2px);
  }
  .sidebar-backdrop.show{ display:block; }
  .content{ padding:12px; }
  .card{ padding:14px; }
  .toolbar{ gap:6px; }
  .table{ font-size:14px; min-width:500px; }
  .table th, .table td{ padding:8px 6px; }
  .toast{ right:8px; bottom:8px; left:8px; max-width:none; }
  .h1{ font-size:20px; margin-bottom:12px; }
  .stats-grid{ grid-template-columns:repeat(auto-fit, minmax(140px, 1fr)); gap:8px; }
  .stat-card{ padding:12px; }
  .stat-value{ font-size:24px; }
  .btn, .button{ padding:10px 14px; min-height:40px; font-size:14px; }
}

@media (max-width: 480px) {
  .topbar{ padding:0 10px; }
  .topbar .brand{ font-size:15px; }
  .content{ padding:8px; }
  .card{ padding:12px; border-radius:8px; margin-bottom:8px; }
  .btn, .button, .input{ font-size:14px; padding:10px 12px; }
  .table{ font-size:12px; min-width:400px; }
  .table th, .table td{ padding:6px 4px; }
  .nav-link{ padding:8px 10px; font-size:14px; }
  .h1{ font-size:18px; }
  .stats-grid{ grid-template-columns:1fr 1fr; gap:6px; }
  .stat-card{ padding:10px; }
  .stat-label{ font-size:11px; }
  .stat-value{ font-size:20px; }
  .toolbar{ gap:6px; }
  .toolbar .btn{ flex:1; min-width:0; padding:8px 6px; font-size:12px; white-space: normal; text-align: center; line-height: 1.3; }
}

/* Extra small screens - aggressive optimization */
@media (max-width: 360px) {
  .btn{ font-size: 12px; padding: 6px 8px; min-height: 36px; white-space: normal; }
  .toolbar .btn{ padding: 6px 4px; font-size: 11px; line-height: 1.2; }
  .toolbar{ gap: 4px; }
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (orientation: landscape) {
  .content{ padding:8px; }
  .card{ padding:10px; }
  .h1{ font-size:16px; margin-bottom:8px; }
  .stat-card{ padding:8px; }
  .stat-value{ font-size:18px; }
}

/* Light theme enhancements */
[data-theme="light"] .sidebar{
  box-shadow: 1px 0 3px rgba(0,0,0,0.05);
}

[data-theme="light"] .topbar{
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

[data-theme="light"] .card{
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-color: #d0d7de;
}

[data-theme="light"] .nav-link:hover{
  background: #f3f4f6;
  border-color: #d0d7de;
}

[data-theme="light"] .nav-link.active{
  background: #ddf4ff;
  border-color: #0969da;
  color: #0550ae;
}

[data-theme="light"] .btn.primary{
  background: #0969da;
  color: white;
}

[data-theme="light"] .btn.primary:hover{
  background: #0550ae;
}

[data-theme="light"] .btn.secondary{
  background: #0969da;
  color: white;
  border: none;
}

[data-theme="light"] .btn.secondary:hover{
  background: #0550ae;
}

[data-theme="light"] .btn.success{
  background: #1a7f37;
  color: white;
}

[data-theme="light"] .btn.success:hover{
  background: #116329;
}

[data-theme="light"] .btn.danger{
  background: #cf222e;
  color: white;
}

[data-theme="light"] .btn.danger:hover{
  background: #a40e26;
}

[data-theme="light"] .badge{
  background: #0969da;
  border-color: #0550ae;
  color: white;
}

[data-theme="light"] .badge.success{
  background: #1a7f37;
  border-color: #116329;
  color: white;
}

[data-theme="light"] .badge.danger{
  background: #cf222e;
  border-color: #a40e26;
  color: white;
}

[data-theme="light"] .badge.warning{
  background: #d97706;
  border-color: #b45309;
  color: white;
}

[data-theme="light"] .table thead th{
  background: #f6f8fa;
  font-weight: 600;
  color: #24292f;
}

[data-theme="light"] .table tbody tr:hover{
  background: #f6f8fa;
}

[data-theme="light"] .input{
  border: 1px solid #d0d7de;
  background: #ffffff;
}

[data-theme="light"] .input:focus{
  outline: 2px solid #0969da;
  outline-offset: -1px;
  border-color: #0969da;
}

[data-theme="light"] .mono{
  background: #ddf4ff;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  color: #0550ae;
  font-weight: 500;
}

[data-theme="light"] .stat-card{
  background: linear-gradient(135deg, #ddf4ff 0%, #f0f8ff 100%);
  border: 1px solid #b6e3ff;
}

[data-theme="light"] .stat-value.primary{
  color: #0969da;
}

[data-theme="light"] .stat-value.success{
  color: #1a7f37;
}

[data-theme="light"] .stat-value.warning{
  color: #d97706;
}
