/* ============================================================
   CRESTIFY — Main Stylesheet
   ============================================================ */

:root {
  --clr-primary:     #4f46e5;
  --clr-primary-d:   #4338ca;
  --clr-sidebar-bg:  #1e1b4b;
  --clr-sidebar-txt: #94a3b8;
  --clr-sidebar-act: #4f46e5;
  --clr-bg:          #f1f5f9;
  --clr-card:        #ffffff;
  --clr-border:      #e2e8f0;
  --clr-text:        #1e293b;
  --clr-muted:       #64748b;
  --clr-green:       #16a34a;
  --clr-red:         #dc2626;
  --clr-orange:      #d97706;
  --clr-blue:        #2563eb;
  --sidebar-w:       250px;
  --topbar-h:        56px;
  --radius:          10px;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

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

body { margin: 0; background: var(--clr-bg); color: var(--clr-text); }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}

.auth-wrap { width: 100%; max-width: 440px; padding: 20px; }

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}

.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 28px; font-weight: 700; color: var(--clr-primary); margin: 8px 0 4px; }
.auth-logo p { color: var(--clr-muted); margin: 0; }
.auth-footer { text-align: center; margin-top: 24px; color: var(--clr-muted); font-size: .9rem; }
.auth-footer a { color: var(--clr-primary); font-weight: 600; }

.brand-icon {
  width: 44px; height: 44px;
  background: var(--clr-primary);
  border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px;
}
.brand-icon.large { width: 56px; height: 56px; font-size: 26px; border-radius: 14px; }

.gst-toggle-card {
  background: #f0fdf4; border: 1.5px solid #86efac;
  border-radius: var(--radius); padding: 16px;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--clr-sidebar-bg);
  display: flex; flex-direction: column;
  transition: transform .25s ease;
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  min-height: var(--topbar-h);
}

.biz-logo { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.brand-text { overflow: hidden; }
.brand-name { display: block; color: #fff; font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gst-badge { display: inline-block; font-size: 9px; font-weight: 700; letter-spacing: .5px; background: #16a34a; color: #fff; padding: 1px 6px; border-radius: 20px; }
.gst-badge.off { background: #d97706; }

.sidebar-nav { flex: 1; padding: 8px 0; }

.nav-section {
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px;
  text-transform: uppercase; color: #475569;
  padding: 12px 20px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: var(--clr-sidebar-txt);
  text-decoration: none;
  font-size: .88rem;
  border-radius: 0;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active { background: rgba(26,86,219,.25); color: #93c5fd; border-right: 3px solid var(--clr-primary); }
.nav-item i { font-size: 1rem; flex-shrink: 0; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,.07); padding: 8px 0; }

/* ============================================================
   MAIN WRAP
   ============================================================ */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin .25s ease;
}

.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }
.main-wrap.expanded { margin-left: 0; }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 900;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--clr-border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.sidebar-toggle {
  background: none; border: none; font-size: 1.4rem;
  color: var(--clr-muted); cursor: pointer; padding: 4px;
  line-height: 1;
}
.sidebar-toggle:hover { color: var(--clr-text); }

.topbar-title { font-weight: 600; font-size: 1rem; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.user-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--clr-bg); border-radius: 20px;
  padding: 4px 12px;
  font-size: .85rem; font-weight: 500;
  color: var(--clr-text);
}

/* ============================================================
   FLASH & PAGE
   ============================================================ */
.flash-wrap { padding: 12px 20px 0; }
.page-content { padding: 20px; }

.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.page-header h4 { margin: 0; font-weight: 700; font-size: 1.25rem; }

/* ============================================================
   CARDS
   ============================================================ */
.card-box {
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-box-title {
  font-weight: 700; font-size: .95rem;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--clr-border);
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
  background: #fff; border: 1px solid var(--clr-border);
  border-radius: var(--radius); padding: 16px;
  position: relative; overflow: hidden;
}

.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0;
  width: 4px; height: 100%; border-radius: var(--radius) 0 0 var(--radius);
}

.stat-card.green::before { background: var(--clr-green); }
.stat-card.red::before   { background: var(--clr-red); }
.stat-card.blue::before  { background: var(--clr-blue); }
.stat-card.orange::before{ background: var(--clr-orange); }

.stat-icon { font-size: 1.4rem; margin-bottom: 6px; }
.stat-card.green .stat-icon { color: var(--clr-green); }
.stat-card.red   .stat-icon { color: var(--clr-red); }
.stat-card.blue  .stat-icon { color: var(--clr-blue); }
.stat-card.orange.stat-icon { color: var(--clr-orange); }

.stat-label { font-size: .78rem; color: var(--clr-muted); font-weight: 500; margin-bottom: 4px; }
.stat-value { font-size: 1.25rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; }

.mini-stat {
  background: #fff; border: 1px solid var(--clr-border);
  border-radius: var(--radius); padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.mini-label { font-size: .8rem; color: var(--clr-muted); }
.mini-value { font-weight: 700; }

/* ============================================================
   RECENT ITEMS
   ============================================================ */
.recent-list { max-height: 380px; overflow-y: auto; }
.recent-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--clr-border);
  text-decoration: none; color: var(--clr-text);
}
.recent-item:hover { background: #f8fafc; }
.ri-name { font-weight: 600; font-size: .9rem; }
.ri-meta { font-size: .75rem; color: var(--clr-muted); }
.ri-right { text-align: right; }
.ri-amount { font-weight: 700; font-size: .9rem; font-family: 'JetBrains Mono', monospace; }
.ri-amount.green { color: var(--clr-green); }
.ri-amount.red   { color: var(--clr-red); }

/* ============================================================
   INVOICE TABLE
   ============================================================ */
.invoice-table { font-size: .85rem; }
.invoice-table th { background: #f8fafc; font-weight: 600; font-size: .8rem; }
.invoice-table td { vertical-align: middle; padding: 6px 8px; }
.invoice-table .form-control,
.invoice-table .form-select { font-size: .83rem; padding: 4px 8px; }

.invoice-view-table th { font-size: .82rem; padding: 8px 12px; }
.invoice-view-table td { padding: 8px 12px; }

.totals-table td { padding: 5px 10px; }

/* ============================================================
   SUMMARY BOX (Invoice form)
   ============================================================ */
.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px dashed var(--clr-border);
  font-size: .88rem;
}
.summary-row:last-of-type { border-bottom: none; }
.total-row { font-size: 1.1rem; font-weight: 700; padding-top: 10px; }

/* ============================================================
   PRODUCT SEARCH DROPDOWN
   ============================================================ */
.input-group { position: relative; }
.search-dropdown {
  display: none;
  position: absolute; top: 100%; left: 0; right: 0;
  background: #fff; border: 1px solid var(--clr-border);
  border-top: none; border-radius: 0 0 8px 8px;
  z-index: 100; max-height: 220px; overflow-y: auto;
  box-shadow: 0 8px 20px rgba(0,0,0,.1);
}
.sd-item {
  padding: 10px 14px; cursor: pointer; font-size: .88rem;
  border-bottom: 1px solid var(--clr-border);
}
.sd-item:last-child { border-bottom: none; }
.sd-item:hover { background: #f0f7ff; }

/* ============================================================
   META BOX (Invoice view)
   ============================================================ */
.meta-box {
  background: var(--clr-bg); border-radius: 8px;
  padding: 10px 14px;
}
.meta-label { display: block; font-size: .75rem; color: var(--clr-muted); font-weight: 500; }
.meta-val { font-weight: 600; }

/* ============================================================
   P&L REPORT
   ============================================================ */
.pl-row {
  display: flex; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px dashed var(--clr-border);
  font-size: 1rem;
}
.pl-row.income span:last-child { color: var(--clr-green); font-weight: 600; }
.pl-row.expense span:last-child { color: var(--clr-red); font-weight: 600; }
.pl-row.profit span:last-child { color: var(--clr-green); font-weight: 700; }
.pl-row.loss span:last-child { color: var(--clr-red); font-weight: 700; }

/* ============================================================
   REPORT CARDS
   ============================================================ */
.report-card {
  display: block; background: #fff;
  border: 1px solid var(--clr-border); border-radius: var(--radius);
  padding: 20px; text-decoration: none; color: var(--clr-text);
  transition: transform .15s, box-shadow .15s;
}
.report-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.1); color: var(--clr-text); }
.rc-icon { font-size: 2rem; margin-bottom: 10px; }
.rc-icon.green { color: var(--clr-green); }
.rc-icon.red   { color: var(--clr-red); }
.rc-icon.blue  { color: var(--clr-blue); }
.rc-icon.orange{ color: var(--clr-orange); }
.rc-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.rc-desc { font-size: .8rem; color: var(--clr-muted); }

/* ============================================================
   BANK BOX
   ============================================================ */
.bank-box {
  background: #f0f9ff; border: 1px solid #bae6fd;
  border-radius: 8px; padding: 10px 14px; font-size: .88rem;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--clr-muted);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary { background: var(--clr-primary); border-color: var(--clr-primary); }
.btn-primary:hover { background: var(--clr-primary-d); border-color: var(--clr-primary-d); }
.btn-xs { font-size: .75rem; padding: 3px 10px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 240px; }
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .page-content { padding: 12px; }
  .stat-value { font-size: 1rem; }
  .topbar { padding: 0 12px; }
}

@media (max-width: 576px) {
  .auth-card { padding: 28px 20px; }
}

/* ============================================================
   TABLE UTILITIES
   ============================================================ */
.table { --bs-table-hover-bg: #f8fafc; }
.table th { font-weight: 600; font-size: .83rem; color: var(--clr-muted); border-bottom-width: 2px; }
.table td { font-size: .88rem; vertical-align: middle; }

/* ============================================================
   FORM CONTROLS
   ============================================================ */
.form-label { font-size: .83rem; font-weight: 600; margin-bottom: 4px; color: var(--clr-text); }
.form-control:focus, .form-select:focus { border-color: var(--clr-primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
.form-check-input:checked { background-color: var(--clr-primary); border-color: var(--clr-primary); }
