@font-face {
  font-family: 'Sarabun';
  src: url('../fonts/Sarabun-Regular.ttf') format('truetype');
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: 'Sarabun';
  src: url('../fonts/Sarabun-Medium.ttf') format('truetype');
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: 'Sarabun';
  src: url('../fonts/Sarabun-SemiBold.ttf') format('truetype');
  font-weight: 600; font-display: swap;
}
@font-face {
  font-family: 'Sarabun';
  src: url('../fonts/Sarabun-Bold.ttf') format('truetype');
  font-weight: 700; font-display: swap;
}

:root {
  --ci: #0d3d54;
  --ci-soft: rgba(13, 61, 84, 0.08);
  --accent: #0d9488;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --rose: #e11d48;
  --rose-soft: rgba(225, 29, 72, 0.12);
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.12);
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 16px;
  --sidebar-w: 248px;
  --bottom-h: 64px;
  --top-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input { font-family: inherit; }
.hint { color: var(--muted); font-size: 12px; }
.na { color: var(--muted); font-style: italic; }
.src-btn {
  border: none; background: var(--ci-soft); color: var(--ci);
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  cursor: pointer; margin-left: 4px; vertical-align: middle;
}
.pill {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.pill.amber { background: var(--amber-soft); color: #92400e; }
.pill.teal { background: var(--accent-soft); color: #0f766e; }
.pill.rose { background: var(--rose-soft); color: #9f1239; }
.pill.green { background: var(--green-soft); color: #065f46; }

/* —— Login —— */
.login-page {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(13,148,136,0.18), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(13,61,84,0.16), transparent 50%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px 24px;
  border: 1px solid var(--border);
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.login-brand img { width: 52px; height: 52px; border-radius: 50%; }
.login-brand h1 { margin: 0; font-size: 20px; color: var(--ci); }
.login-brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: #fff; font-size: 15px;
}
.field input:focus { outline: 2px solid rgba(13,148,136,0.35); border-color: var(--accent); }
.btn-primary {
  width: 100%; border: none; border-radius: 12px; padding: 13px 16px;
  background: linear-gradient(135deg, #0d9488, #0d3d54);
  color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
}
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.login-error {
  display: none; margin: 0 0 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--rose-soft); color: #9f1239; font-size: 13px; font-weight: 600;
}
.login-error.show { display: block; }
.login-foot { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }
.sso-disabled {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  border: 1px dashed var(--border); color: var(--muted); font-size: 12px; text-align: center;
}

/* —— App shell —— */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh; max-height: 100dvh;
}
.sidebar {
  background: linear-gradient(180deg, #0d3d54 0%, #0a2f40 100%);
  color: #e8f4f8;
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 16px; }
.brand img { border-radius: 50%; background: #fff; width: 44px; height: 44px; }
.brand-text { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; opacity: 0.7; }
.nav-group-label {
  margin: 10px 8px 4px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.45;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px;
  font-weight: 600; font-size: 14px; color: rgba(255,255,255,0.78);
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active {
  background: rgba(13, 148, 136, 0.28); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.35);
}
.nav-item.soon { opacity: 0.55; cursor: default; }
.nav-ico {
  width: 28px; height: 28px; border-radius: 8px;
  background: rgba(255,255,255,0.1);
  display: grid; place-items: center; font-size: 13px; flex-shrink: 0;
}
.soon-tag {
  margin-left: auto; font-size: 10px; font-weight: 700;
  background: rgba(255,255,255,0.12); padding: 2px 7px; border-radius: 999px;
}
.sidebar-footer { margin-top: auto; padding: 12px 8px; font-size: 11px; opacity: 0.55; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; max-height: 100dvh; overflow: hidden; }
.topbar {
  height: var(--top-h); flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; gap: 16px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; flex-wrap: wrap; }
.mobile-brand { display: none; align-items: center; gap: 8px; font-weight: 700; }
.sample-tag {
  font-size: 11px; color: var(--muted); background: var(--ci-soft);
  padding: 4px 10px; border-radius: 999px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.btn-ghost {
  border: 1px solid var(--border); background: var(--card); border-radius: 10px;
  padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text);
}
.content {
  flex: 1; overflow: auto; padding: 20px 24px 32px;
  padding-bottom: calc(32px + var(--bottom-h));
}

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 16px 18px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }

.alerts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.alert-card {
  border-radius: var(--radius); padding: 14px 16px; border: 1px solid transparent;
}
.alert-card.warn { background: var(--amber-soft); border-color: rgba(245,158,11,0.35); }
.alert-card.danger { background: var(--rose-soft); border-color: rgba(225,29,72,0.25); }
.alert-card .al-title { font-weight: 700; margin-bottom: 4px; }

.hero-row { display: grid; grid-template-columns: 280px 1fr; gap: 14px; margin-bottom: 16px; }
.hero-ring-card { text-align: center; }
.ring-wrap { position: relative; width: 180px; height: 180px; margin: 0 auto 10px; }
.ring-wrap svg { width: 180px; height: 180px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #e2e8f0; stroke-width: 14; }
.ring-fg { fill: none; stroke: url(#ringGrad); stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 502.65; stroke-dashoffset: 502.65; transition: stroke-dashoffset 0.8s ease; }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-pct { font-size: 32px; font-weight: 700; color: var(--ci); line-height: 1; }
.ring-pct.sqm-mode { font-size: 22px; }
.ring-pct.unknown-target { font-size: 15px; font-weight: 700; max-width: 120px; margin: 0 auto; }
.ring-sub { font-size: 12px; color: var(--muted); }
.forecast-line { font-size: 13px; color: var(--muted); margin-top: 6px; }
.target-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.kpi {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 700; color: var(--ci); margin: 4px 0; }

.channel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.metric-card .big { font-size: 24px; font-weight: 700; color: var(--ci); }
.metric-card .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.metric-card.unknown { border-left: 4px solid var(--amber); }

.daily-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.daily-card .day { font-weight: 700; margin-bottom: 6px; }

.stock-section { margin-top: 8px; }
.stock-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.stock-count { font-size: 28px; font-weight: 700; }
.stock-count.push { color: var(--accent); }
.stock-count.hold { color: #b45309; }
.stock-count.abnormal { color: var(--rose); }

.sku-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-bottom: 16px; }
.sku-card { padding: 12px 14px; }
.sku-card .sku { font-weight: 700; font-size: 14px; color: var(--ci); }
.sku-card .model { font-size: 13px; margin-top: 2px; }
.sku-card .meta-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.sku-card .reason { margin-top: 8px; font-size: 12px; color: var(--muted); }

.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 18px 0 10px;
}
.section-title h2 { margin: 0; font-size: 16px; }

.coming-soon-panel {
  display: none; place-items: center; min-height: 40vh; text-align: center; padding: 40px 20px;
}
.coming-soon-panel.show { display: grid; }
.coming-soon-panel h2 { margin: 0 0 8px; color: var(--ci); }

.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card); border-top: 1px solid var(--border);
  z-index: 40;
}
.bottom-nav button {
  flex: 1; border: none; background: transparent; padding: 8px 4px 6px;
  font-size: 10px; font-weight: 600; color: var(--muted); display: flex;
  flex-direction: column; align-items: center; gap: 2px;
}
.bottom-nav button.active { color: var(--accent); }
.bottom-nav .bn-ico { font-size: 18px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-brand { display: flex; }
  .bottom-nav { display: flex; }
  .content { padding: 16px; padding-bottom: calc(24px + var(--bottom-h) + env(safe-area-inset-bottom, 0px)); }
  .alerts-row, .hero-row, .channel-grid, .daily-grid, .stock-summary, .kpi-grid {
    grid-template-columns: 1fr;
  }
  .hero-row { grid-template-columns: 1fr; }
  .sample-tag { display: none; }
}

/* Module 2 การตลาด */
.table-wrap { overflow-x: auto; margin-bottom: 12px; }
table.data {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; font-size: 12px;
}
table.data th, table.data td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th { background: #f1f5f9; color: var(--ci); font-weight: 700; white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
.ad-card .pill.cut { background: #ffe4e6; color: #be123c; }
.ad-card .pill.watch { background: #ffedd5; color: #c2410c; }
.ad-card .pill.keep { background: #dcfce7; color: #166534; }
.ad-card .pill.closed { background: #e2e8f0; color: #475569; }
.ad-card .pill.unmapped { background: #fce7f3; color: #9d174d; }
.na { color: #94a3b8; font-style: italic; }
@media (max-width: 900px) {
  table.data { font-size: 11px; }
  table.data th, table.data td { padding: 6px 8px; }
}

.data-table { width:100%; border-collapse:collapse; font-size:13px; background:var(--card); }
.data-table th, .data-table td { padding:8px 10px; border-bottom:1px solid var(--border); text-align:left; vertical-align:top; }
.data-table th { color:var(--muted); font-weight:600; font-size:12px; }
.data-table tr:last-child td { border-bottom:none; }

.mono-path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; word-break: break-all; max-width: 280px; }
.appr-card { margin-bottom: 12px; padding: 14px 16px; }
.appr-head { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.appr-title { font-weight:700; font-size:15px; }
.appr-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; align-items:center; }
.appr-comment { flex:1 1 180px; min-width:140px; padding:8px 10px; border:1px solid var(--border); border-radius:8px; font:inherit; }
.btn-appr { border:none; border-radius:8px; padding:8px 12px; font:inherit; font-weight:600; cursor:pointer; }
.btn-appr.ok { background:#059669; color:#fff; }
.btn-appr.no { background:#e11d48; color:#fff; }
.btn-appr.edit { background:#f59e0b; color:#111; }
.btn-appr:disabled { opacity:.5; cursor:not-allowed; }
@media (max-width: 480px) {
  .mono-path { max-width: 160px; }
  .appr-actions { flex-direction: column; align-items: stretch; }
}

.btn-bell { position:relative; border:none; background:transparent; font-size:18px; cursor:pointer; padding:6px 8px; border-radius:8px; }
.btn-bell:hover { background: rgba(15,23,42,.06); }
.notif-badge { position:absolute; top:0; right:0; min-width:16px; height:16px; padding:0 4px; border-radius:999px; background:#e11d48; color:#fff; font-size:10px; font-weight:700; line-height:16px; text-align:center; }
.notif-wrap { position:relative; }
.notif-panel { position:absolute; right:0; top:36px; width:min(360px,92vw); max-height:70vh; overflow:auto; background:var(--card,#fff); border:1px solid var(--border); border-radius:12px; box-shadow:0 12px 40px rgba(0,0,0,.12); z-index:40; padding:10px; }
.notif-panel-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; }
.notif-sound-row { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:8px; font-size:13px; }
.notif-list { display:flex; flex-direction:column; gap:8px; }
.notif-item { padding:10px; border-radius:10px; background:#f8fafc; border:1px solid var(--border); cursor:pointer; }
.notif-item.unread { border-color:rgba(14,165,233,.45); background:#f0f9ff; }
.notif-item .n-title { font-weight:700; font-size:13px; }
.settings-form-row { display:flex; flex-wrap:wrap; gap:10px; align-items:end; }
.settings-form-row label { display:flex; flex-direction:column; gap:4px; font-size:12px; color:var(--muted); min-width:140px; }
.settings-form-row input { padding:8px 10px; border:1px solid var(--border); border-radius:8px; font:inherit; }
.page-reg-card { margin-bottom:12px; padding:14px 16px; }
.page-reg-card .grid-fields { display:grid; grid-template-columns:repeat(auto-fill,minmax(180px,1fr)); gap:8px; margin-top:8px; }
.page-reg-card label { display:flex; flex-direction:column; gap:4px; font-size:12px; color:var(--muted); }
.page-reg-card input { padding:7px 9px; border:1px solid var(--border); border-radius:8px; font:inherit; }
.page-reg-card input:disabled { background:#f1f5f9; color:#64748b; }
.target-edit-row input { width:110px; padding:6px 8px; border:1px solid var(--border); border-radius:8px; font:inherit; }
