/* Customer portal. Read on a phone, from a WhatsApp link, in a shop doorway -
   so: large figures, high contrast, one column on a small screen. */

:root {
  --ink: #0e1116;
  --ink-soft: #5b6672;
  --line: #e3e7ec;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --primary: #1b4dff;
  --danger: #d92d20;
  --success: #12b76a;
  --warn: #f79009;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute is honoured by the browser's own stylesheet as
   `display: none`, but ANY author `display` rule beats a UA one - so
   `.overlay { display: grid }` silently re-showed a hidden overlay on top of
   the page. Author-level and !important, so `hidden` means hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* --- gate ---------------------------------------------------------------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 32px;
  max-width: 460px;
  text-align: center;
}

.gate-card h1 { font-size: 20px; margin-bottom: 10px; }
.gate-card p { color: var(--ink-soft); margin: 0; }

/* --- masthead ------------------------------------------------------------ */

.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.masthead-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 20px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.supplier { font-size: 18px; font-weight: 600; }
.supplier-meta { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.customer { text-align: right; }
.customer-label { color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.customer-name { font-size: 17px; font-weight: 600; }

main { max-width: 1000px; margin: 0 auto; padding: 20px; }

/* --- cards --------------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.card-due { border-color: #c9d4ff; background: #f5f7ff; }
.card-label { color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 30px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card-value.is-clear { color: var(--success); }
.card-note { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
#overdue { color: var(--danger); }

/* --- panels -------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.panel h2 { font-size: 14px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; }

.ageing { display: flex; gap: 10px; flex-wrap: wrap; }

.ageing-bucket {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  min-width: 120px;
}

.ageing-label { color: var(--ink-soft); font-size: 12px; }
.ageing-value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- tabs ---------------------------------------------------------------- */

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }

.tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 7px 18px;
  font: inherit;
  cursor: pointer;
}

.tab.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* --- tables -------------------------------------------------------------- */

/* Wide content scrolls inside its own box; the page itself never does. */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.is-clear { color: var(--success); }
.is-cancelled td { color: var(--ink-soft); text-decoration: line-through; }
.is-cancelled .tag-warn { text-decoration: none; }

.tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: #eef1f5;
  color: var(--ink-soft);
  text-decoration: none;
}

.tag-warn { background: #fef0c7; color: #93370d; }
.hsn { display: block; color: var(--ink-soft); font-size: 12px; }

.empty { color: var(--ink-soft); text-align: center; padding: 24px 0; margin: 0; }
.closing { text-align: right; font-weight: 600; padding-top: 12px; font-variant-numeric: tabular-nums; }
.footnote { color: var(--ink-soft); font-size: 13px; text-align: center; padding: 8px 0 30px; }

/* --- buttons ------------------------------------------------------------- */

button { font: inherit; cursor: pointer; border-radius: 8px; }

.ghost { background: var(--surface); border: 1px solid var(--line); color: var(--ink); padding: 6px 14px; }
.ghost:hover { border-color: var(--primary); color: var(--primary); }
.small { padding: 4px 12px; font-size: 13px; }
.primary { background: var(--primary); border: 1px solid var(--primary); color: #fff; padding: 9px 20px; }

/* --- document overlay ---------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 17, 22, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  width: min(760px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}

.overlay-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.overlay-head h2 { font-size: 19px; }
.overlay-actions { margin-top: 18px; text-align: right; }

.banner { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.banner-warn { background: #fef0c7; color: #93370d; }

.doc-totals { margin-top: 16px; margin-left: auto; width: min(320px, 100%); }

.total-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-variant-numeric: tabular-nums;
}

.total-row.is-grand {
  border-top: 2px solid var(--ink);
  margin-top: 6px;
  padding-top: 9px;
  font-size: 17px;
  font-weight: 650;
}

#doc-payments h3 { font-size: 13px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 6px; }
.payment-line { font-size: 14px; padding: 3px 0; color: var(--ink-soft); }

/* --- print --------------------------------------------------------------- */

@media print {
  body { background: #fff; }
  .tabs, .overlay-actions, .footnote, .cards, #ageing-panel, .masthead { display: none; }
  .overlay { position: static; background: none; padding: 0; }
  .overlay-card { box-shadow: none; max-height: none; width: 100%; padding: 0; }
  .ghost { display: none; }
}

/* --- dark ---------------------------------------------------------------- */

/* Light is the default here, unlike the till: a customer opens this from a
   WhatsApp link in daylight, usually outside. The three states match the rest
   of the product - system, or a choice that beats it in both directions. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e8ecf1;
    --ink-soft: #98a3b1;
    --line: #262c35;
    --bg: #0e1116;
    --surface: #151a21;
    color-scheme: dark;
  }
  :root:not([data-theme="light"]) .card-due { background: #141c33; border-color: #24365f; }
  :root:not([data-theme="light"]) .tag { background: #222933; }
  :root:not([data-theme="light"]) .tag-warn { background: #4a3413; color: #fdd58c; }
  :root:not([data-theme="light"]) .banner-warn { background: #4a3413; color: #fdd58c; }
}

:root[data-theme="dark"] {
  --ink: #e8ecf1;
  --ink-soft: #98a3b1;
  --line: #262c35;
  --bg: #0e1116;
  --surface: #151a21;
  color-scheme: dark;
}
:root[data-theme="dark"] .card-due { background: #141c33; border-color: #24365f; }
:root[data-theme="dark"] .tag { background: #222933; }
:root[data-theme="dark"] .tag-warn { background: #4a3413; color: #fdd58c; }
:root[data-theme="dark"] .banner-warn { background: #4a3413; color: #fdd58c; }

/* The control itself. The portal has no button styles of its own worth
   reusing, so this is self-contained. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink-soft);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); }
.theme-toggle .icon {
  width: 17px; height: 17px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

@media (max-width: 640px) {
  .masthead-inner { flex-direction: column; }
  .customer { text-align: left; }
  .card-value { font-size: 26px; }
}

/* --- pay by UPI ----------------------------------------------------------
   White behind the code in every theme: a QR inverted for a dark background
   is not a QR any more. */

.doc-pay { display: flex; gap: 18px; align-items: flex-start; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line, #ddd); }
.doc-pay__code { flex: 0 0 auto; background: #fff; padding: 10px; border-radius: 8px; line-height: 0; }
.doc-pay__code svg { display: block; width: 156px; height: 156px; }
.doc-pay__text h3 { margin: 0 0 6px; font-size: 15px; }
.doc-pay__text p { margin: 0 0 6px; }
.doc-pay .fine { font-size: 12px; opacity: .75; max-width: 46ch; }

@media (max-width: 560px) {
  .doc-pay { flex-direction: column; }
}

.masthead-theme { align-self: flex-start; margin-left: 14px; }
@media (max-width: 640px) { .masthead-theme { margin: 8px 0 0; } }
