/* DG quotation admin — styles. Clean, practical, works on phone + desktop. */
* { box-sizing: border-box; }
:root {
  --ink: #171615; --muted: #6f6658; --line: #e2dccf; --bg: #f6f3ec; --card: #fff;
  --brand: #94703a; --green: #1f9d55; --danger: #b23b32; --radius: 8px;
}
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: "DM Sans", -apple-system, Segoe UI, Roboto, Arial, sans-serif; line-height: 1.32; }
a { color: var(--brand); }

.topbar { display: flex; align-items: center; gap: 14px; padding: 7px 14px;
  background: var(--ink); color: #f5f1e9; position: sticky; top: 0; z-index: 10; }
.topbar .brand { color: #fff; font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #cfc6b6; text-decoration: none; padding: 4px 9px; border-radius: 5px; font-weight: 600; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.topbar .logout { color: #cfc6b6; text-decoration: none; font-size: .82rem; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 12px 14px 56px; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 2px 0 10px; }
h1 { font-size: 1.32rem; margin: 0; }
h3 { margin: 12px 0 6px; }
.muted { color: var(--muted); font-size: .78rem; }
.back { display: inline-block; margin-bottom: 5px; text-decoration: none; color: var(--muted); font-size: .8rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; padding: 0 11px;
  background: var(--ink); color: #f5f1e9; border: 1px solid var(--ink); border-radius: var(--radius);
  font-size: .84rem; font-weight: 700; text-decoration: none; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn:hover { opacity: .92; }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
button.link.danger { color: var(--danger); }
.inline { display: inline; }

.filters { display: flex; gap: 8px; margin-bottom: 9px; flex-wrap: wrap; }
.filters input, .filters select { min-height: 32px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 5px; background: #fff; font: inherit; }
.filters input[type=search] { flex: 1; min-width: 200px; }

.source-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 9px; }
.source-tabs a { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 800; }
.source-tabs a.active { background: var(--ink); border-color: var(--ink); color: #f5f1e9; }
.source-tabs span { opacity: .72; font-weight: 700; }

table.list, table.items, table.prev { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { background: #efe9dd; font-size: .68rem; text-transform: uppercase; letter-spacing: .055em; color: var(--muted); }
.num { text-align: right; white-space: nowrap; }
.actions { white-space: nowrap; font-size: .78rem; }
td code { background: #efe9dd; padding: 1px 5px; border-radius: 4px; }

.badge, .sourcebadge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.s-draft { background: #e7e2d6; color: #6f6658; }
.s-sent { background: #dbe8fb; color: #245; }
.s-viewed { background: #fcefcf; color: #7a5b12; }
.s-accepted { background: #d7f0e0; color: #14663a; }
.s-declined { background: #f6dcda; color: #8a2b23; }
.s-expired { background: #eee; color: #777; }
.source-portal-import { background: #e8f1ff; color: #234d80; }
.source-admin { background: #eaf6ef; color: #14663a; }
.source-legacy { background: #f2e8dc; color: #795224; }

.metric-grid { display: grid; grid-template-columns: 150px 150px minmax(240px, 1fr); gap: 8px; margin-bottom: 10px; }
.metric { min-height: 58px; padding: 9px 11px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.metric span { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: .055em; color: var(--muted); font-weight: 800; }
.metric strong { display: block; margin-top: 4px; font-size: 1.05rem; overflow-wrap: anywhere; }
.metric.wide strong { font-size: .86rem; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.grid-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.form label { display: block; margin-bottom: 7px; font-size: .74rem; font-weight: 700; color: var(--muted); }
.form input, .form select, .form textarea { display: block; width: 100%; margin-top: 3px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; font: inherit; color: var(--ink); }
.form textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 10px; }
.grid4 { display: grid; grid-template-columns: 2fr .75fr 1fr 1fr; gap: 0 10px; align-items: end; }
.form.compact { padding: 8px 10px; }
.form.compact label { margin-bottom: 0; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.form label.check input { width: auto; margin: 0; }
.formactions { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.saved { color: var(--green); font-weight: 700; }
.hist ul { margin: 6px 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .85rem; }

/* Quote editor */
.meta { position: relative; }
.qsection { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px; margin-bottom: 9px; }
.qsection__head { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.sectitle { flex: 1; font-size: .95rem; font-weight: 700; border: 0; border-bottom: 1px dashed var(--line); padding: 2px; background: transparent; }
table.items th, table.items td { padding: 4px 5px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.items th { font-size: .66rem; text-transform: uppercase; color: var(--muted); text-align: left; }
table.items input, table.items select { width: 100%; border: 1px solid var(--line); border-radius: 5px; padding: 4px 5px; font: inherit; background: #fff; }
.iname { font-weight: 600; }
.idesc { margin-top: 2px; font-size: .76rem; color: var(--muted); }
.iqty, .iprice { text-align: right; min-width: 70px; }
.itype { min-width: 96px; }
.additem { position: relative; margin-top: 7px; display: flex; gap: 9px; align-items: center; }
.prodsearch { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }

/* Autocomplete dropdown */
.ac { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; background: #fff; border: 1px solid var(--line);
  border-radius: 0 0 8px 8px; box-shadow: 0 12px 30px rgba(0,0,0,.14); max-height: 260px; overflow: auto; }
.ac:empty { display: none; }
.acitem { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  background: #fff; padding: 6px 9px; cursor: pointer; }
.acitem:hover { background: #f3eee3; }
.acname { display: block; font-weight: 700; }
.acmeta { display: block; font-size: .78rem; color: var(--muted); }
.acprice { display: block; font-size: .82rem; color: var(--green); font-weight: 700; }

.grandbar { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 10px; padding: 9px 12px; background: var(--ink); color: #f5f1e9; border-radius: var(--radius);
  box-shadow: 0 -6px 18px rgba(0,0,0,.14); }
.grandbar strong { font-size: 1.15rem; font-family: Georgia, serif; }

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 30px; width: min(360px, 90vw); text-align: center; }
.login-card h1 { margin: 0; }
.login-card p { color: var(--muted); margin: 4px 0 18px; }
.login-card label { display: block; text-align: left; font-size: .82rem; font-weight: 700; color: var(--muted); }
.login-card input { width: 100%; margin: 6px 0 16px; padding: 10px; border: 1px solid var(--line); border-radius: 6px; }
.login-card button { width: 100%; }
.login-card .err { color: var(--danger); margin-top: 12px; }

/* Preview */
body.preview table.prev td { padding: 8px 10px; border-bottom: 1px solid var(--line); }

/* Compact invoice view */
body.invoice-print { background: #e9e3d8; }
.invoice-page { width: min(840px, calc(100vw - 24px)); min-height: 100vh; margin: 12px auto; padding: 28px 34px;
  background: #fff; color: #171615; box-shadow: 0 8px 32px rgba(0,0,0,.16); font-size: 12px; line-height: 1.28; }
.invoice-head { display: grid; grid-template-columns: 1fr 180px; gap: 24px; border-bottom: 1px solid #d8cfbf; padding-bottom: 14px; }
.invoice-head h1 { font-size: 17px; margin: 0 0 5px; letter-spacing: .01em; }
.invoice-head p, .banking p, .invoice-note p { margin: 0; color: #4f493f; }
.invoice-title { display: grid; align-content: start; justify-items: end; gap: 5px; font-size: 12px; }
.invoice-title strong { font-size: 24px; letter-spacing: .08em; color: #171615; }
.invoice-meta { display: grid; grid-template-columns: 1.5fr 1fr .8fr; gap: 12px; margin: 14px 0; padding: 10px 0;
  border-bottom: 1px solid #e5ded1; }
.invoice-lines { width: 100%; border-collapse: collapse; margin-top: 4px; }
.invoice-lines th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: #6f6658;
  border-bottom: 1px solid #d8cfbf; padding: 6px; }
.invoice-lines td { padding: 8px 6px; border-bottom: 1px solid #eee8de; vertical-align: top; }
.invoice-total { display: flex; justify-content: flex-end; align-items: baseline; gap: 28px; margin: 14px 0 12px; font-size: 13px; }
.invoice-total strong { font-size: 20px; }
.invoice-note { margin: 8px 0 12px; padding: 8px 10px; background: #f6f3ec; border: 1px solid #e5ded1; }
.banking { margin-top: 10px; padding-top: 10px; border-top: 1px solid #d8cfbf; }
.banking h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin: 0 0 6px; }
.print-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.print-actions button, .print-actions a { min-height: 30px; padding: 6px 12px; border-radius: 6px; border: 1px solid #171615;
  background: #171615; color: #fff; text-decoration: none; cursor: pointer; }
.print-actions a { background: transparent; color: #171615; }

@media (max-width: 640px) {
  .metric-grid, .grid-panels { grid-template-columns: 1fr; }
  .grid2, .grid4 { grid-template-columns: 1fr; }
  table.items, table.items thead, table.items tbody, table.items tr, table.items td { display: block; }
  table.items thead { display: none; }
  table.items tr { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 10px; }
  table.items td { border: 0; padding: 4px 0; }
  .additem { flex-direction: column; align-items: stretch; }
}

@media (max-width: 980px) and (min-width: 641px) {
  .grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body.invoice-print { background: #fff; }
  .invoice-page { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
  .print-actions { display: none; }
}

/* Row actions + reusability save button */
.rowactions { white-space: nowrap; }
.link.save { color: var(--green); font-weight: 700; }
.link.save:hover { text-decoration: underline; }

/* Toast (catalogue save feedback) */
.toast { position: fixed; left: 50%; bottom: 84px;
  transform: translate(-50%, 12px); background: var(--ink); color: #f5f1e9; padding: 11px 18px;
  border-radius: 8px; font-size: .9rem; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.24);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Reuse-past-line search */
.pastsearch { position: relative; margin-top: 6px; }
.pastsearch .prodsearch { width: 100%; }

/* Portal export */
.codebox {
  box-sizing: border-box;
  width: 100%;
  min-height: 560px;
  margin-top: 14px;
  padding: 16px;
  border: 1px solid #d6c8ac;
  border-radius: 8px;
  background: #171615;
  color: #f5f1e9;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: .82rem;
  line-height: 1.45;
  white-space: pre;
}

.warn {
  margin: 14px 0;
  padding: 14px 16px;
  border: 1px solid #c98d2a;
  border-radius: 8px;
  background: #fff8e8;
  color: #4d3510;
}

.warn ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

/* Staff auth: signed-in badge + password reset control */
.topbar .whoami { margin-left: auto; margin-right: 14px; color: #cfc6b6; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.pwreset { display: inline-block; }
.pwreset > summary { cursor: pointer; color: var(--brand); list-style: none; }
.pwreset > summary::-webkit-details-marker { display: none; }
.pwreset form { margin-top: 6px; display: flex; gap: 6px; }
.pwreset input { min-height: 32px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 5px; }

/* Data-driven invoice view: stacked totals + screen-only helpers */
.invoice-totals { margin: 12px 0; }
.invoice-totals .invoice-total { margin: 3px 0; }
.invoice-total.sub strong { font-size: 13px; }
@media print { .noprint { display: none !important; } }
