:root {
  --navy: #101a33;
  --navy-light: #1c2b4f;
  --accent: #3b6cf6;
  --accent-dark: #2952c8;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e3e7f0;
  --text: #1a2033;
  --text-muted: #6b7590;
  --danger: #d9483a;
  --success: #1f9d55;
  --warning: #c98a1d;
  --radius: 10px;
  font-size: 15px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); }
button {
  font-family: inherit;
  cursor: pointer;
}
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

/* ---- Layout ------------------------------------------------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  background: var(--navy);
  color: #cfd6ea;
  flex-shrink: 0;
  padding: 16px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  padding: 0 20px 16px;
}
.sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: #cfd6ea;
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--navy-light); }
.sidebar nav a.active {
  background: var(--navy-light);
  border-left-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.sidebar .user-box {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.1);
  margin-top: 10px;
  font-size: 12px;
  color: #9aa4c4;
}
.sidebar .user-box button {
  margin-top: 8px;
  background: none;
  border: 1px solid rgba(255,255,255,.2);
  color: #cfd6ea;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 20px 24px 60px;
}
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
}
.topbar .brand { font-weight: 700; }
.topbar button {
  background: none;
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 6px;
  padding: 6px 10px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.page-header h1 { font-size: 20px; margin: 0; }

/* ---- Cards / tables ------------------------------------------------ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: #fafbfe; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-draft { background: #eceef4; color: #5a6480; }
.badge-sent { background: #e6edff; color: var(--accent-dark); }
.badge-paid { background: #e3f7ea; color: var(--success); }
.badge-partially_paid { background: #fdf1de; color: var(--warning); }
.badge-overdue { background: #fdeceb; color: var(--danger); }
.badge-cancelled { background: #f0f0f0; color: #999; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.btn:hover { background: #f2f4f9; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: #f3c9c4; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.field input, .field select, .field textarea {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.field textarea { resize: vertical; min-height: 60px; }

.line-items-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.line-items-table td { vertical-align: top; }
.line-items-table .lineAmt { font-weight: 600; }

.totals-box { min-width: 300px; max-width: 340px; margin-left: auto; font-size: 14px; }
.totals-box .row { display: flex; justify-content: space-between; gap: 24px; padding: 4px 0; }
.totals-box .row span:first-child { white-space: nowrap; }
.totals-box .row.grand { font-weight: 700; font-size: 16px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--navy);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card button { width: 100%; padding: 10px; }
.form-error { color: var(--danger); font-size: 13px; margin-bottom: 10px; }

.empty-state { color: var(--text-muted); text-align: center; padding: 40px 20px; font-size: 14px; }

/* ---- Mobile ---------------------------------------------------------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .sidebar.open {
    display: block;
    position: fixed;
    z-index: 100;
    width: 240px;
  }
  .topbar { display: flex; }
  .main { padding: 16px; }
  .inv-footer-grid { grid-template-columns: 1fr !important; }
  .form-grid { grid-template-columns: 1fr; }
  .totals-box { max-width: none; }
}

/* ---- Public site --------------------------------------------------- */
.public-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.public-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
}
.public-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.public-nav a {
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.public-nav a:hover { color: var(--accent); }
.public-nav .public-login-link {
  color: var(--text-muted);
  font-size: 13px;
}
.public-main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 60px;
}
.public-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
}
.footer-links a:hover { color: var(--accent); text-decoration: underline; }
.public-page h1 { font-size: 26px; margin-top: 0; }
.public-page img { max-width: 100%; border-radius: var(--radius); }

/* Blog */
.blog-list { display: flex; flex-direction: column; gap: 18px; margin-top: 20px; }
.blog-card {
  display: flex;
  gap: 16px;
  text-decoration: none;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.blog-card img { width: 140px; height: 100px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.blog-card h2 { margin: 0 0 4px; font-size: 17px; }
.blog-card p { margin: 6px 0 0; color: var(--text-muted); font-size: 14px; }
.blog-meta { color: var(--text-muted); font-size: 12px; margin: 4px 0; }
.blog-featured { width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--radius); margin: 12px 0; }
.blog-tags { margin-top: 14px; }
.blog-tags .tag {
  display: inline-block;
  background: #eceef4;
  color: var(--text-muted);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 12px;
  margin-right: 6px;
}
.comment {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.comment-form { margin-top: 10px; max-width: 480px; }
.comment-form .field { margin-bottom: 12px; }

/* Catalog */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 18px;
  margin-top: 20px;
}
.catalog-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.catalog-card img, .catalog-noimg {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  background: #eceef4;
  margin-bottom: 10px;
}
.catalog-card h3 { margin: 0 0 6px; font-size: 15px; }
.catalog-card p { margin: 0 0 8px; font-size: 13px; color: var(--text-muted); }
.catalog-price { font-weight: 700; }

/* Admin blog tabs */
.tab-btn { border-radius: 0 !important; }
.tab-btn.active { background: var(--bg); font-weight: 700; border-bottom: 2px solid var(--accent); }

/* ---- Print (invoice/quotation only) --------------------------------- */
@page { size: A4; margin: 10mm; }
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .toast { display: none !important; }
  #printArea { font-size: 12px; }
  #printArea th, #printArea td { padding: 4px 6px; }
  #printArea hr { margin: 10px 0 !important; }
  #printArea .totals-box .row { padding: 2px 0; }
  #printArea .inv-footer-grid { margin-top: 12px !important; grid-template-columns: 1fr 1fr !important; }
  #printArea .totals-box { max-width: 340px !important; }
  #printArea .inv-footer-grid div[style*="height:50px"] { height: 30px !important; }
  #printArea tr, #printArea .totals-box, #printArea .inv-footer-grid { break-inside: avoid; page-break-inside: avoid; }
  #printArea .table-wrap { overflow: visible; }
  .sidebar, .topbar, .page-header, .public-header, .public-footer, .public-nav {
    display: none !important;
  }
  .main, .app-shell, body, html, .public-main {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  #printArea, #printArea.card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  #actionCard { display: none !important; }
}

/* ---- Homepage hero & feature grid (for use inside Pages content) --- */
.hero {
  text-align: center;
  padding: 48px 20px;
  background: linear-gradient(180deg, #eef2fb 0%, transparent 100%);
  border-radius: var(--radius);
  margin-bottom: 32px;
}
.hero h1 { font-size: 32px; margin: 0 0 10px; }
.hero p { font-size: 16px; color: var(--text-muted); max-width: 560px; margin: 0 auto 22px; }
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin: 32px 0;
}
.feature-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.feature-card h3 { margin: 0 0 8px; font-size: 16px; }
.feature-card p { margin: 0; font-size: 14px; color: var(--text-muted); }
.contact-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 32px;
}

/* ---- v8: statements / stock ------------------------------------------- */
.tab-btn { margin-right: -1px; }
tfoot th { border-top: 2px solid var(--border); }
@media print {
  .no-print { display: none !important; }
  #statementArea .card { border: none !important; padding: 0 0 8px !important; }
  #statementArea .stat-grid { grid-template-columns: repeat(3, 1fr); }
}
