/* ใบเสนอราคา: สีหลักแก้ที่ --brand */
:root {
  --brand: #3b5bdb;
  --brand-soft: #edf2ff;
  --ok: #2b8a3e;
  --ok-soft: #ebfbee;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c2233;
  --muted: #5c6580;
  --line: #e1e5ef;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.06), 0 6px 20px rgba(20, 30, 60, 0.06);
  --radius: 16px;
  color-scheme: light;
}

/* dark: follows the device unless the switch picked one (data-theme on <html>, remembered in localStorage) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #7c9cff;
    --brand-soft: #1d2647;
    --ok: #69db7c;
    --ok-soft: #13301b;
    --bg: #0f1320;
    --card: #171c2c;
    --text: #e8ebf5;
    --muted: #a3abc4;
    --line: #2a3150;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #7c9cff;
  --brand-soft: #1d2647;
  --ok: #69db7c;
  --ok-soft: #13301b;
  --bg: #0f1320;
  --card: #171c2c;
  --text: #e8ebf5;
  --muted: #a3abc4;
  --line: #2a3150;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.65 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

h1, h2, h3 { line-height: 1.3; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.45rem, 4.5vw, 2.1rem); }
h2 { font-size: 1.3rem; margin-top: 0; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 0.75em; }
a { color: var(--brand); }
small { font-size: 0.82em; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.wrap {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 0 16px;
}

main.wrap > section {
  margin: 0 auto 20px;
  padding: 22px 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-inner { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.logo { border-radius: 50%; flex: none; }
.top-text { display: grid; line-height: 1.3; flex: 1; min-width: 0; }
.top-text span { color: var(--muted); font-size: 0.85rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn:focus-visible, .pk:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }

/* ---------- hero ---------- */
.hero { margin-top: 20px !important; background: linear-gradient(135deg, var(--brand-soft), var(--card)) !important; }
.eyebrow { color: var(--brand); font-weight: 700; margin-bottom: 0.4em; }
.meta { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 14px 0 0; }
.meta div { display: grid; }
.meta dt { color: var(--muted); font-size: 0.85rem; }
.meta dd { margin: 0; font-weight: 600; }

/* ---------- packages ---------- */
.packages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.pk {
  position: relative;
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 18px 16px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.pk:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.pk.is-on { border-color: var(--brand); background: var(--brand-soft); }
.pk-name { font-weight: 700; }
.pk-price { font-size: 1.5rem; font-weight: 700; color: var(--brand); }
.pk-price small { font-size: 0.85rem; font-weight: 500; }
.pk-note { color: var(--muted); font-size: 0.88rem; line-height: 1.5; }
.pk-badge {
  position: absolute;
  top: -11px;
  right: 12px;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--ok);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ---------- items ---------- */
.items { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; transition: border-color 0.15s, background 0.15s; }
.item.is-on { border-color: color-mix(in srgb, var(--brand) 55%, var(--line)); background: color-mix(in srgb, var(--brand-soft) 55%, var(--card)); }
.item-head { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; align-items: center; gap: 10px; cursor: pointer; }
.item-head input { width: 22px; height: 22px; accent-color: var(--brand); margin: 0; }
.item-head input:disabled { cursor: not-allowed; }
.item-code {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}
.item-name { font-weight: 600; }
.item-price { font-weight: 700; white-space: nowrap; }
.item-price small { font-weight: 500; color: var(--muted); }
.item-details { margin: 10px 0 4px; padding-left: 1.2em; color: var(--muted); font-size: 0.93rem; }
.item-details li { margin-bottom: 2px; }
.item-time { margin: 0; color: var(--muted); font-size: 0.85rem; }

/* ---------- yearly ---------- */
.yearly { display: grid; gap: 6px; margin: 0 0 14px; padding: 0; list-style: none; }
.yearly li, .contact-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.toggle { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; color: var(--muted); font-size: 0.93rem; }
.toggle strong { color: var(--text); }
.toggle input { width: 20px; height: 20px; margin-top: 3px; flex: none; accent-color: var(--brand); }

/* ---------- summary ---------- */
.summary { border: 2px solid var(--brand) !important; }
.sum-list { margin: 0 0 12px; }
.sum-list div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sum-list dt { min-width: 0; }
.sum-list dd { margin: 0; font-weight: 600; text-align: right; white-space: nowrap; }
.sum-list .is-discount dd { color: var(--ok); }
.sum-list .is-total { font-size: 1.12rem; font-weight: 700; border-bottom-width: 2px; }
.sum-list .is-total dd { color: var(--brand); font-weight: 700; }
.sum-list .is-sub { color: var(--muted); font-size: 0.92rem; }
.sum-list .is-sub dd { font-weight: 500; }
.sum-list div:last-child dd { white-space: normal; }
.sum-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.copied { margin: 10px 0 0; padding: 8px 12px; border-radius: 10px; background: var(--ok-soft); color: var(--ok); font-weight: 600; }

/* ---------- terms / scope ---------- */
.terms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.terms article, .box { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; }
.terms p, .box ul { margin: 0; color: var(--muted); font-size: 0.95rem; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.ticks, .crosses { padding: 0; list-style: none; }
.ticks li, .crosses li { position: relative; padding-left: 1.6em; margin-bottom: 4px; }
.ticks li::before { content: '✓'; position: absolute; left: 0; color: var(--ok); font-weight: 700; }
.crosses li::before { content: '✕'; position: absolute; left: 0; color: #e03131; font-weight: 700; }
.notes { margin: 0; padding-left: 1.3em; color: var(--muted); }
.notes li { margin-bottom: 8px; }
.notes strong { color: var(--text); }
.contact-list { margin: 0; padding: 0; list-style: none; }

/* ---------- sticky total (phones) ---------- */
.sticky {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(20, 30, 60, 0.08);
  transition: transform 0.2s;
}
.sticky.is-hidden { transform: translateY(110%); }
.sticky-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 56px; font-size: 0.95rem; }
.sticky strong { color: var(--brand); font-size: 1.1rem; }

.foot { padding: 8px 0 28px; color: var(--muted); font-size: 0.85rem; text-align: center; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .sticky { display: none; }
}

@media (max-width: 720px) {
  .packages, .terms, .cols { grid-template-columns: minmax(0, 1fr); }
  .pk { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .pk-note { grid-column: 1 / -1; }
  .pk-price { grid-row: 1; grid-column: 2; font-size: 1.25rem; }
  .item-head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .item-code { grid-column: 2; justify-self: start; }
  .item-name { grid-column: 2; grid-row: 2; }
  .item-price { grid-column: 3; grid-row: 1 / span 2; }
  .hide-sm { display: none; }
  main.wrap > section { padding: 18px 16px; }
  .print-btn { padding: 0 14px; font-size: 0.85rem; }
  .print-btn .lg { display: none; }
}

.theme-btn {
  width: 44px;
  padding: 0;
  flex: none;
}
.theme-btn svg { width: 20px; height: 20px; }
.theme-btn .moon { display: none; }
:root[data-theme="dark"] .theme-btn .sun { display: none; }
:root[data-theme="dark"] .theme-btn .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .sun { display: none; }
  :root:not([data-theme="light"]) .theme-btn .moon { display: block; }
}

@media (max-width: 380px) {
  .top-text span { display: none; }
  .sum-list div { flex-wrap: wrap; }
  .sum-list dd { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- print / PDF ---------- */
@media print {
  :root, :root[data-theme] {
    --brand: #3b5bdb; --brand-soft: #edf2ff; --ok: #2b8a3e; --ok-soft: #ebfbee;
    --bg: #fff; --card: #fff; --text: #1c2233; --muted: #5c6580; --line: #e1e5ef; --shadow: none; color-scheme: light;
  }
  body { padding: 0; font-size: 12pt; }
  .top { position: static; backdrop-filter: none; }
  .print-btn, .theme-btn, .sticky, .sum-actions, .copied, .toggle input, .item-head input { display: none !important; }
  .item:not(.is-on) { display: none; }
  main.wrap > section { break-inside: avoid; box-shadow: none; }
  main.wrap > section:has(.packages) { display: none; }
}
