:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2433; --muted: #6b7385; --line: #dfe3ea;
  --brand: #e8891c; --brand-dark: #c56f0d; --accent: #2b5fab; --danger: #b42318; --ok: #157347; --warn-bg: #fff4e0;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Noto Sans TC", Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[x-cloak] { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 20px; background: #fff; border-bottom: 1px solid var(--line); padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 20; }
.topbar .logo img { height: 30px; display: block; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 8px 12px; border-radius: 6px; color: var(--ink); white-space: nowrap; }
.topbar nav a.active, .topbar nav a:hover { background: #fdf0e1; color: var(--brand-dark); text-decoration: none; }
.topbar .who { color: var(--muted); font-size: 13px; white-space: nowrap; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 80px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; }
@media (max-width: 800px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=email], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f6c48a; border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 6px; font-weight: normal; color: var(--ink); font-size: 14px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 6px; font: inherit; font-weight: 600; 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(--danger); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { border: none; background: none; cursor: pointer; color: var(--muted); padding: 4px 6px; font-size: 15px; border-radius: 4px; }
.iconbtn:hover { background: #eef0f4; color: var(--ink); }

table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.list th.sortable { cursor: pointer; user-select: none; }
table.list th.sortable:hover { color: var(--ink); }
table.list th.sorted { color: var(--ink); }
table.list th.sorted { text-decoration: underline; text-underline-offset: 3px; }
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click:hover td { background: #fafbfc; cursor: pointer; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; text-transform: capitalize; }
.badge.draft { background: #eef0f4; color: #4b5563; }
.badge.issued { background: #e3edfb; color: #1f4f96; }
.badge.accepted { background: #ddf3e6; color: var(--ok); }
.badge.lost { background: #fde8e7; color: var(--danger); }

/* quotation editor lines */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 6px; border-bottom: 1px solid var(--line); }
table.lines td { padding: 5px 6px; vertical-align: top; border-bottom: 1px solid #eef0f4; }
table.lines tr.heading td { background: #fbf7f1; }
table.lines input, table.lines textarea { padding: 6px 8px; }
.hints { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.hints button { border: none; background: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.hints .k { color: var(--ink); font-weight: 600; }
.combo { position: relative; }
.dropdown { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto; }
.dropdown div { padding: 7px 10px; cursor: pointer; }
.dropdown div:hover, .dropdown div.hl { background: #fdf0e1; }
.dropdown .new { color: var(--accent); font-weight: 600; border-top: 1px solid var(--line); }

.terms-list .term { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: start; padding: 6px 0; border-bottom: 1px solid #eef0f4; }
.terms-list .no { padding-top: 8px; font-weight: 600; color: var(--muted); }
.total { font-size: 20px; font-weight: 700; }

.sticky-actions { position: sticky; bottom: 0; background: rgba(245,246,248,.95); border-top: 1px solid var(--line); padding: 12px 0; margin-top: 10px; z-index: 10; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 100; }
.toast.err { background: var(--danger); }
.warn { background: var(--warn-bg); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,24,33,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; padding: 20px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 1100px; }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.login { max-width: 360px; margin: 10vh auto; }
.login img { width: 100%; margin-bottom: 18px; }
.error { color: var(--danger); margin: 8px 0; }
@media (max-width: 700px) { .topbar .who { display: none; } main { padding: 14px 10px 80px; } }

/* jobs, visits, invoices */
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tabs button { border: none; background: #fff; padding: 7px 16px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.on { background: #fdf0e1; color: var(--brand-dark); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.warn-pill { background: var(--warn-bg); color: #8a5300; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.card .v { font-size: 18px; font-weight: 700; margin-top: 2px; }
.card.hot { border-color: #f3c27c; background: #fffaf2; }
@media (max-width: 800px) { .cards { grid-template-columns: 1fr 1fr; } }
.split { display: grid; grid-template-columns: minmax(300px, 5fr) 7fr; gap: 16px; align-items: start; }
.split .sheet { position: sticky; top: 70px; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } .split .sheet { position: static; } }
.sheet-img { width: 100%; border: 1px solid var(--line); border-radius: 6px; display: block; max-height: 75vh; object-fit: contain; background: #fafafa; }
.thumb { width: 54px; height: 70px; object-fit: cover; border: 2px solid var(--line); border-radius: 4px; cursor: pointer; }
.thumb.on { border-color: var(--brand); }
label.btn { margin: 0; color: var(--ink); font-size: 13px; }
.btn.disabled { opacity: .5; pointer-events: none; }
table.sums { width: 100%; border-collapse: collapse; margin-top: 14px; border-top: 1px solid var(--line); }
table.sums td { padding: 7px 6px; vertical-align: top; }
table.sums tr.t td { border-top: 1px solid var(--line); font-weight: 700; }
.banner { background: var(--warn-bg); border: 1px solid #f3c27c; border-radius: 6px; padding: 10px 14px; margin-bottom: 14px; }
table.statement { width: 100%; border-collapse: collapse; font-size: 14px; }
table.statement th { font-size: 12px; color: var(--muted); padding: 5px 6px; border-bottom: 1px solid var(--line); }
table.statement td { padding: 5px 6px; border-bottom: 1px solid #eef0f4; }
table.statement tr.b td { font-weight: 700; }
.red { color: var(--danger); }
details > summary { cursor: pointer; }
.rate-only-total { font-size: 20px; font-weight: 700; }
table.list tr.old-head td { background: #f0f2f5; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 7px 10px; }
table.list tr.old td { color: #4a5263; }
/* item drop-down on a quotation */
.dropdown.items-pick { position: fixed; right: auto; top: auto; bottom: auto; z-index: 40; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.dropdown.items-pick .pick-list { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.dropdown.items-pick .pick { display: grid; grid-template-columns: 62px 1fr 34px 170px; gap: 8px; align-items: baseline; padding: 7px 10px; }
.dropdown.items-pick .pick-code { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; font-weight: 600; }
.dropdown.items-pick .pick-desc b { background: #fff3c4; font-weight: 600; }
.dropdown.items-pick .pick-unit { color: var(--muted); font-size: 12px; }
.dropdown.items-pick .pick-price { color: #2f7a3e; text-align: right; }
.dropdown.items-pick .pick-head, .dropdown.items-pick .pick-foot { flex: none; background: #f5f6f8; color: var(--muted); font-size: 12px; padding: 6px 10px; cursor: default; }
.dropdown.items-pick .pick-head { border-bottom: 1px solid var(--line); }
.dropdown.items-pick .pick-foot { border-top: 1px solid var(--line); }
.dropdown.items-pick .pick-head:hover, .dropdown.items-pick .pick-foot:hover { background: #f5f6f8; }
@media (max-width: 700px) {
  .dropdown.items-pick .pick { grid-template-columns: 54px 1fr; }
  .dropdown.items-pick .pick-unit, .dropdown.items-pick .pick-price { grid-column: 2; }
}
/* drag to reorder */
.drag-handle { cursor: grab; touch-action: none; font-size: 16px; line-height: 1; letter-spacing: -1px; color: var(--muted); }
.drag-handle:active { cursor: grabbing; }
.drag-row.dragging, .drag-row.dragging > td { opacity: .45; }
.drag-row.drop-before, .drag-row.drop-before > td { box-shadow: inset 0 3px 0 var(--accent); }
.drag-row.drop-after, .drag-row.drop-after > td { box-shadow: inset 0 -3px 0 var(--accent); }

.record-search { align-items: flex-end; flex-wrap: wrap; }
.record-search label:first-of-type { flex: 1 1 220px; }
.record-search input[name="year"] { max-width: 8em; }
