/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --sidebar-w:    240px;
  --sidebar-bg:   #0f172a;
  --accent:       #991b1b;
  --accent-hover: #7f1d1d;
  --body-bg:      #f1f5f9;
  --card-bg:      #ffffff;
  --text-main:    #1e293b;
  --text-muted:   #64748b;
  --border:       #e2e8f0;
  --danger:       #dc2626;
  --success:      #16a34a;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--body-bg);
  color: var(--text-main);
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo .brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .3px;
}
.sidebar-logo .sub {
  font-size: .75rem;
  color: #94a3b8;
  margin-top: 2px;
}

.sidebar nav {
  padding: .75rem .5rem;
  flex: 1;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .9rem;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  font-size: .875rem;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.sidebar .nav-link:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}
.sidebar .nav-link.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.sidebar .nav-link i { font-size: 1rem; flex-shrink: 0; }

.nav-section-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: #475569;
  text-transform: uppercase;
  padding: 1rem .9rem .3rem;
}

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 1rem .5rem;
}

/* ── Main content ────────────────────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .page-title { font-size: 1rem; font-weight: 600; color: var(--text-main); }
.topbar .topbar-right { display: flex; align-items: center; gap: .75rem; font-size: .825rem; color: var(--text-muted); }

.content {
  padding: 1.75rem;
  flex: 1;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-header-custom {
  padding: .75rem 1rem;
  border-radius: 10px 10px 0 0;
  font-weight: 600;
  font-size: .875rem;
  color: #fff;
}
.card-body { padding: 1.25rem; }

/* ── Stat tiles on home page ─────────────────────────────────────────────── */
.stat-tile {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow .15s, transform .15s;
}
.stat-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-2px); }
.stat-tile .tile-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-tile .tile-label { font-size: .8rem; color: var(--text-muted); }
.stat-tile .tile-name  { font-size: 1rem; font-weight: 600; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-label { font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: .3rem; }
.form-control, .form-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .45rem .75rem;
  font-size: .875rem;
  transition: border-color .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}
.form-control[readonly] { background: #f8fafc; color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { font-size: .875rem; padding: .45rem 1rem; border-radius: 6px; font-weight: 500; }
.btn-primary   { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline-secondary { border-color: var(--border); color: var(--text-muted); }
.btn-danger    { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table { font-size: .825rem; }
.table th { color: var(--text-muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--border); }
.table td { vertical-align: middle; border-color: var(--border); }
.table-hover tbody tr:hover { background: #f8fafc; }

/* ── Alerts / flash ──────────────────────────────────────────────────────── */
.alert { border-radius: 8px; font-size: .875rem; padding: .75rem 1rem; }

/* ── Login page — styled inline in auth/login.html ───────────────────────── */

/* ── Section sub-label (used inside forms) ───────────────────────────────── */
.section-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: .3rem;
}

/* ── Tab bar for section pages ───────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.tab-btn {
  padding: .4rem .85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.tab-btn:hover { background: #f1f5f9; color: var(--text-main); }
.tab-btn.active { background: var(--section-color, var(--accent)); color: #fff; border-color: transparent; }

/* ── Focus ring fix (red, not old teal) ──────────────────────────────────── */
.form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 3px rgba(153,27,27,.12);
}

/* ── Enhanced card ───────────────────────────────────────────────────────── */
.card {
  border-radius: 14px !important;
  box-shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.05) !important;
  border: none !important;
}
.card-header-custom {
  border-radius: 14px 14px 0 0 !important;
  padding: .8rem 1.1rem !important;
  display: flex;
  align-items: center;
  gap: .35rem;
}

/* ── Tab bar — pill style ─────────────────────────────────────────────────── */
.tab-bar {
  gap: .4rem;
  padding: .3rem;
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  display: inline-flex;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: .45rem 1rem;
  border-radius: 9px;
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .01em;
}
.tab-btn:hover { background: #f1f5f9; color: var(--text-main); transform: none; }
.tab-btn.active {
  background: var(--section-color, var(--accent));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

/* ── Stat strip ──────────────────────────────────────────────────────────── */
.stat-strip {
  display: flex;
  gap: .875rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.stat-card {
  flex: 1;
  min-width: 120px;
  background: var(--card-bg);
  border-radius: 12px;
  padding: .875rem 1.125rem;
  border-left: 3px solid var(--section-color, var(--accent));
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
.stat-card .stat-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .25rem;
}
.stat-card .stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
}

/* ── Calc preview panel ──────────────────────────────────────────────────── */
.calc-preview {
  background: linear-gradient(135deg, #1a0505 0%, #7f1d1d 100%);
  border-radius: 10px;
  padding: .875rem 1rem;
  color: #fff;
  margin-bottom: .875rem;
}
.calc-preview .cp-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  opacity: .65;
  margin-bottom: .1rem;
}
.calc-preview .cp-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -.3px;
}

/* ── Supplier segment ────────────────────────────────────────────────────── */
.supplier-seg {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: .875rem;
}
.supplier-seg-hdr {
  background: #1e293b;
  color: #e2e8f0;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: .45rem .875rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.supplier-seg-body { padding: .75rem .875rem .25rem; }

/* ── Icon-only delete button ─────────────────────────────────────────────── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: .875rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-icon:hover { background: #f8fafc; }
.btn-icon-danger:hover { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
}
.empty-state i { font-size: 2rem; opacity: .3; display: block; margin-bottom: .5rem; }
.empty-state p { font-size: .85rem; margin: 0; }

/* ── Table value pill ────────────────────────────────────────────────────── */
.val-pill {
  display: inline-block;
  background: #f1f5f9;
  border-radius: 5px;
  padding: .1rem .45rem;
  font-weight: 600;
  font-size: .8rem;
}

/* ── Price item row ──────────────────────────────────────────────────────── */
.price-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 0;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}
.price-item:last-child { border-bottom: none; }
.price-item .pi-label { font-weight: 600; font-size: .9rem; }
.price-item .pi-unit  { font-size: .75rem; color: var(--text-muted); }
.price-item .pi-input { width: 90px; }

/* ── Spacious table rows ─────────────────────────────────────────────────── */
.table-roomy td, .table-roomy th {
  padding-top: .75rem !important;
  padding-bottom: .75rem !important;
}
.table-roomy tbody tr:not(:last-child) td {
  border-bottom: 1px solid var(--border);
}

/* ── Scrollable record tables ────────────────────────────────────────────── */
.card-body.p-0 .table-responsive {
  max-height: 500px;
  overflow-y: auto;
}
.card-body.p-0 .table-responsive thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--card-bg);
  border-bottom: 2px solid var(--border) !important;
}

/* ── Table utilities: filter bar, monthly groups, totals row ─────────────── */
.tbl-filter-bar {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: .45rem .75rem;
  font-size: .82rem;
}
.tbl-month-hdr-cell {
  background: #f1f5f9 !important;
  color: var(--text-muted);
  padding: .3rem .75rem !important;
  font-size: .78rem;
  letter-spacing: .02em;
}
.tbl-month-hdr td { border-bottom: none !important; }
.tbl-month-sub td {
  background: #f0f9ff !important;
  border-top: 1px dashed #bae6fd !important;
  border-bottom: 1px dashed #bae6fd !important;
  padding-top: .28rem !important;
  padding-bottom: .28rem !important;
}
.tbl-sub-label {
  font-size: .73rem !important;
  color: #64748b !important;
  font-style: italic;
}
.tbl-totals-row td {
  background: #f8fafc !important;
  border-top: 2px solid var(--border) !important;
  font-size: .84rem;
  padding-top: .4rem !important;
  padding-bottom: .4rem !important;
}
/* sticky thead must sit above month-hdr rows */
.card-body.p-0 .table-responsive thead th { z-index: 3; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 991px) {
  .sidebar { display: none; }
  .main-wrapper { margin-left: 0; }
}

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .tab-bar, .btn, .btn-group,
  .table-filter-row, .form-card, .section-label + .card,
  [data-bs-toggle="modal"], .alert, .stat-strip { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .content { padding: 0.5rem !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  table { font-size: 9px !important; }
  @page { margin: 1.5cm; }
}
