:root {
  --bg:        #f4f5f7;
  --panel:     #ffffff;
  --ink:       #16191d;
  --ink-soft:  #5b6470;
  --line:      #dfe3e8;
  --line-soft: #eceff3;
  --accent:    #1f6feb;
  --accent-dk: #1858c4;
  --ok-bg:     #e7f6ec;  --ok-ink:  #17603a;
  --err-bg:    #fdeaea;  --err-ink: #98221f;
  --warn-bg:   #fff6e3;  --warn-ink:#7a5210;
  --side:      #14181e;
  --side-ink:  #aab4c0;
  --radius:    8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ----------------------------------------------------------------- shell */
.shell { display: flex; min-height: 100vh; }

.side {
  width: 230px; flex-shrink: 0;
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid #232a33; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 6px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.brand-name { color: #fff; font-weight: 600; font-size: 14px; line-height: 1.25; word-break: break-word; }

.side nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.side nav a {
  display: block; padding: 9px 12px; border-radius: 6px;
  color: var(--side-ink); font-size: 13.5px; margin-bottom: 2px;
}
.side nav a:hover { background: #1d232b; color: #fff; text-decoration: none; }
.side nav a.on { background: var(--accent); color: #fff; }
.nav-gap {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
  color: #5d6875; padding: 16px 12px 6px;
}

.side-foot { padding: 12px 16px; border-top: 1px solid #232a33; font-size: 12.5px; }
.side-foot .who { color: #fff; margin-bottom: 3px; }
.side-foot .signout { color: #8d99a7; }

.main { flex: 1; min-width: 0; padding: 0 26px 40px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 20px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 20px;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; }

/* ---------------------------------------------------------------- flash */
.flash {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13.5px;
  background: var(--ok-bg); color: var(--ok-ink);
}
.flash.err  { background: var(--err-bg);  color: var(--err-ink); }
.flash.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* --------------------------------------------------------------- panels */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.panel > h2 {
  font-size: 14px; margin: 0 0 14px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft);
}
.panel-flush { padding: 0; overflow: hidden; }

.hint { color: var(--ink-soft); font-size: 12.5px; margin-top: 4px; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); }

/* --------------------------------------------------------------- tables */
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--ink-soft); padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: #fafbfc; white-space: nowrap;
}
table.grid td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.muted { color: var(--ink-soft); }
.strong { font-weight: 600; }

/* ---------------------------------------------------------------- forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #37404b; }
.field .req { color: #c0392b; }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid #cbd2da; border-radius: 6px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,235,.12);
}
input[readonly], input:disabled, select:disabled { background: #f2f4f7; color: var(--ink-soft); }
textarea { resize: vertical; min-height: 80px; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1 1 200px; margin-bottom: 14px; }
.row > .field.narrow { flex: 0 1 130px; }
.row > .field.wide   { flex: 3 1 340px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.check input { width: auto; }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-block; padding: 8px 15px; border-radius: 6px; font-size: 13.5px;
  font-weight: 550; border: 1px solid #cbd2da; background: #fff; color: var(--ink);
  cursor: pointer; text-decoration: none; line-height: 1.4;
}
.btn:hover { background: #f6f8fa; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dk); }
.btn.danger { color: #b02a26; border-color: #e6bbb9; }
.btn.danger:hover { background: #fdeaea; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.btn-row.end { justify-content: flex-end; }

/* --------------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
}
.badge.ok     { background: var(--ok-bg);  color: var(--ok-ink); }
.badge.off    { background: #eceff3;       color: #6a737d; }
.badge.err    { background: var(--err-bg); color: var(--err-ink); }
.badge.info   { background: #e6f0fe;       color: #14509c; }

/* ---------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-soft); }
.stat .v { font-size: 24px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ------------------------------------------------------------ toolbar */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; }
.toolbar input[type=text], .toolbar input[type=date] { min-width: 150px; }

/* ------------------------------------------------------- invoice editor */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft);
  padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; background: #fafbfc;
}
table.lines td { padding: 5px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.lines input, table.lines select { padding: 6px 8px; font-size: 13px; }
table.lines .amt-cell { text-align: right; font-variant-numeric: tabular-nums; padding-top: 12px; font-weight: 600; }
table.lines .del-cell { width: 34px; text-align: center; }
.line-del {
  border: none; background: none; color: #b0b8c1; cursor: pointer;
  font-size: 18px; line-height: 1; padding: 6px 4px;
}
.line-del:hover { color: #c0392b; }

.w-sr   { width: 34px; }
.w-hsn  { width: 90px; }
.w-qty  { width: 90px; }
.w-unit { width: 78px; }
.w-rate { width: 100px; }
.w-amt  { width: 120px; }

.totals-box { margin-left: auto; width: 340px; }
.totals-box table { width: 100%; border-collapse: collapse; }
.totals-box td { padding: 7px 4px; border-bottom: 1px solid var(--line-soft); }
.totals-box td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.totals-box tr.grand td { font-size: 17px; font-weight: 700; border-bottom: none; padding-top: 12px; }

/* ------------------------------------------------------------ auth page */
.auth-body { display: grid; place-items: center; min-height: 100vh; background: #101418; padding: 20px; }
.auth-card { width: 100%; max-width: 460px; background: #fff; border-radius: 12px; padding: 32px 28px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card .sub { color: var(--ink-soft); font-size: 13px; margin-bottom: 22px; }
.auth-card .btn { width: 100%; text-align: center; padding: 10px; font-size: 14px; }
.auth-alt { margin-top: 18px; text-align: center; font-size: 12.5px; color: var(--ink-soft); }

/* --------------------------------------------------------------- misc */
.err-page { display: grid; place-items: center; min-height: 100vh; text-align: center; padding: 20px; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.err-page h1 { font-size: 46px; margin: 0; }
.err-page p { color: var(--ink-soft); }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-gap { width: 100%; padding: 8px 12px 2px; }
  .main { padding: 0 14px 30px; }
  .totals-box { width: 100%; }
}

/* --------------------------------------------------- admin user rows */
.user-row { padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.user-row:last-of-type { border-bottom: none; }
.user-row .field { margin-bottom: 8px; }

/* ---------------------------------------------------------- landing page */
.landing { text-align: center; }
.landing h1 { font-size: 26px; margin: 0 0 6px; }
.landing .sub { color: var(--ink-soft); font-size: 13.5px; margin: 0 auto 26px; max-width: 340px; line-height: 1.55; }

.choices { display: grid; gap: 12px; text-align: left; }
.choice {
  display: grid;
  grid-template-columns: 38px 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  padding: 18px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
}
.choice:hover { border-color: var(--accent); background: #f7faff; text-decoration: none; }
.choice-mark {
  grid-row: 1 / 3;
  width: 38px; height: 38px; border-radius: 9px;
  background: #eceff3; color: var(--ink-soft);
  display: grid; place-items: center; font-size: 18px; font-weight: 700;
}
.choice-title { font-size: 15.5px; font-weight: 650; }
.choice-note { font-size: 12.5px; color: var(--ink-soft); line-height: 1.45; }
.choice.primary { border-color: var(--accent); }
.choice.primary .choice-mark { background: var(--accent); color: #fff; }

/* ------------------------------------------------------------ UPI QR box */
.qr-preview {
  width: 150px; height: 150px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; padding: 6px;
  display: grid; place-items: center;
}
.qr-preview svg { width: 100%; height: 100%; display: block; }
.qr-preview.empty-qr {
  color: var(--ink-soft); font-size: 12px; text-align: center;
  border-style: dashed; background: #fafbfc; padding: 10px;
}
