/* ============================================================
   RightSight Accounting & Billing System — Design System
   Color palette: deep navy sidebar, clean white content,
   teal primary, amber for money/positive, brick for dues/danger.
   Tabular numerals throughout for financial data alignment.
   ============================================================ */

:root {
  /* Brand */
  --navy:        #1a2332;
  --navy-dark:   #111927;
  --navy-mid:    #243044;
  --teal:        #0d7377;
  --teal-dark:   #095f62;
  --teal-light:  #e8f5f5;
  --amber:       #c97a1a;
  --amber-soft:  #fef6ec;
  --brick:       #c0392b;
  --brick-soft:  #fdecea;
  --green:       #1a7a4a;
  --green-soft:  #eaf5f0;

  /* Neutrals */
  --white:       #ffffff;
  --paper:       #f8f9fb;
  --border:      #e2e8f0;
  --border-soft: #edf2f7;
  --text:        #1a2332;
  --text-soft:   #4a5568;
  --muted:       #718096;
  --sidebar-text:#c8d3e0;

  /* Spacing */
  --radius:      6px;
  --radius-lg:   10px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --shadow:      0 2px 8px rgba(0,0,0,.1);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.12);

  /* Sidebar */
  --sidebar-w:   256px;
  --topbar-h:    56px;

  /* Typography */
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-num:    'SF Mono', 'Fira Code', Consolas, monospace;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--teal-dark); }
h1,h2,h3,h4 { margin: 0 0 .75rem; font-weight: 700; line-height: 1.25; color: var(--text); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .75rem; }
img { max-width: 100%; }

/* ── App Layout ────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--navy-mid) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--navy-mid); border-radius: 2px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.1rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.brand-icon {
  width: 36px; height: 36px;
  background: var(--teal);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem;
  color: #fff;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: .85rem; color: #fff; line-height: 1.2; }
.brand-sub  { font-size: .65rem; color: #8099b0; margin-top: 1px; }

.sidebar-nav { padding: .5rem 0 1.5rem; }
.nav-section {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #5a7490;
  padding: 1.1rem .9rem .3rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .48rem .9rem;
  color: var(--sidebar-text);
  font-size: .82rem;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s;
}
.nav-item:hover {
  background: rgba(255,255,255,.05);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: rgba(13,115,119,.18);
  border-left-color: var(--teal);
  color: #fff;
  font-weight: 600;
}
.nav-icon { width: 1.1rem; text-align: center; font-size: .85rem; flex-shrink: 0; }

/* ── Main Area ─────────────────────────────────────────────── */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}
.sidebar-toggle {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--text-soft); display: none;
  padding: .25rem;
}
.topbar-title { font-weight: 700; font-size: 1rem; flex: 1; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: .75rem; }
.topbar-user-info { display: flex; align-items: center; gap: .4rem; font-size: .82rem; }
.user-name { color: var(--text-soft); font-weight: 600; }
.topbar-actions { display: flex; gap: .4rem; }

/* ── Page Content ──────────────────────────────────────────── */
.page-content { padding: 1.5rem; flex: 1; }
.app-footer {
  padding: .75rem 1.5rem;
  display: flex; justify-content: space-between;
  font-size: .75rem; color: var(--muted);
  border-top: 1px solid var(--border-soft);
  background: var(--white);
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap; gap: .75rem;
}
.card-header h1,
.card-header h2,
.card-header h3 { margin: 0; }
.card-title { font-size: 1rem; font-weight: 700; color: var(--text); }

/* ── Stat Tiles ────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-tile {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.stat-tile .stat-label {
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); margin-bottom: .3rem;
}
.stat-tile .stat-value {
  font-size: 1.45rem; font-weight: 800;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat-tile .stat-sub { font-size: .75rem; color: var(--muted); margin-top: .2rem; }
.stat-tile.tile-teal .stat-value { color: var(--teal); }
.stat-tile.tile-green .stat-value { color: var(--green); }
.stat-tile.tile-amber .stat-value { color: var(--amber); }
.stat-tile.tile-danger .stat-value { color: var(--brick); }
.stat-tile.tile-navy .stat-value { color: var(--navy); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem .9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .83rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; box-shadow: var(--shadow-sm); }
.btn-primary   { background: var(--teal);  color: #fff; border-color: var(--teal); }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-secondary { background: var(--white); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--paper); }
.btn-danger    { background: var(--brick); color: #fff; border-color: var(--brick); }
.btn-danger:hover { background: #a93226; color: #fff; }
.btn-success   { background: var(--green); color: #fff; border-color: var(--green); }
.btn-warning   { background: var(--amber); color: #fff; border-color: var(--amber); }
.btn-navy      { background: var(--navy);  color: #fff; border-color: var(--navy); }
.btn-sm  { padding: .3rem .65rem; font-size: .76rem; }
.btn-lg  { padding: .65rem 1.2rem; font-size: .92rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: 1 / -1; }
label {
  font-size: .76rem; font-weight: 700;
  color: var(--text-soft); letter-spacing: .01em;
}
label .req { color: var(--brick); margin-left: 2px; }
input, select, textarea {
  font-family: var(--font); font-size: .86rem;
  padding: .52rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white); color: var(--text);
  width: 100%; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,115,119,.1);
}
input[type=number], input.money-input {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: .72rem; color: var(--muted); margin-top: .15rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }

/* Filter bar */
.filter-bar {
  display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end;
  padding: .9rem 1rem; margin-bottom: 1rem;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; flex: 1; }
.filter-bar .form-group label { font-size: .72rem; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: .83rem; background: var(--white); }
thead th {
  background: #f1f5f9;
  color: var(--text-soft);
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  padding: .6rem .85rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
thead th.num { text-align: right; }
tbody td { padding: .55rem .85rem; border-bottom: 1px solid var(--border-soft); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
tfoot td {
  padding: .65rem .85rem;
  font-weight: 800; font-size: .83rem;
  background: #f8fafc;
  border-top: 2px solid var(--border);
}
tfoot td.num { text-align: right; font-family: var(--font-num); }
.table-striped tbody tr:nth-child(even) { background: #fafbfc; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .18rem .55rem; border-radius: 999px;
  font-size: .68rem; font-weight: 700;
  white-space: nowrap;
}
.badge-success   { background: var(--green-soft);  color: var(--green);  }
.badge-danger    { background: var(--brick-soft);  color: var(--brick);  }
.badge-warning   { background: var(--amber-soft);  color: var(--amber);  }
.badge-info      { background: var(--teal-light);  color: var(--teal);   }
.badge-secondary { background: #edf2f7; color: var(--text-soft); }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: .6rem;
  padding: .75rem 1rem; border-radius: var(--radius);
  margin: 0 1.5rem .75rem; font-size: .85rem;
  border-left: 4px solid transparent;
}
.alert-success  { background: var(--green-soft);  border-color: var(--green);  color: #0f5132; }
.alert-error    { background: var(--brick-soft);  border-color: var(--brick);  color: #842029; }
.alert-info     { background: var(--teal-light);  border-color: var(--teal);   color: #0a4f53; }
.alert-warning  { background: var(--amber-soft);  border-color: var(--amber);  color: #664700; }
.alert-dismissible { position: relative; }
.alert-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: inherit; opacity: .6;
  padding: 0; line-height: 1; margin-left: auto; flex-shrink: 0;
}
.alert-close:hover { opacity: 1; }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination { display: flex; gap: .35rem; margin-top: 1rem; flex-wrap: wrap; }
.page-item {
  min-width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .8rem; color: var(--text-soft);
  text-decoration: none; padding: 0 .5rem;
}
.page-item:hover { background: var(--paper); text-decoration: none; }
.page-item.active { background: var(--teal); color: #fff; border-color: var(--teal); font-weight: 700; }

/* ── Text Utilities ─────────────────────────────────────────── */
.text-success { color: var(--green); }
.text-danger  { color: var(--brick); }
.text-warning { color: var(--amber); }
.text-muted   { color: var(--muted); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-bold      { font-weight: 700; }
.fw-800       { font-weight: 800; }
.text-sm      { font-size: .78rem; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.no-print { /* keep visible in browser */ }

/* ── Section heading within a card ─────────────────────────── */
.section-title {
  font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: .75rem 0 .4rem;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: .75rem;
}

/* ── Empty state ────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { margin: 0; }

/* ── Auth pages ─────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--navy-dark) 0%, var(--navy) 50%, #1e3a5f 100%);
  padding: 1rem;
}
.auth-card {
  background: var(--white); border-radius: var(--radius-lg);
  padding: 2.5rem 2rem; width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo .brand-icon {
  width: 48px; height: 48px; font-size: 1.1rem; margin: 0 auto .75rem;
}
.auth-logo h1 { font-size: 1.3rem; color: var(--text); }
.auth-logo p  { font-size: .82rem; color: var(--muted); margin: 0; }

/* ── Error page ─────────────────────────────────────────────── */
.error-page {
  background: var(--paper); display: flex;
  align-items: center; justify-content: center;
  min-height: 100vh;
}
.error-box {
  text-align: center; max-width: 400px; padding: 2rem;
}
.error-code { font-size: 6rem; font-weight: 900; color: var(--teal); line-height: 1; }

/* ── Print ──────────────────────────────────────────────────── */
.print-only { display: none; }
@media print {
  .sidebar, .topbar, .filter-bar, .btn, .form-actions,
  .pagination, .alert, .app-footer, .no-print, td.actions, th.actions-col { display: none !important; }
  .main-area { display: block; }
  .page-content { padding: 0; }
  .card { box-shadow: none; border: none; page-break-inside: avoid; }
  .print-only { display: block !important; }
  body { font-size: 11px; }
  table { font-size: 10px; }
  thead th { background: #eee !important; -webkit-print-color-adjust: exact; }
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: calc(-1 * var(--sidebar-w));
    top: 0; bottom: 0; z-index: 100;
    transition: left .2s ease;
    box-shadow: none;
  }
  .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
  .sidebar-toggle { display: block; }
  .page-content { padding: 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.span-2 { grid-column: 1; }
  .form-group.span-3 { grid-column: 1; }
  .topbar { padding: 0 1rem; }
  .topbar-user-info .user-role { display: none; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar-user-info { display: none; }
}
