/* Logo colours — the same palette as quote_app.py */
:root {
  --navy: #202060; --navy-hover: #2C2C7A;
  --orange: #EC8A1C; --orange-hover: #D47812; --orange-soft: #FDF1E2;
  --green: #2FA84A; --green-hover: #258C3C; --green-soft: #E8F6EB;
  --bg: #F3F4F9; --card: #FFFFFF; --border: #E1E3EE; --field: #F8F9FC;
  --text: #1E1E3F; --muted: #7A7C95;
  --err: #D64545; --err-soft: #FCEAEA;
  --warn-text: #9A6B00; --warn-soft: #FFF4CC;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.35;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ---------- header ---------- */
.top { background: var(--card); }
.top-inner {
  max-width: 1000px; margin: 0 auto; padding: 14px 24px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.logo { height: 58px; width: auto; }
.titles { text-align: right; }
.titles h1 { margin: 0; font-size: 24px; color: var(--navy); }
.titles p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.strip { display: flex; height: 4px; }
.strip i { flex: 1; }
.strip i:nth-child(1) { background: var(--navy); }
.strip i:nth-child(2) { background: var(--orange); }
.strip i:nth-child(3) { background: var(--green); }

.page { max-width: 1000px; margin: 0 auto; padding: 16px 24px 40px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 20px; margin-bottom: 14px;
}

/* ---------- price list state ---------- */
.prices-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 10px 8px 16px; margin-bottom: 10px;
}
.prices-text { display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: baseline; }
.prices-text strong { color: var(--navy); font-size: 15px; }
.prices-text span { color: var(--muted); font-size: 13px; }
.prices-bar.error .prices-text strong { color: var(--err); }
.btn-icon {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 10px;
  background: var(--field); color: var(--navy); font-size: 20px;
}
.btn-icon:hover { background: var(--border); }
.offline-note {
  background: var(--warn-soft); color: var(--warn-text); border: 2px solid #F1D98A;
  border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; font-weight: 600;
}

/* ---------- details ---------- */
.details { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-start; }
.field { display: flex; flex-direction: column; min-width: 0; }
.field.grow { flex: 1 1 260px; }
.cap { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
input[type="text"] {
  height: 48px; padding: 0 12px; border-radius: 10px; outline: none;
  background: var(--field); border: 2px solid var(--border);
  color: var(--navy); font-size: 16px; font-weight: 600; width: 100%;
}
input[type="text"]::placeholder { color: #B5B7C9; font-weight: 400; }
input[type="text"]:focus { border-color: var(--orange); }
input.err { border-color: var(--err) !important; }
input.ok { border-color: var(--green); }
input.center { text-align: center; }
#date { width: 150px; }
.discount-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#discount { width: 86px; font-size: 18px; font-weight: 700; }
.pct { font-size: 18px; font-weight: 700; color: var(--navy); }
.hint { font-size: 12px; padding: 5px 10px; border-radius: 8px; white-space: nowrap; }
.hint.need { background: var(--orange-soft); color: var(--orange-hover); }
.hint.bad { background: var(--err-soft); color: var(--err); }
.hint.good { background: var(--green-soft); color: var(--green-hover); }

/* ---------- items ---------- */
.items { padding: 14px; }
.items-head, .row {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) 90px 150px 130px 40px;
  gap: 8px; align-items: center;
}
.items-head {
  background: var(--navy); color: #fff; border-radius: 10px; padding: 10px;
  font-size: 12px; font-weight: 700; text-align: center; margin-bottom: 6px;
}
.row {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; margin: 6px 0;
}
.row.missing { background: #FFFBEA; border-color: #F1D98A; }
.row .sn { text-align: center; font-weight: 700; color: var(--navy); }
.row input[type="text"] { height: 46px; border-width: 1px; font-weight: 400; color: var(--text); }
.row input.qty { text-align: center; }
.item-wrap { position: relative; min-width: 0; }
.price {
  text-align: center; font-size: 13px; color: var(--muted);
  border-radius: 8px; padding: 6px 4px; white-space: nowrap;
}
.price.found { background: var(--green-soft); color: var(--green-hover); }
.price.pick { background: var(--orange-soft); color: var(--orange-hover); }
.price.none { background: var(--warn-soft); color: var(--warn-text); }
.total { text-align: center; font-weight: 700; white-space: nowrap; }
.del {
  width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 15px;
}
.del:hover { background: var(--err-soft); color: var(--err); }
.mini { display: none; }

.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 3px); z-index: 20;
  background: var(--card); border: 2px solid var(--orange); border-radius: 10px;
  padding: 5px; box-shadow: 0 8px 24px rgba(32, 32, 96, .18);
}
.suggest.above { top: auto; bottom: calc(100% + 3px); }
.suggest button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  border-radius: 7px; padding: 0 12px; min-height: 44px; font-size: 15px; color: var(--text);
}
.suggest button.active, .suggest button:hover { background: var(--orange-soft); }
.suggest .note { color: var(--muted); font-size: 12px; padding: 6px 12px 4px; }

.btn-add {
  width: 100%; min-height: 50px; margin-top: 8px; border-radius: 10px;
  background: var(--orange-soft); color: var(--orange-hover);
  border: 2px solid var(--orange); font-size: 16px; font-weight: 700;
}
.btn-add:hover { background: #FBE2C3; }

/* ---------- totals and actions ---------- */
.footer { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: center; justify-content: space-between; }
.tline { display: grid; grid-template-columns: 170px 130px auto; gap: 8px; align-items: baseline; color: var(--muted); font-size: 14px; }
.tline b { text-align: right; }
.tline em { font-style: normal; font-size: 11px; }
.tline.grand { color: var(--navy); font-size: 19px; font-weight: 700; }
.tline.grand em { font-size: 16px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-plain {
  min-height: 52px; padding: 0 18px; border-radius: 12px; background: transparent;
  border: 1px solid var(--border); color: var(--navy); font-size: 14px;
}
.btn-plain:hover { background: var(--field); }
.btn-go {
  min-height: 52px; padding: 0 32px; border-radius: 12px; border: 0;
  background: var(--green); color: #fff; font-size: 17px; font-weight: 700;
}
.btn-go:hover { background: var(--green-hover); }
.btn-go:disabled { opacity: .6; cursor: default; }
.btn-go.small { min-height: 44px; font-size: 15px; }

/* ---------- result ---------- */
.result { border: 2px solid var(--green); }
.result.warn { border-color: #E0B93A; }
.result h2 { margin: 0 0 6px; font-size: 17px; color: var(--green-hover); }
.result.warn h2 { color: var(--warn-text); }
.result pre { margin: 0 0 12px; font: inherit; white-space: pre-wrap; word-break: break-word; }
.downloads { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-dl {
  flex: 1 1 200px; display: flex; align-items: center; justify-content: center;
  min-height: 54px; border-radius: 12px; text-decoration: none; font-size: 16px; font-weight: 700; color: #fff;
}
.btn-dl.excel { background: var(--green); }
.btn-dl.excel:hover { background: var(--green-hover); }
.btn-dl.pdf { background: var(--navy); }
.btn-dl.pdf:hover { background: var(--navy-hover); }
.btn-dl.off { background: var(--border); color: var(--muted); pointer-events: none; }
.status { color: var(--muted); font-size: 13px; margin: 4px 4px 0; min-height: 18px; }
.status.err { color: var(--err); }

/* ---------- message box ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 20px; width: min(440px, calc(100vw - 32px));
  color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(30, 30, 63, .45); }
dialog h3 { margin: 0 0 8px; color: var(--navy); font-size: 17px; }
dialog p { margin: 0 0 16px; white-space: pre-wrap; word-break: break-word; }
.msg-actions { display: flex; justify-content: flex-end; gap: 8px; }
.msg-actions .btn-plain { min-height: 44px; }

/* ---------- phone ---------- */
@media (max-width: 680px) {
  .top-inner { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .logo { height: 40px; }
  .titles h1 { font-size: 18px; }
  .titles p { display: none; }
  .page { padding: 12px 12px 32px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .card { padding: 12px; }
  .field, .field.grow { flex: 1 1 100%; }
  #date { width: 100%; }
  input[type="text"] { height: 52px; }
  #discount { width: 110px; }

  .items { padding: 10px; }
  .items-head { display: none; }
  .row {
    grid-template-columns: 26px 96px minmax(0, 1fr) 44px;
    grid-template-areas: "sn item item del" ". qty info info";
    gap: 8px 6px; padding: 10px 8px;
  }
  .row .sn { grid-area: sn; }
  .row .item-wrap { grid-area: item; }
  .row input.qty { grid-area: qty; }
  .row .info { grid-area: info; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .row .del { grid-area: del; width: 44px; height: 44px; }
  .row input[type="text"] { height: 50px; }
  .price { padding: 8px 10px; }
  .mini { display: inline; color: var(--muted); font-weight: 400; font-size: 12px; }

  .footer { flex-direction: column; align-items: stretch; }
  .tline { grid-template-columns: 1fr auto auto; }
  .actions { flex-direction: column-reverse; }
  .btn-go, .btn-plain { width: 100%; min-height: 56px; }
  .msg-actions .btn-go, .msg-actions .btn-plain { width: auto; min-height: 48px; }
  .btn-dl { flex-basis: 100%; min-height: 58px; }
}
@media (min-width: 681px) {
  .row .info { display: contents; }
}
