:root {
  --accent: #f0b400;
  --accent-dark: #c79400;
  --accent-soft: #fdf3d7;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e3e6ea;
  --good: #1a7f4b;
  --bad: #c0392b;
  --warn: #a86f00;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 25, 35, .08), 0 4px 14px rgba(20, 25, 35, .05);
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* ---------- header ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  background: var(--accent);
  color: #111;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: .5px;
  font-size: 14px;
  flex: none;
}

.app-title { line-height: 1.15; }
.app-title b { font-size: 1.05rem; }
.app-title small { display: block; color: #cdd3dc; font-size: .72rem; }

nav.tabs { margin-left: auto; display: flex; gap: 6px; }
nav.tabs a {
  color: #cdd3dc;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: .95rem;
  text-decoration: none;
}
nav.tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.tabs a.active { background: var(--accent); color: #111; font-weight: 700; }

/* ---------- layout ---------- */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 20px 80px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2 { margin: 0 0 12px; font-size: 1.15rem; }
.card h3 { margin: 18px 0 8px; font-size: .95rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.grow { flex: 1; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- forms ---------- */
label.field { display: block; font-size: .8rem; color: var(--ink-soft); margin-bottom: 10px; }
label.field > span { display: block; margin-bottom: 4px; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 7px; font-size: .9rem; margin-bottom: 10px; cursor: pointer; }

input, select, textarea {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type="checkbox"] { width: auto; }
input:disabled, textarea:disabled { background: var(--bg); color: var(--ink-soft); }
textarea { resize: vertical; }

button {
  font: inherit;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  background: #e8eaee;
  color: var(--ink);
  font-weight: 600;
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--accent); color: #111; }
button.primary:hover { background: var(--accent-dark); }
button.danger { background: #fbeae8; color: var(--bad); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
button.icon { padding: 6px 10px; }

/* ---------- tables ---------- */
table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover { background: var(--accent-soft); }
table.grid input { padding: 5px 8px; }
table.grid.compact th, table.grid.compact td { padding: 6px 7px; }
table.grid.compact { font-size: .87rem; }
table.grid a { color: inherit; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge.open { background: #e2f4ea; color: var(--good); }
.badge.partial { background: var(--accent-soft); color: var(--warn); }
.badge.closed { background: #f0f1f4; color: var(--ink-soft); }
.badge.cancelled { background: #fbeae8; color: var(--bad); text-decoration: line-through; }
.badge.type { background: #e7edfb; color: #2b4ea2; }
.badge.nonret { background: #f3e9fb; color: #7a3ba2; }

/* ---------- misc ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: #fff;
  padding: 11px 22px;
  border-radius: 24px;
  font-size: .9rem;
  opacity: 0;
  transition: all .25s;
  z-index: 100;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--bad); }

.empty { text-align: center; color: var(--ink-soft); padding: 40px 0; }
.spinner { text-align: center; color: var(--ink-soft); padding: 40px 0; }

/* ---------- challan sheet (screen preview + print) ---------- */
/* A4 landscape like the paper book. Same letterhead structure as the
   invoices (logo, centred title, joined bordered boxes) but strictly
   black & white — the office printers are all greyscale. */
.sheet-preview {
  max-width: 1080px;
  margin: 0 auto 18px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.dc-sheet {
  position: relative;
  background: #fff;
  color: #111;
  border: 1.5px solid #111;
  padding: 20px 22px;
  font-size: 12.5px;
  line-height: 1.35;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-width: 900px;
}

.dc-sheet .watermark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 90px;
  font-weight: 800;
  color: rgba(0, 0, 0, .13);
  transform: rotate(-18deg);
  pointer-events: none;
  z-index: 1;
}

.sheet-head {
  display: flex;
  gap: 14px;
  align-items: center;
  border-bottom: 1.5px solid #111;
  padding-bottom: 10px;
}
/* the scanned company logo, used as-is (texture + typography matter) */
img.sheet-logo {
  width: 62px;
  height: 62px;
  object-fit: contain;
  flex: none;
  filter: grayscale(1);
}
.sheet-title { flex: 1; text-align: center; }
.sheet-title .doc-type { font-weight: 700; font-size: 14px; letter-spacing: .5px; }
.sheet-title .co-name { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.sheet-title .co-addr { font-size: 11.5px; }
.copies { font-size: 8.5px; border: 1px solid #111; }
.copies div { padding: 2px 6px; border-bottom: 1px solid #111; text-align: center; }
.copies div:last-child { border-bottom: none; }

.sheet-meta { display: flex; border: 1px solid #111; border-top: none; }
.sheet-meta .meta-left { width: 32%; padding: 8px 10px; border-right: 1px solid #111; }
.sheet-meta .meta-right { flex: 1; padding: 8px 10px; }
.meta-left div { display: flex; gap: 6px; margin-bottom: 2px; }
.meta-left span { width: 90px; color: #444; font-size: 11px; text-transform: uppercase; flex: none; }
.meta-right span { color: #444; font-size: 11px; text-transform: uppercase; }
.dc-no { font-size: 15px; }
.buyer-label { font-weight: 700; font-size: 11px; text-transform: uppercase; text-decoration: underline; margin-bottom: 2px; }
.buyer-name { font-weight: 700; }
.buyer-addr { margin-bottom: 3px; white-space: pre-line; }

.sheet-purpose {
  border: 1px solid #111;
  border-top: none;
  padding: 5px 10px;
  font-style: italic;
}

table.sheet-items {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #111;
  border-top: none;
}
.sheet-items th, .sheet-items td {
  border-left: 1px solid #111;
  padding: 3px 6px;
  vertical-align: top;
}
.sheet-items th:first-child, .sheet-items td:first-child { border-left: none; }
.sheet-items thead th { border-bottom: 1px solid #111; font-size: 10.5px; text-transform: uppercase; text-align: center; }
.sheet-items thead tr.sub th { border-bottom: 1.5px solid #111; font-size: 9.5px; padding: 1px 6px; }
.sheet-items thead tr.sub th:first-child { border-left: 1.5px solid #111; }
.sheet-items .sl { width: 4%; }
.sheet-items .desc { width: 24%; }
.sheet-items td { border-bottom: 1px solid #ccc; }
.sheet-items td.c { text-align: center; }
/* double rule setting the RECEIVED group apart, like the paper book */
.sheet-items th.recv, .sheet-items td.recv { border-left: 1.5px solid #111; }
.sheet-items tr.blank td { height: 24px; }

.sheet-sign {
  display: flex;
  border: 1px solid #111;
  border-top: 1.5px solid #111;
}
.sheet-sign .sign-cell { flex: 1; padding: 8px 12px; }
.sheet-sign .sign-cell.right { text-align: right; border-left: 1px solid #111; }
.sheet-sign .sig-space { height: 46px; }

/* print area is only visible when printing */
#print-area { display: none; }

@media print {
  @page { size: A4 landscape; margin: 9mm; }
  body { background: #fff; }
  .app-header, main, .toast { display: none !important; }
  #print-area { display: block; }
  #print-area .dc-sheet { min-width: 0; }
  .dc-sheet .watermark { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-logo { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
