:root {
  --blue: #1C6BB0;
  --navy: #11365C;
  --red: #C8102E;
  --yellow: #F5C518;   /* lines and blocks only, never text */
  --ink: #1d2630;
  --muted: #5b6774;
  --line: #d9dfe6;
  --bg: #f4f6f9;
  --card: #fff;
  --ok: #2e7d4f;
  --warn: #9a5b00;
  --radius: 10px;
  --tabbar-h: 60px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 17px; line-height: 1.6;
}
a { color: var(--blue); }
h1 { font-size: 22px; margin: 4px 0 14px; font-weight: 700; color: var(--navy); }
h2 { font-size: 19px; margin: 20px 0 10px; font-weight: 700; color: var(--navy); }
h3 { font-size: 17px; margin: 0 0 6px; font-weight: 700; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff; padding: 10px 16px; border-bottom: 3px solid var(--yellow);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.sync { display: flex; align-items: center; gap: 6px; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 15px; cursor: pointer; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa5b1; }
.dot.ok { background: #5fd38d; } .dot.pending { background: var(--yellow); } .dot.err { background: #ff6b6b; }
.view { max-width: 960px; margin: 0 auto; padding: 16px 14px calc(var(--tabbar-h) + 28px); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; text-align: center; padding: 16px 4px; text-decoration: none; color: var(--muted); font-weight: 500; }
.tabbar a.active { color: var(--blue); font-weight: 700; box-shadow: inset 0 3px 0 var(--blue); }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.warn { color: var(--warn); }
.err { color: var(--red); }
.tag { display: inline-block; font-size: 14px; padding: 1px 8px; border-radius: 999px; background: #e8eef5; color: var(--navy); }
.tag.warn { background: #fff3d6; color: var(--warn); }
.tag.ok { background: #e1f3e8; color: var(--ok); }
.list { list-style: none; padding: 0; margin: 0; }
.list > li > a, .list > li > .item { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; text-decoration: none; color: var(--ink); }
.list > li > a:active { background: #eef3f9; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* forms */
label { display: block; font-weight: 500; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 17px; padding: 10px 12px; border: 1px solid #b9c3ce; border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
input[type="checkbox"] { width: 22px; height: 22px; vertical-align: middle; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 12px 0; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 18px;
  font: inherit; font-weight: 700; border-radius: 8px; border: 1px solid var(--blue); background: #fff; color: var(--blue);
  cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.cta { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.small { min-height: 38px; padding: 4px 12px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.search { margin-bottom: 12px; }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 8px; }
.photo { position: relative; aspect-ratio: 1; background: #e6eaef; border-radius: 8px; overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .cap { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(17,54,92,.75); color: #fff; font-size: 13px; padding: 2px 6px; }
.photo .del { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,.9); border: 0; border-radius: 6px; font-size: 13px; padding: 2px 6px; color: var(--red); }
.photo .up { position: absolute; top: 4px; left: 4px; background: var(--yellow); width: 10px; height: 10px; border-radius: 50%; }

/* quote editor */
.work { border-left: 4px solid var(--blue); }
.params { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
.items { width: 100%; border-collapse: collapse; margin-top: 10px; }
.items th, .items td { border-bottom: 1px solid var(--line); padding: 8px 4px; text-align: left; vertical-align: top; }
.items th { font-size: 14px; color: var(--muted); font-weight: 500; }
.items td.num, .items th.num { text-align: right; white-space: nowrap; }
.items input, .items select { padding: 6px 8px; font-size: 16px; }
.items .qty { width: 80px; } .items .price { width: 100px; }
.items tr.zero { opacity: .45; }
@media (max-width: 639px) {
  .items thead { display: none; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px 10px; padding: 12px 0;
    grid-template-areas: "name name del" "brand brand brand" "qty price amt"; border-bottom: 1px solid var(--line); }
  .items td { border: 0; padding: 0; text-align: left !important; }
  .items td.name { grid-area: name; }
  .items td.delc { grid-area: del; text-align: right !important; }
  .items td.brand { grid-area: brand; }
  .items td.qtyc { grid-area: qty; }
  .items td.pricec { grid-area: price; }
  .items td.amt { grid-area: amt; text-align: right !important; align-self: end; padding-bottom: 10px; font-weight: 700; }
  .items td.unitc { display: none; }
  .items td[data-l]::before { content: attr(data-l); display: block; font-size: 13px; color: var(--muted); }
  .items .qty, .items .price { width: 100%; }
}
.totals { margin-left: auto; max-width: 360px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 2px solid var(--navy); font-weight: 700; font-size: 20px; margin-top: 6px; padding-top: 8px; }
.sticky-actions { position: sticky; bottom: calc(var(--tabbar-h) + 8px); background: var(--bg); padding: 8px 0; z-index: 5; }

/* printable quote */
.doc { background: #fff; border: 1px solid var(--line); padding: 28px; color: #000; }
.doc h1 { text-align: center; color: #000; letter-spacing: 6px; margin-bottom: 4px; }
.doc .head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; border-bottom: 3px solid var(--yellow); padding-bottom: 10px; margin-bottom: 14px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 15px; }
.doc th, .doc td { border: 1px solid #999; padding: 5px 6px; }
.doc th { background: #eef2f6; }
.doc td.num { text-align: right; white-space: nowrap; }
.doc .group td { background: #f6f8fa; font-weight: 700; }
.doc .sign { display: flex; justify-content: space-between; margin-top: 36px; gap: 20px; }
.doc .sign div { flex: 1; border-top: 1px solid #000; padding-top: 4px; text-align: center; }
.doc .terms { font-size: 14px; margin-top: 16px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; transition: .2s; z-index: 50; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 13px; }
  .no-print, .topbar, .tabbar, .actions { display: none !important; }
  .view { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; }
  .doc th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 639px) { .doc { padding: 14px; } .doc table { font-size: 14px; } }
