:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #fbf8f4;
  --ink: #251a16;
  --muted: #76675f;
  --line: #e8dfd8;
  --brand: #8b331f;
  --brand-dark: #632314;
  --brand-soft: #f6e8df;
  --green: #247154;
  --green-soft: #e8f5ee;
  --amber: #a76413;
  --amber-soft: #fff3df;
  --red: #af2f36;
  --red-soft: #feecee;
  --shadow: 0 16px 45px rgba(74, 45, 31, 0.08);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.muted { color: var(--muted); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 20%, #f2d7c5 0, transparent 34%), linear-gradient(145deg, #f9f4ed, #eee4da); }
.login-card { width: min(460px, 100%); padding: 42px; border: 1px solid rgba(139, 51, 31, 0.14); border-radius: 28px; background: rgba(255,255,255,0.94); box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 8px; font-size: 2.2rem; }
.login-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; margin-bottom: 20px; border-radius: 18px; background: var(--brand); color: white; font: 800 1.8rem Georgia, serif; box-shadow: 0 10px 25px rgba(139, 51, 31, .25); }
.brand-mark.small { width: 40px; height: 40px; margin: 0; border-radius: 12px; font-size: 1.2rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px 20px; display: flex; flex-direction: column; background: #2a1812; color: white; }
.brand-row { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; }
.brand-row strong, .brand-row span { display: block; }
.brand-row span { margin-top: 2px; color: #cdbdb5; font-size: .8rem; }
.sidebar nav { display: grid; gap: 6px; }
.nav-item { width: 100%; padding: 12px 14px; border: 0; border-radius: 12px; background: transparent; color: #dbcfc9; text-align: left; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.11); color: white; }
.sidebar-note { margin-top: auto; padding: 14px; display: flex; align-items: center; gap: 8px; border-radius: 12px; background: rgba(255,255,255,.07); color: #d8cbc4; font-size: .78rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #5dd79e; box-shadow: 0 0 0 4px rgba(93,215,158,.12); }

main { min-width: 0; padding: 0 34px 50px; }
.topbar { min-height: 112px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 0; font-size: 1.75rem; }
.topbar-status { padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .78rem; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .4; transform: translateY(3px); } }

.panel { padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 8px 25px rgba(74,45,31,.035); }
.panel h2 { margin: 0; font-size: 1.18rem; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 20px; }
.safety-banner { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; padding: 18px 20px; border: 1px solid #bfdfd0; border-radius: 17px; background: var(--green-soft); color: #1d5d45; }
.safety-banner.warm { border-color: #ecd0ad; background: var(--amber-soft); color: #75490f; }
.safety-banner p { margin: 3px 0 0; opacity: .85; }
.safety-icon { width: 35px; height: 35px; display: grid; place-items: center; flex: none; border-radius: 50%; background: rgba(255,255,255,.75); font-weight: 900; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.metric-card { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: block; margin: 7px 0 2px; font-size: 2rem; font-family: Georgia, serif; }
.two-column { display: grid; grid-template-columns: 1.15fr .85fr; gap: 20px; }
.accent-panel { background: linear-gradient(145deg, #fff, var(--brand-soft)); }
.step-list { margin: 0; padding: 0; display: grid; gap: 16px; list-style: none; }
.step-list li { display: grid; grid-template-columns: 34px 1fr; gap: 12px; }
.step-list li > span { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 800; }
.step-list p { margin: 2px 0 0; color: var(--muted); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.chip, .safe-pill { padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.72); color: var(--brand); font-size: .73rem; font-weight: 700; }
.safe-pill { background: var(--green-soft); color: var(--green); }

label { display: grid; gap: 7px; margin-bottom: 15px; color: #594941; font-size: .84rem; font-weight: 700; }
input, textarea, select { width: 100%; padding: 11px 12px; border: 1px solid #d9cec7; border-radius: 11px; outline: none; background: white; color: var(--ink); font-weight: 400; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139,51,31,.1); }
textarea { resize: vertical; line-height: 1.55; }
button.primary, button.secondary, button.ghost { padding: 10px 15px; border-radius: 11px; font-weight: 750; }
button.primary { border: 1px solid var(--brand); background: var(--brand); color: white; }
button.primary:hover { background: var(--brand-dark); }
button.secondary { border: 1px solid #d4c6bd; background: white; color: var(--ink); }
button.ghost { border: 1px solid var(--line); background: transparent; color: inherit; }
button.full { width: 100%; }
button:disabled { cursor: wait; opacity: .55; }
.sidebar > .ghost { margin-top: 10px; color: #ddd0ca; border-color: rgba(255,255,255,.16); }
.button-row { display: flex; justify-content: flex-end; gap: 10px; }
.form-message { min-height: 20px; margin: 10px 0 0; color: var(--red); font-size: .83rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 20px; margin-bottom: 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 0 15px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.checkbox-row { display: flex; align-items: center; gap: 9px; }
.checkbox-row input { width: auto; }

.customer-summary { margin-bottom: 16px; padding: 14px; border-radius: 12px; background: var(--surface-2); color: var(--muted); }
.analysis-lines { display: grid; gap: 12px; }
.analysis-line { display: grid; grid-template-columns: minmax(155px,1fr) minmax(155px,1fr) minmax(125px,.7fr) minmax(220px,1.25fr); gap: 14px; align-items: end; padding: 15px; border: 1px solid var(--line); border-radius: 14px; }
.analysis-line h3 { margin: 0 0 3px; font-size: 1rem; }
.analysis-line p { margin: 0; color: var(--muted); font-size: .8rem; }
.analysis-line label { margin: 0; }
.match-warning { color: var(--red) !important; }
.confirmation-box { margin-top: 18px; padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-radius: 14px; background: var(--amber-soft); color: #70470f; }
.confirmation-box p { margin: 2px 0 0; }

.catalog-list, .availability-list, .orders-list { display: grid; gap: 12px; }
.catalog-group { padding: 16px; border: 1px solid var(--line); border-radius: 14px; }
.catalog-group-head { display: flex; justify-content: space-between; gap: 14px; }
.catalog-group h3 { margin: 0; }
.alias-text { color: var(--muted); font-size: .8rem; }
.variant-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.variant-chip { padding: 7px 10px; border-radius: 9px; background: var(--surface-2); font-size: .8rem; }
.empty-state { padding: 28px; border: 1px dashed #d5c7be; border-radius: 14px; color: var(--muted); text-align: center; }
.availability-row { display: grid; grid-template-columns: 1fr 170px 1fr auto; align-items: center; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; }
.availability-row label { margin: 0; }
.availability-row strong, .availability-row small { display: block; }
.availability-row small { color: var(--muted); }
.order-card { padding: 16px; border: 1px solid var(--line); border-radius: 14px; }
.order-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.order-head h3 { margin: 0; }
.order-lines { margin: 12px 0; padding-left: 21px; color: #594941; }
.status-badge { padding: 5px 9px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: .75rem; font-weight: 800; }
.status-badge.confirmed { background: var(--green-soft); color: var(--green); }

.roadmap-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.roadmap-card span { display: inline-block; margin-bottom: 16px; padding: 5px 9px; border-radius: 99px; font-size: .72rem; font-weight: 800; }
.roadmap-card.ready span { background: var(--green-soft); color: var(--green); }
.roadmap-card.waiting span { background: var(--amber-soft); color: var(--amber); }
.roadmap-card.blocked span { background: var(--red-soft); color: var(--red); }
.roadmap-card p { margin-bottom: 0; color: var(--muted); }
.channel-grid { margin-top: 20px; }
.crm-panel { margin-top: 20px; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.crm-results { display: grid; gap: 12px; margin-top: 16px; }
.crm-customer { padding: 15px; border: 1px solid var(--line); border-radius: 13px; }
.crm-customer h3 { margin: 0; }
.crm-history { margin: 10px 0 0; padding-left: 20px; color: var(--muted); }

.toast { position: fixed; z-index: 50; top: 20px; right: 24px; max-width: 420px; padding: 13px 16px; border-radius: 12px; background: #2c211c; color: white; box-shadow: var(--shadow); }
.toast.error { background: var(--red); }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .two-column, .roadmap-grid { grid-template-columns: 1fr 1fr; }
  .field-grid { grid-template-columns: repeat(2, 1fr); }
  .analysis-line { grid-template-columns: 1fr 1fr; }
  .analysis-line > label:last-child { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(2, 1fr); }
  .sidebar-note { margin-top: 16px; }
  main { padding: 0 15px 40px; }
  .topbar { min-height: 95px; }
  .topbar-status { display: none; }
  .metric-grid, .two-column, .form-grid, .roadmap-grid, .field-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .analysis-line, .availability-row { grid-template-columns: 1fr; }
  .analysis-line > label:last-child { grid-column: auto; }
  .confirmation-box { align-items: stretch; flex-direction: column; }
  .login-card { padding: 28px; }
}
