/* ==========================================================================
   FBR Digital Invoicing — Design System
   Palette: deep teal (brand/sidebar), warm slate text, status accents
   (green = submitted, amber = pending, red = failed) tied to invoice
   lifecycle rather than decoration. Flat cards with hairline borders and a
   4px status/brand accent bar in place of drop shadows.
   Type: Space Grotesk for numerals & headings, Inter for UI/body text.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --color-bg: #F5F7F5;
  --color-surface: #FFFFFF;
  --color-sidebar: #0F3D3E;
  --color-sidebar-hover: #154E4E;
  --color-sidebar-active: #1B8A5A;
  --color-sidebar-text: #C9DBD6;
  --color-sidebar-text-active: #FFFFFF;

  --color-text: #1C2624;
  --color-text-muted: #63726E;
  --color-text-faint: #94A19D;
  --color-border: #E1E6E2;
  --color-border-strong: #C9D1CB;

  --color-primary: #0F3D3E;
  --color-primary-hover: #0A2C2D;
  --color-primary-soft: #E6EFED;

  --color-success: #1B8A5A;
  --color-success-soft: #E4F4EC;
  --color-warning: #C77D22;
  --color-warning-soft: #FBF0E0;
  --color-danger: #B23B3B;
  --color-danger-soft: #FBEAE9;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --sidebar-width: 248px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .font-display { font-family: var(--font-display); letter-spacing: -0.01em; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--color-success); outline-offset: 2px; }

/* ---------- App Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 22px 22px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand-mark {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: var(--color-sidebar-active);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  font-size: 15px;
}

.sidebar-brand-name { font-family: var(--font-display); font-weight: 600; font-size: 15.5px; color: #fff; }
.sidebar-brand-sub { font-size: 11px; color: var(--color-sidebar-text); opacity: 0.75; margin-top: 1px; }

.sidebar-nav { padding: 14px 12px; flex: 1; }
.sidebar-nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: rgba(201,219,214,0.55); padding: 12px 12px 6px;
}

.sidebar-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: var(--radius-md);
  color: var(--color-sidebar-text);
  font-size: 13.5px; font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar-link:hover { background: var(--color-sidebar-hover); color: #fff; }
.sidebar-link.active { background: rgba(27,138,90,0.22); color: #fff; }
.sidebar-link.active .sidebar-icon { color: var(--color-sidebar-active); }
.sidebar-icon { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 20px 18px; border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px; color: rgba(201,219,214,0.7);
}

/* ---------- Main column ---------- */
.main-col { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px; flex-shrink: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px;
  position: sticky; top: 0; z-index: 20;
}

.topbar-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  min-width: 240px;
  color: var(--color-text-muted);
}
.search-box input { border: none; background: transparent; outline: none; font-size: 13px; width: 100%; color: var(--color-text); }

.user-chip { display: flex; align-items: center; gap: 9px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-primary-soft); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 13px;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--color-text-muted); text-transform: capitalize; }

.profile-tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--color-border); margin-bottom: 20px; }
.profile-tab { flex: 0 0 auto; padding: 10px 14px; border-bottom: 2px solid transparent; color: var(--color-text-muted); font-size: 13px; font-weight: 600; text-decoration: none; }
.profile-tab.active { border-bottom-color: var(--color-primary); color: var(--color-primary); }

.content { padding: 26px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-md);
  font-size: 13.5px; font-weight: 600; border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-outline { background: var(--color-surface); border-color: var(--color-border-strong); color: var(--color-text); }
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { background: #146e48; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--color-text-muted); padding: 6px 10px; }
.btn-ghost:hover { color: var(--color-text); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }

/* Stat cards with a 4px top accent bar keyed to what they measure */
.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 22px; }
@media (max-width: 1200px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 3px solid var(--stat-accent, var(--color-primary));
  border-radius: var(--radius-md);
  padding: 16px 16px 14px;
}
.stat-card .stat-label { font-size: 11.5px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 25px; font-weight: 700; margin-top: 8px; }
.stat-card .stat-sub { font-size: 11.5px; color: var(--color-text-faint); margin-top: 3px; }

.stat-total { --stat-accent: var(--color-primary); }
.stat-today { --stat-accent: #3C7A8C; }
.stat-sales { --stat-accent: var(--color-primary); }
.stat-submitted { --stat-accent: var(--color-success); }
.stat-pending { --stat-accent: var(--color-warning); }
.stat-failed { --stat-accent: var(--color-danger); }

/* ---------- Welcome banner ---------- */
.welcome-banner {
  background: linear-gradient(135deg, #0F3D3E 0%, #12514F 100%);
  color: #fff; border-radius: var(--radius-lg);
  padding: 22px 26px; margin-bottom: 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.welcome-banner h2 { margin: 0 0 4px; font-size: 20px; }
.welcome-banner p { margin: 0; color: rgba(255,255,255,0.75); font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left; padding: 11px 16px; background: var(--color-bg);
  color: var(--color-text-muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.03em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #FAFBFA; }
.table-empty { padding: 40px 20px; text-align: center; color: var(--color-text-muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-neutral { background: var(--color-bg); color: var(--color-text-muted); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .form-grid, .form-grid.cols-2, .form-grid.cols-4 { grid-template-columns: 1fr 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--color-text); }
.field .hint { font-size: 11px; color: var(--color-text-faint); }

.input, select.input, textarea.input {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: 9px 12px; font-size: 13.5px; font-family: inherit;
  background: var(--color-surface); color: var(--color-text);
  width: 100%;
}
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
textarea.input { resize: vertical; min-height: 70px; }

.field-row-full { grid-column: 1 / -1; }

/* ---------- Modal / Lightbox ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,25,24,0.55);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--color-surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  border: 1px solid var(--color-border);
}
.modal-box.modal-wide { max-width: 900px; }
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--color-text-muted); line-height: 1; }
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Invoice builder (POS-style) ---------- */
.invoice-builder { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .invoice-builder { grid-template-columns: 1fr; } }

.item-search { position: relative; }
.item-search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); box-shadow: 0 8px 24px rgba(15,25,24,0.12);
  max-height: 280px; overflow-y: auto; z-index: 30; display: none;
}
.item-search-results.open { display: block; }
.item-search-row { padding: 10px 14px; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; gap: 10px; }
.item-search-row:last-child { border-bottom: none; }
.item-search-row:hover { background: var(--color-bg); cursor: pointer; }
.item-search-row .name { font-weight: 600; font-size: 13px; }
.item-search-row .meta { font-size: 11.5px; color: var(--color-text-muted); }

.line-items-table th, .line-items-table td { padding: 9px 10px; }
.line-items-table input.input, .line-items-table select.input { padding: 7px 8px; font-size: 12.5px; }
.remove-line { color: var(--color-danger); background: none; border: none; font-size: 16px; }

.summary-card .row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 13.5px; }
.summary-card .row.total { border-top: 1px solid var(--color-border); margin-top: 6px; padding-top: 12px; font-weight: 700; font-size: 16px; font-family: var(--font-display); }
.summary-card .row .muted { color: var(--color-text-muted); }

.customer-select-box {
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-md);
  padding: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
}

/* ---------- Generated invoice / print view ---------- */
.invoice-doc { max-width: 780px; margin: 0 auto; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 34px; }
.invoice-doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--color-border); padding-bottom: 20px; margin-bottom: 20px; }
.invoice-doc-head h2 { margin: 0 0 6px; font-size: 20px; }
.invoice-doc-meta { text-align: right; font-size: 12.5px; color: var(--color-text-muted); }
.invoice-doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
.invoice-doc-parties .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-faint); margin-bottom: 4px; }
.invoice-doc-qr { display: flex; align-items: center; gap: 18px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--color-border); }
.qr-box { width: 120px; height: 120px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; background: #fff; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-col { margin-left: 0 !important; }
  body { background: #fff; }
  .invoice-doc { border: none; padding: 0; }
}

/* ---------- Auth (login) ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--color-bg); }
.auth-card { width: 380px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 32px; }
.auth-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-card h1 { font-size: 18px; margin: 0 0 4px; }
.auth-card .sub { font-size: 12.5px; color: var(--color-text-muted); margin-bottom: 22px; }
.field-error { color: var(--color-danger); font-size: 12px; margin-top: 4px; }
.alert { padding: 11px 14px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px; }
.alert-success { background: var(--color-success-soft); color: var(--color-success); }
.alert-error { background: var(--color-danger-soft); color: var(--color-danger); }
.demo-creds { margin-top: 18px; padding: 12px 14px; background: var(--color-bg); border-radius: var(--radius-md); font-size: 12px; color: var(--color-text-muted); line-height: 1.7; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: 12.5px; }
.w-full { width: 100%; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--color-text-muted); }
.empty-state .icon { width: 40px; height: 40px; margin: 0 auto 14px; color: var(--color-text-faint); }
.pagination { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 12.5px; color: var(--color-text-muted); }
.pagination .active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
