*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #F8F9FB;
  color: #1A1A2E;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
:root {
  --indigo:      #4F46E5;
  --indigo-dark: #3730A3;
  --indigo-soft: #EEF2FF;
  --green:       #059669;
  --green-soft:  #D1FAE5;
  --red:         #DC2626;
  --red-soft:    #FEE2E2;
  --orange:      #D97706;
  --orange-soft: #FEF3C7;
  --border:      #E5E7EB;
  --muted:       #6B7280;
  --card-bg:     #FFFFFF;
  --sidebar-w:   240px;
  --topbar-h:    52px;
}

/* ── LAYOUT ─────────────────────────────────── */
#overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 40;
}
#overlay.open { display: block; }

#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: #1E1B4B;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 50; overflow-y: auto;
}
#sidebar.open { transform: translateX(0); }

@media (min-width: 768px) {
  #sidebar { transform: translateX(0); }
  #main { margin-left: var(--sidebar-w); }
  #overlay { display: none !important; }
  #menu-btn { display: none; }
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  min-height: 72px;
  display: flex;
  align-items: center;
}
.sidebar-brand {
  font-size: 18px; font-weight: 700; color: #fff;
  letter-spacing: -0.3px;
}
.sidebar-logo { max-width: 140px; max-height: 52px; object-fit: contain; }

.nav-list { list-style: none; padding: 8px 0; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; color: rgba(255,255,255,0.7);
  text-decoration: none; font-size: 14px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: var(--indigo); color: #fff; }
.nav-icon { font-size: 16px; width: 22px; text-align: center; }

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

#topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
#menu-btn {
  background: none; border: none; font-size: 20px;
  color: var(--indigo); cursor: pointer; padding: 4px 8px;
  border-radius: 6px; line-height: 1;
}
#menu-btn:hover { background: var(--indigo-soft); }
.topbar-title { font-size: 16px; font-weight: 700; color: var(--indigo); }

#content { padding: 16px; flex: 1; max-width: 960px; }

/* ── CARDS ───────────────────────────────────── */
.card {
  background: var(--card-bg); border-radius: 12px;
  border: 1px solid var(--border); padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 15px; font-weight: 700; margin-bottom: 16px;
  color: #111; display: flex; align-items: center; gap: 8px;
}

/* ── FORMS ───────────────────────────────────── */
.form-group { margin-bottom: 12px; }
label {
  display: block; font-size: 11px; font-weight: 700;
  color: var(--muted); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.6px;
}
input[type=text], input[type=number], input[type=date],
input[type=email], input[type=tel], input[type=file],
select, textarea {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: #111;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
input[readonly] { background: #F9FAFB; color: var(--muted); }
textarea { resize: vertical; min-height: 72px; }
select { appearance: auto; }

/* ── BUTTONS ──────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 14px; font-weight: 600; text-decoration: none;
  transition: opacity 0.15s, transform 0.1s; font-family: inherit;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:hover  { opacity: 0.88; }
.btn-primary   { background: var(--indigo);      color: #fff; }
.btn-secondary { background: var(--indigo-soft); color: var(--indigo); }
.btn-danger    { background: var(--red-soft);    color: var(--red); }
.btn-success   { background: var(--green-soft);  color: var(--green); }
.btn-sm   { padding: 6px 12px; font-size: 13px; border-radius: 6px; }
.btn-block { width: 100%; }

/* ── GRID HELPERS ─────────────────────────────── */
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.col-auto { flex: 0 0 auto !important; min-width: unset !important; }

/* ── TABLES ──────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; padding: 8px 12px;
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted);
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #FAFBFF; }

/* ── BADGES ──────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 9px;
  border-radius: 20px; font-size: 12px; font-weight: 700;
}
.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-red    { background: var(--red-soft);    color: var(--red); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-indigo { background: var(--indigo-soft); color: var(--indigo); }

/* ── SUMMARY CARDS ───────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px; margin-bottom: 16px;
}
@media (min-width: 600px) { .summary-grid { grid-template-columns: repeat(4, 1fr); } }
.summary-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 12px; text-align: center;
}
.summary-card .sc-val { font-size: 20px; font-weight: 800; line-height: 1.2; }
.summary-card .sc-lbl { font-size: 11px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── ALERTS ──────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: 8px; font-size: 14px;
  margin-bottom: 12px; display: none; font-weight: 500;
}
.alert.show  { display: block; }
.alert-success { background: var(--green-soft); color: var(--green); border: 1px solid #A7F3D0; }
.alert-error   { background: var(--red-soft);   color: var(--red);   border: 1px solid #FECACA; }

/* ── LINE ITEMS (SALES) ───────────────────────── */
.line-item-row {
  display: grid;
  grid-template-columns: 2fr 70px 110px 90px 32px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
@media (max-width: 520px) {
  .line-item-row { grid-template-columns: 1fr 55px 90px 75px 28px; }
}
.row-total { font-weight: 600; text-align: right; font-size: 14px; white-space: nowrap; }

/* ── INVOICE ──────────────────────────────────── */
.invoice-print-area { max-width: 680px; }

@media print {
  #sidebar, #topbar, .no-print { display: none !important; }
  #main { margin-left: 0 !important; }
  #content { padding: 8px !important; max-width: 100% !important; }
  .card { border: none !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; }
  body { background: #fff !important; }
  .invoice-print-area { max-width: 100% !important; }
  hr { border-color: #ccc !important; }
}

/* ── MISC ────────────────────────────────────── */
code {
  font-family: 'Courier New', monospace; font-size: 12px;
  background: #F3F4F6; padding: 2px 6px; border-radius: 4px;
}
.text-muted { color: var(--muted); }
small { font-size: 12px; }
