:root {
  --brand: #f26b1d;
  --brand-dark: #d4560c;
  --brand-soft: #fff4ec;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f7f7f8;
  --card: #fff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", sans-serif;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: #16181d; color: #d1d5db; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.15rem; padding: 4px 10px 18px; }
.logo:hover { text-decoration: none; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 800; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #d1d5db; font-weight: 500;
}
.nav a:hover { background: #23262d; text-decoration: none; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #2b2f37; padding-top: 12px; font-size: .85rem; }
.sidebar-foot .who { color: #fff; font-weight: 600; padding: 0 10px; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .email { color: #9ca3af; padding: 0 10px 8px; overflow: hidden; text-overflow: ellipsis; }
.linklike { background: none; border: 0; color: #9ca3af; cursor: pointer; padding: 6px 10px; font: inherit; }
.linklike:hover { color: #fff; }

main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ---------- Components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: 2fr 1fr; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .82rem; font-weight: 500; }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.alert .value { color: var(--bad); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafafa; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfcfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 10px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; text-transform: capitalize; }
.badge.draft, .badge.on_hold, .badge.void { background: #f3f4f6; color: #4b5563; }
.badge.sent, .badge.active { background: var(--info-soft); color: var(--info); }
.badge.paid, .badge.completed { background: var(--ok-soft); color: var(--ok); }
.badge.overdue { background: var(--bad-soft); color: var(--bad); }
.badge.billed { background: var(--ok-soft); color: var(--ok); }
.badge.unbilled { background: var(--warn-soft); color: var(--warn); }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; font-size: .9rem; }
.tabs a.active { background: var(--ink); color: #fff; }
.tabs a:hover { text-decoration: none; background: #eceef1; }
.tabs a.active:hover { background: var(--ink); }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; border: 1px solid; }
.flash.success { background: var(--ok-soft); color: #14532d; border-color: #bbf7d0; }
.flash.error { background: var(--bad-soft); color: #7f1d1d; border-color: #fecaca; }

/* ---------- Forms ---------- */
.form { max-width: 760px; }
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(242, 107, 29, .35); border-color: var(--brand); }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.inline-form { display: grid; grid-template-columns: 2fr 1fr .8fr 2fr auto auto; gap: 10px; align-items: end; }
.inline-form .field { margin: 0; }

/* Invoice line items */
.items { width: 100%; }
.items th { background: none; padding: 6px 6px; }
.items td { padding: 6px; border: 0; }
.items td:first-child { width: 55%; }
.items .amount { text-align: right; font-variant-numeric: tabular-nums; padding-top: 14px; white-space: nowrap; }
.totals { margin-left: auto; width: 300px; margin-top: 10px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 9px; font-weight: 700; font-size: 1.1rem; }
.callout { background: var(--brand-soft); border: 1px solid #fed7aa; border-radius: 8px; padding: 12px 14px; margin: 12px 0; }

/* Invoice document (show + public) */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 44px; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 34px; }
.doc-title { color: var(--brand); font-size: 1.9rem; font-weight: 800; letter-spacing: .02em; }
.doc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 28px; }
.doc-meta dl { display: grid; grid-template-columns: auto auto; gap: 4px 18px; margin: 0; justify-content: end; }
.doc-meta dt { color: var(--muted); }
.doc-meta dd { margin: 0; font-weight: 600; text-align: right; }
.share { display: flex; gap: 8px; }
.share input { font-size: .85rem; background: #fafafa; }

/* Checklist */
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; align-items: center; padding: 7px 0; }
.checklist .tick { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #d1d5db; display: grid; place-items: center; font-size: .7rem; flex: none; }
.checklist .done .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist .done a { color: var(--muted); text-decoration: line-through; }

.meter { height: 6px; background: #eceef1; border-radius: 999px; overflow: hidden; margin-top: 8px; }
.meter span { display: block; height: 100%; background: var(--brand); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 0%, #fff1e6, var(--bg) 55%); }
.auth .card { width: 100%; max-width: 410px; padding: 30px; }
.auth .logo { color: var(--ink); justify-content: center; padding-bottom: 8px; }
.auth h1 { text-align: center; font-size: 1.3rem; margin-bottom: 4px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.auth .switch { text-align: center; margin-top: 16px; color: var(--muted); }

.public { max-width: 860px; margin: 0 auto; padding: 32px 18px 60px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: column; align-items: stretch; padding: 8px 10px 6px; gap: 6px; }
  .logo { padding: 2px 4px; font-size: 1.05rem; }
  .logo-mark { width: 26px; height: 26px; }
  .nav { display: flex; flex-wrap: nowrap; gap: 4px; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 6px 11px; font-size: .86rem; flex: none; }
  .nav .ico { display: none; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .inline-form .field:first-of-type, .inline-form .field:nth-last-of-type(1) { grid-column: 1 / -1; }
  .stat .value { font-size: 1.2rem; }
  .stats { gap: 10px; }
  .page-head h1 { font-size: 1.3rem; }
  th, td { padding: 9px 10px; }
  .card-head { padding: 14px 14px; }
  .legal-body { padding: 22px 18px; }
  .items td:first-child { min-width: 160px; }
  .items { min-width: 560px; }
  form#invoice-form .items-wrap { overflow-x: auto; }
  .sidebar-foot { display: none; }
  main { padding: 18px 14px 40px; }
  .row, .row-3, .doc-meta { grid-template-columns: 1fr; }
  .doc { padding: 22px; }
  .doc-head { flex-direction: column; }
  .table-wrap { overflow-x: auto; }
  .totals { width: 100%; }
}
@media print {
  .sidebar, .page-head .actions, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  .doc { border: 0; box-shadow: none; padding: 0; }
  body { background: #fff; }
}

/* ---------- Legal pages ---------- */
.legal { max-width: 820px; margin: 0 auto; padding: 24px 18px 60px; }
.legal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.legal-head .logo { color: var(--ink); padding: 0; }
.legal-head nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: .9rem; }
.legal-body { padding: 32px 36px; }
.legal-body h1 { margin-bottom: 4px; }
.legal-body h2 { margin-top: 24px; }
.legal-body li { margin-bottom: 6px; }
.legal-foot { text-align: center; margin-top: 14px; font-size: .85rem; color: var(--muted); }
.legal-foot a { margin: 0 6px; color: var(--muted); }
.danger-zone { border-color: #fecaca; }
.danger-zone h2 { color: var(--bad); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
