*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface2: #f0f2f8;
  --border: #e2e6f0;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #ede9fe;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --sidebar-w: 220px;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

body.dark {
  --bg: #0f1117;
  --surface: #1a1d2e;
  --surface2: #252840;
  --border: #2e3250;
  --text: #e8eaf6;
  --text-muted: #9099c4;
  --primary-light: #312e81;
  --danger-light: #450a0a;
  --success-light: #064e3b;
  --warning-light: #451a03;
}

body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; font-size: 14px; }

.hidden { display: none !important; }

/* LOGIN */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}
.login-card {
  background: var(--surface); border-radius: 16px; padding: 40px;
  width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--primary); }
.login-logo p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.input {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; background: var(--bg); color: var(--text);
  transition: border-color 0.2s;
}
.input:focus { outline: none; border-color: var(--primary); }
.btn-primary {
  width: 100%; padding: 12px; background: var(--primary); color: white;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background 0.2s; margin-top: 8px;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; margin-top: 10px; min-height: 18px; }

/* APP LAYOUT */
#app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1.5px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-header { padding: 20px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 15px; font-weight: 700; color: var(--primary); }
.sidebar-header p { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  cursor: pointer; color: var(--text-muted); font-size: 13px; font-weight: 500;
  border-left: 3px solid transparent; transition: all 0.15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 16px; }
.sidebar-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }
.btn-logout {
  width: 100%; padding: 9px; background: var(--danger-light); color: var(--danger);
  border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}

/* MAIN */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  background: var(--surface); border-bottom: 1.5px solid var(--border);
  padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.topbar h1 { font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.theme-btn {
  background: var(--surface2); border: 1.5px solid var(--border); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 16px;
}
.save-indicator { font-size: 12px; color: var(--primary); font-weight: 600; }
.content { flex: 1; overflow-y: auto; padding: 24px; }
#app-loading { text-align: center; padding: 60px; color: var(--text-muted); font-size: 15px; }

/* SECTIONS */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h2 { font-size: 16px; font-weight: 700; }

/* STATS GRID */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  border: 1.5px solid var(--border); box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; margin-bottom: 8px; }
.stat-card .value { font-size: 22px; font-weight: 800; color: var(--text); }
.stat-card .value.green { color: var(--success); }
.stat-card .value.red { color: var(--danger); }
.stat-card .value.purple { color: var(--primary); }

.section-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 900px) { .section-row { grid-template-columns: 1fr; } }

.card { background: var(--surface); border-radius: var(--radius); padding: 18px; border: 1.5px solid var(--border); }
.card h3 { font-size: 13px; font-weight: 700; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.list-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.list-row:last-child { border-bottom: none; }
.alert-item { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 8px; }
.alert-item:last-child { margin-bottom: 0; }
.alert-warning { background: var(--warning-light); color: #92400e; }
.alert-danger { background: var(--danger-light); color: #991b1b; }

/* TABLES */
.table-wrapper { background: var(--surface); border-radius: var(--radius); border: 1.5px solid var(--border); overflow: hidden; }
.table-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1.5px solid var(--border); gap: 12px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 11px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 700; border-bottom: 1.5px solid var(--border); background: var(--surface2); }
td { padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.empty-cell { text-align: center; color: var(--text-muted); padding: 30px !important; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; }

/* BADGES */
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.badge-green { background: var(--success-light); color: #065f46; }
.badge-red { background: var(--danger-light); color: #991b1b; }
.badge-yellow { background: var(--warning-light); color: #92400e; }

.muted { color: var(--text-muted); font-size: 11px; }

/* BUTTONS */
.btn {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; background: var(--primary); color: white; transition: background 0.2s;
}
.btn:hover { background: var(--primary-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-icon { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; border: 1.5px solid var(--border); background: var(--surface2); color: var(--text); transition: all 0.15s; }
.btn-icon:hover { background: var(--primary); color: white; border-color: var(--primary); }
.btn-icon.btn-danger { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.btn-icon.btn-danger:hover { background: var(--danger); color: white; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 28px;
  width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 16px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-cancel { background: var(--surface2); color: var(--text); }

/* SETTINGS */
.price-row { display: grid; grid-template-columns: 2fr 1fr 1fr 2fr auto auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.add-price-row { display: grid; grid-template-columns: 2fr 1fr 1fr 2fr auto; gap: 10px; align-items: center; margin-bottom: 20px; }
.price-display { font-size: 13px; color: var(--primary); font-weight: 600; margin-top: 6px; }

/* FILTER ROW */
.filter-row { display: flex; gap: 10px; align-items: center; }
select.input { width: auto; }
.search-input { flex: 1; max-width: 260px; }

.empty-state { color: var(--text-muted); font-size: 13px; text-align: center; padding: 16px 0; }


.menu-toggle {
  display: none;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
}

@media (max-width: 768px) {
  .menu-toggle { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: 240px;
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open { display: block; }

  #app { display: block; }

  .main { height: 100vh; display: flex; flex-direction: column; }

  .topbar { padding: 0 14px; gap: 10px; }

  .content { padding: 14px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  .stat-card { padding: 12px; }
  .stat-card .value { font-size: 17px; }

  .section-row { grid-template-columns: 1fr; }

  .section-header { flex-wrap: wrap; gap: 10px; }

  .filter-row { flex-wrap: wrap; }

  .search-input { max-width: 100%; }

  .table-wrapper { overflow-x: auto; }

  table { min-width: 480px; font-size: 12px; }
  th { padding: 8px 10px; font-size: 10px; }
  td { padding: 8px 10px; font-size: 12px; }
  .btn-icon { padding: 4px 8px; font-size: 11px; }

  .modal { padding: 20px; }

  .price-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .price-row input { min-width: 0; }

  .add-price-row { grid-template-columns: 1fr 1fr; gap: 8px; }

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

.sidebar-close-btn {
  display: none;
  width: calc(100% - 32px);
  margin: 10px 16px 4px;
  padding: 8px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
}

@media (max-width: 768px) {
  .sidebar-close-btn { display: block; }
}