:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f8faff;
  --ink: #0e1118;
  --muted: #677085;
  --line: #e4e8ef;
  --line-soft: #eef1f5;
  --blue: #2864ed;
  --blue-soft: #eef3ff;
  --green: #08a43c;
  --red: #f12732;
  --orange: #f17813;
  --sidebar-width: 244px;
  --radius: 13px;
  --shadow: 0 1px 4px rgba(18, 34, 66, .035);
}

* { box-sizing: border-box; }

/* Panels below set display on elements they also toggle with .hidden — without this the
   author rule beats the browser default and a hidden skeleton keeps its grey box. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 17px 8px 45px;
}

/* The logo carries the name and the tagline itself, so the sidebar header is the artwork and
   nothing else. It is a white-background PNG on a white sidebar, which is why no cut-out is
   needed; `max-width` rather than a fixed width so the narrower sidebar below 900px shrinks
   it instead of clipping it. */
.brand {
  display: flex;
  align-items: center;
  height: 47px;
  padding: 0 7px;
}

.brand img { width: 100%; max-width: 192px; height: auto; }

.main-nav { margin-top: 28px; }

.nav-item {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 0 13px;
  color: #151a27;
  text-align: left;
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}

.nav-item:hover { background: #f5f7fb; }
.nav-item.active { color: #1c57dd; background: #eef3ff; font-weight: 600; }
.nav-item > svg { width: 17px; height: 17px; stroke-width: 1.8; }
.nav-item > span:nth-child(2) { flex: 1; }
.nav-chevron { width: 13px !important; height: 13px !important; }

.nav-children { display: grid; padding: 0 0 5px 28px; }
.nav-children a { display: flex; height: 40px; align-items: center; gap: 11px; }
.nav-children a svg { width: 17px; height: 17px; flex: 0 0 auto; }
.nav-children a:hover { color: var(--blue); }
.nav-children a.active { color: var(--blue); font-weight: 600; }

/* Small, quiet, and on the same line as the dates: it is context for the numbers, not a
   heading of its own. An unnamed page still shows — a page spending money is worth seeing
   even before somebody has typed what it is called. */
.page-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; }
.page-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 2px 10px 2px 2px;
  font-size: 12px;
  color: var(--ink);
}
.page-chip img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.page-chip .page-blank {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--line-soft); flex: 0 0 auto;
}
.page-chip small { color: var(--muted); font-size: 11px; }
.page-chip[data-unnamed="1"] { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 11px; }

/* ----- the alerts page ------------------------------------------------------------------ */
.al-panel { padding: 14px 16px; margin-bottom: 13px; }
.al-count { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.al-list { display: grid; gap: 8px; margin-top: 12px; }
.al-item {
  border: 1px solid var(--line);
  border-left: 3px solid var(--orange);
  border-radius: var(--radius);
  padding: 10px 13px;
}
.al-item[data-severity="red"] { border-left-color: var(--red); }
.al-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.al-head strong { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.al-head time { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.al-item p { margin: 5px 0 0; color: #4c566b; font-size: 12.5px; line-height: 1.55; }
.al-tips { display: grid; gap: 7px; margin: 12px 0 0; padding: 0 0 0 2px; list-style: none;
  font-size: 13px; line-height: 1.55; }
.al-empty { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
/* The bell on the page the bell leads to: still there so the topbar does not change shape,
   but not a link back to where you already are. */
.notification-btn.is-here { opacity: .45; cursor: default; }

.beta-pill {
  flex: 0 0 auto !important;
  border-radius: 5px;
  background: linear-gradient(90deg, #a45ce7, #ca57e5);
  color: #fff;
  padding: 1px 6px 0;
  font-size: 12px;
  font-weight: 700;
}

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
/* The page used to end flush against the bottom of the window, with the last card's border
   sitting on the edge of the glass. */
.app-footer { padding: 18px 20px 22px; color: var(--muted); font-size: 12px; text-align: center; }

.topbar {
  display: flex;
  height: 76px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f3f4f7;
  padding: 0 20px;
  background: rgba(255,255,255,.96);
}

.topbar-left, .topbar-right { display: flex; align-items: center; }
.topbar-left h1 { margin: 0 20px 0 0; font-size: 24px; letter-spacing: -.3px; }
.topbar-left time { margin-left: 16px; font-weight: 500; white-space: nowrap; }
.date-divider { display: block; width: 1px; height: 16px; margin-left: 14px; background: #e3e6eb; }

.icon-btn, .plain-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-btn {
  width: 42px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}

.icon-btn svg { width: 17px; height: 17px; }
.calendar-btn { margin-left: 15px; }
.mobile-menu { display: none; margin-right: 10px; }
/* The way back, left of the page's own name. The sidebar already reaches every page, but a
   sidebar entry is a place to go, not a way back from where you are — the owner opened the
   catalogue from the order table and found nothing that read as a return (2026-09-07). */
.topbar-back { margin-right: 10px; text-decoration: none; color: var(--ink); }
.topbar-back:hover { border-color: #aab7c9; background: #f8faff; }
.plain-icon { position: relative; width: 34px; height: 36px; }
.plain-icon svg { width: 20px; height: 20px; stroke-width: 1.8; }
.notification-btn { margin-right: 4px; }
.notification-badge, .count-badge {
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #ef343d;
  color: #fff;
  font-weight: 700;
}
.notification-badge { position: absolute; top: 0; right: -1px; width: 17px; height: 17px; border: 2px solid #fff; font-size: 11px; }
.header-separator { width: 1px; height: 17px; margin: 0 10px; background: var(--line); }
.company-profile { display: flex; align-items: center; gap: 14px; margin-left: 8px; }
.company-copy { display: flex; flex-direction: column; align-items: flex-end; }
.company-copy strong { font-size: 16px; font-weight: 700; }
.company-copy small { margin-top: 1px; color: var(--muted); font-size: 13.5px; }
.avatar { position: relative; display: block; width: 34px; height: 34px; overflow: hidden; border-radius: 50%; background: #edf0f5; }
.avatar img { position: absolute; top: -18px; left: -1481px; width: 1536px; height: 1024px; max-width: none; }

/* Who is signed in, and the way out. Filled in by session.js from /api/auth/me — the name in
   the corner is the person holding the cookie, never a name written into the page. */
.user-menu { position: relative; }
.user-menu .company-profile { border: 0; background: none; padding: 0; cursor: pointer; text-align: right; }
.user-initial {
  display: grid;
  place-items: center;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 15px;
  font-weight: 700;
}
.user-menu-list {
  position: absolute;
  z-index: 60;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  width: max-content;
  min-width: 190px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(29, 42, 70, .13);
}
.user-menu-email {
  margin: 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  padding: 10px 13px;
  font-size: 13px;
}
.user-menu-list button { border: 0; background: #fff; padding: 10px 13px; text-align: left; cursor: pointer; }
.user-menu-list button:hover { color: var(--blue); background: #f5f7fb; }

/* The account this page is about. Its options are only ever the caller's own accounts, and
   with one account there is nothing to open — the button then just names it. */
.account-label { display: flex; align-items: center; gap: 6px; max-width: 190px; }
.account-label > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-switch .select-btn:disabled { background: #fff; cursor: default; }
.account-switch .select-btn:disabled svg { visibility: hidden; }

.dropdown { position: relative; }
.select-btn {
  display: flex;
  min-width: 128px;
  height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  /* The button is one line tall. A label that wrapped would spill out of it rather than make
     it taller, so nothing in here wraps — the account switcher trims with an ellipsis
     instead, and the period button grows to fit. */
  white-space: nowrap;
  cursor: pointer;
}
.select-btn:hover, .icon-btn:hover { border-color: #cdd5e2; }
.select-btn svg { width: 14px; height: 14px; }
.select-menu {
  position: absolute;
  z-index: 60;
  top: calc(100% + 6px);
  left: 0;
  display: none;
  width: max-content;
  min-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(29, 42, 70, .13);
}
.select-menu.open { display: grid; }
.select-menu.align-right { right: 0; left: auto; }
.select-menu button { min-width: 128px; border: 0; background: #fff; padding: 9px 12px; text-align: left; cursor: pointer; }
.select-menu button:hover { color: var(--blue); background: #f5f7fb; }
.select-menu button[data-open-range] { border-top: 1px solid var(--line-soft); }

.range-popover {
  position: absolute;
  z-index: 61;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  gap: 8px;
  width: max-content;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(29, 42, 70, .13);
  padding: 12px;
}
.range-popover label { display: grid; gap: 4px; color: var(--muted); }
.range-popover input[type="date"] {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 0 8px;
  color: var(--ink);
  font: inherit;
}
.range-popover input[type="date"]:focus-visible { border-color: var(--blue); outline: none; }
.range-error { margin: 0; color: var(--red); }
.range-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 2px; }
.range-actions .secondary-btn, .range-actions .primary-btn { height: 32px; padding: 0 12px; }
.primary-btn {
  border: 1px solid var(--blue);
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
}
.primary-btn:hover { background: #1d55d6; }

/* The greeting line and the filter row share this bar, and the filter row must never be the
   one that gives. A flex item shrinks below its content by default, so the row was being
   squeezed a few pixels short of what its buttons wanted and the labels inside them wrapped
   to two lines — "ดาวน์โหลดรายงาน" and a custom date range are simply long. Wrapping the bar
   puts the controls on their own line when the room runs out, which is the honest answer;
   the sentence on the left is what gives up width first. */
.greeting-bar {
  display: flex;
  flex-wrap: wrap;
  min-height: 80px;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  margin: 0 20px;
  border: 1px solid #e5eaf1;
  border-radius: 12px;
  background: linear-gradient(108deg, #f7f9ff 0%, #fff 72%);
  padding: 12px 14px;
}
.greeting-bar > div:first-child { min-width: 0; flex: 1 1 240px; }
.greeting-bar strong { font-size: 16px; }
.greeting-bar p { margin: 5px 0 0; font-size: 15px; }
.data-through { color: var(--muted); font-size: 13px; }
.data-through[data-tone="warn"] { color: var(--orange); }
.panel-note { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.filter-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
/* Every control keeps the width its own label needs. Losing a line of text is worse than
   losing a line of layout, so the row wraps rather than compressing what is in it. */
.filter-actions > * { flex: none; }
.channel-filter { width: 148px; }
/* min-width, not width: the presets fit in 152px but a hand-picked range ("24 ส.ค. – 30 ส.ค.")
   does not, and a fixed width made the button wrap its own label. */
.period-filter { min-width: 152px; }
.compare-btn, .download-btn {
  height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.compare-btn { background: #eef1f6; }
.download-btn { display: flex; align-items: center; gap: 7px; margin-left: 18px; background: #101725; color: #fff; padding: 0 14px; }
.download-btn svg { width: 15px; height: 15px; }
.download-btn:hover { background: #1c2638; }

.dashboard { padding: 13px 20px 0; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.55fr);
  gap: 9px;
}

.kpi-card {
  display: flex;
  min-width: 0;
  height: 106px;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 19px 15px;
  box-shadow: var(--shadow);
}

.metric-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 9px;
}
.metric-icon svg { width: 20px; height: 20px; stroke-width: 2; }
.metric-icon.green { color: #64bd19; background: #eaf8df; }
.metric-icon.blue { color: #2765ed; background: #eaf0ff; }
.metric-icon.orange { color: #f27b16; background: #fff0e1; }
.metric-icon.purple { color: #913fe1; background: #f2e6ff; }
.metric-icon.cyan { color: #22b4cc; background: #e1f6fa; }
.kpi-content { min-width: 0; flex: 1; }
.kpi-label { color: #505a6d; font-size: 15px; white-space: nowrap; }
.kpi-value-row { display: flex; min-width: 0; align-items: baseline; justify-content: space-between; gap: 5px; margin-top: 2px; }
.kpi-value-row strong { font-size: 24.5px; line-height: 1.25; letter-spacing: -.4px; }
.kpi-content > small { color: #5b6578; font-size: 13.5px; white-space: nowrap; }
.trend { white-space: nowrap; font-style: normal; font-weight: 500; }
.trend.up { color: var(--green); }
.trend.down { color: var(--red); }
.kpi-value-row .trend { font-size: 15px; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 366px;
  gap: 11px;
  margin-top: 10px;
}
.primary-column { display: grid; min-width: 0; align-self: start; gap: 10px; }
.overview-row { display: grid; grid-template-columns: minmax(0, 1.46fr) minmax(335px, 1fr); gap: 10px; }

.panel, .channel-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; }
.panel h2, .channel-card h2 { margin: 0; font-size: 17.5px; }

.sales-panel, .channel-chart-panel { height: 254px; overflow: hidden; }
.sales-panel { padding: 13px 17px 11px; }
.channel-chart-panel { padding: 15px 17px; }
.chart-filter { width: 115px; height: 32px; }
.headline-value { display: flex; align-items: baseline; margin-top: 5px; }
.headline-value strong { font-size: 24.5px; line-height: 1; }
.headline-value > span:not(.trend) { margin-left: 5px; color: #6d778b; font-size: 13.5px; }
.headline-value .trend { margin-left: 22px; font-size: 15px; }
.headline-value small { margin-left: 10px; color: #7b8495; font-size: 12px; }
.line-chart-wrap { height: 158px; margin-top: 6px; }
.chart-wrap canvas { display: block; width: 100%; height: 100%; }

.donut-content { display: grid; grid-template-columns: 162px 1fr; align-items: center; gap: 10px; height: 194px; }
.channel-chart-panel .donut-content { transform: translateY(8px); }
.donut-wrap { position: relative; width: 160px; height: 160px; }
.donut-wrap canvas { display: block; width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center span { font-size: 15px; font-weight: 600; }
.donut-center strong { margin-top: 1px; font-size: 21.5px; line-height: 1.15; }
.donut-center small { font-size: 13.5px; font-weight: 600; }
.legend-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.legend-list li { display: grid; grid-template-columns: 9px 1fr auto; align-items: start; column-gap: 8px; font-size: 13.5px; }
.legend-list li > span:nth-child(2) { display: flex; flex-direction: column; }
.legend-list small { color: #858da0; font-size: 11px; }
.legend-list strong { font-size: 13.5px; }
.legend-dot { width: 7px; height: 7px; margin-top: 3px; border-radius: 50%; }
.legend-dot.facebook { background: #2e61ed; }
.legend-dot.google { background: #9876df; }
.legend-dot.direct { background: #ffb285; }
.legend-dot.organic { background: #8bc632; }

.channel-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.channel-card { height: 201px; padding: 16px 17px 12px; overflow: hidden; }
.channel-card header { display: flex; align-items: center; gap: 9px; }
.channel-card header > strong { font-size: 17.5px; }
.channel-logo { display: grid; width: 23px; height: 23px; flex: 0 0 23px; place-items: center; border-radius: 50%; font-weight: 700; }
.meta-logo { background: #2a67e9; color: #fff; font-family: Arial, sans-serif; font-size: 23px; }
.google-logo { color: #3775ee; }
.google-logo svg { width: 22px; height: 22px; fill: #f5c542; stroke: #3976e8; }
.web-logo { color: #3164c9; background: #eef3ff; }
.seo-logo { color: #4f5ee7; background: #eef0ff; }
.channel-logo svg { width: 17px; height: 17px; }
.status-pill { margin-left: auto; border-radius: 8px; background: #eaf8f1; color: #289364; padding: 3px 10px 2px; font-size: 12px; }
.status-pill.off  { background: #f0f2f6; color: #6b7386; }
.status-pill.warn { background: #fff3e5; color: #b9601a; }
.channel-metrics { display: grid; margin-top: 15px; }
.channel-metrics.three-col { grid-template-columns: 1.2fr .9fr .5fr; gap: 8px; }
.channel-metrics > span { display: flex; min-width: 0; flex-direction: column; }
.channel-metrics small, .site-row > span, .seo-headings { color: #737c90; font-size: 12px; }
.channel-metrics strong { margin-top: 4px; font-size: 18px; line-height: 1.2; white-space: nowrap; }
.channel-metrics em, .site-row em { color: #697488; font-size: 12px; font-style: normal; font-weight: 400; }
.blank-label { visibility: hidden; }
.channel-bottom { display: grid; grid-template-columns: 60px 1fr 50px; height: 60px; align-items: center; gap: 5px; }
.mini-label { color: #737c90; font-size: 12px; }
.sparkline { width: 100%; height: 42px; }
.channel-bottom .trend { justify-self: end; font-size: 13.5px; }
.secondary-btn { width: 100%; height: 34px; border: 1px solid #dee4ed; border-radius: 7px; background: linear-gradient(#fff, #f8fafc); font-weight: 500; cursor: pointer; }
.secondary-btn:hover { border-color: #aab7c9; background: #f8faff; }
a.secondary-btn   { display: grid; place-items: center; }
.wide-btn { margin-top: 25px; height: 36px; }
.site-row { display: flex; height: 36px; align-items: center; justify-content: space-between; }
.site-row:first-of-type { margin-top: 8px; }
.site-row strong { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.site-row strong small { font-size: 12px; }
.channel-card .site-row + .secondary-btn { margin-top: 9px; }
.seo-headings, .seo-values { display: grid; grid-template-columns: 1.05fr 1.1fr .52fr; gap: 7px; }
.seo-headings { margin-top: 14px; }
.seo-headings .trend, .seo-values .trend { justify-self: end; }
.seo-values { margin-top: 5px; align-items: center; }
.seo-values strong { font-size: 16px; }
.seo-values .trend { font-size: 12px; }
.seo-values + .site-row { margin-top: 6px; }

.bottom-overview { display: grid; grid-template-columns: minmax(0, 1.56fr) minmax(380px, 1fr); height: 288px; overflow: hidden; }
.daily-chart-section { min-width: 0; padding: 14px 17px 10px; }
.products-section { min-width: 0; border-left: 1px solid var(--line); padding: 14px 17px 10px; }
.bottom-title-row h2 { font-size: 17.5px; }
.bottom-title-row h2 span { color: #737d91; font-weight: 400; }
.chart-legend { display: flex; gap: 22px; margin: 13px 0 0 33px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.bar-key { width: 12px; height: 7px; border-radius: 2px; background: #5b8bf0; }
.dash-key { width: 15px; height: 0; border-top: 1px dashed #6d95e8; }
.bar-chart-wrap { height: 163px; margin-top: -3px; }

table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 13.5px; }
th { color: #737c8f; font-size: 11px; font-weight: 400; }
th, td { height: 25px; padding: 0 2px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td { font-weight: 500; }
td.trend { font-size: 12px; }

.panel-link { display: flex; height: 29px; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 5px; background: #fafbfe; color: #1f5ce3; font-weight: 600; cursor: pointer; }
.panel-link:hover { background: #f0f4ff; }
.panel-link svg { width: 13px; height: 13px; }
.products-section .panel-link { width: 100%; margin-top: 4px; }

.right-rail { display: grid; align-content: start; gap: 10px; }
.rail-heading { display: flex; min-height: 48px; align-items: center; border-bottom: 1px solid var(--line); padding: 0 17px; }
.rail-heading h2 { display: flex; align-items: center; gap: 8px; }
.count-badge { width: 17px; height: 17px; font-size: 12px; }

.alerts-panel { height: 340px; overflow: hidden; }
.alert-list { padding: 0 17px; }
.alert-item { position: relative; height: 85px; border-bottom: 1px solid var(--line-soft); padding: 12px 0 8px 20px; }
.alert-top { display: flex; align-items: center; justify-content: space-between; }
.alert-top strong { display: flex; align-items: center; gap: 10px; color: var(--red); font-size: 15px; }
.alert-top time { color: #718096; font-size: 12px; }
.alert-dot { position: absolute; left: 0; top: 17px; width: 9px; height: 9px; border: 3px solid currentColor; border-radius: 50%; }
.alert-dot.red { color: var(--red); }
.alert-dot.orange { color: var(--orange); }
.alert-item:nth-child(2) .alert-top strong { color: var(--red); }
.alert-item p { margin: 8px 0 0; font-size: 13px; }
.alert-item button { position: absolute; right: 0; bottom: 7px; height: 24px; border: 0; border-radius: 7px; background: #fff0f0; color: var(--red); padding: 0 12px; cursor: pointer; }
.alerts-panel > .panel-link { width: calc(100% - 34px); margin: 0 17px; }

.recommendations-panel { height: 150px; overflow: hidden; }
.recommendations-panel .rail-heading { min-height: 38px; }
.recommendation-list { display: grid; gap: 7px; margin: 9px 17px 7px; padding: 0; list-style: none; }
.recommendation-list li { display: flex; align-items: flex-start; gap: 4px; font-size: 13px; white-space: nowrap; }
.recommendation-list svg { width: 12px; height: 12px; flex: 0 0 12px; color: var(--green); stroke-width: 3; }
.recommendations-panel .panel-link { width: calc(100% - 34px); height: 27px; margin: 0 17px; border-top: 1px solid var(--line-soft); background: #fff; }

.activity-panel { height: 218px; overflow: hidden; }
.activity-panel .rail-heading { min-height: 38px; }
.activity-list { display: grid; gap: 10px; margin: 11px 17px 8px; padding: 0; list-style: none; }
.activity-list li { display: grid; grid-template-columns: 12px 37px 1fr; align-items: center; gap: 7px; font-size: 13px; }
.activity-icon { width: 11px; height: 11px; }
.activity-icon.red { color: var(--red); }
.activity-icon.orange { color: var(--orange); }
.activity-icon.green { color: var(--green); }
.activity-list time { color: #748097; }
.activity-list em { color: var(--red); font-style: normal; }
.activity-panel .panel-link { width: calc(100% - 34px); height: 27px; margin: 0 17px; border-top: 1px solid var(--line-soft); background: #fff; }

.toast {
  position: fixed;
  z-index: 100;
  right: 24px;
  bottom: 24px;
  display: flex;
  min-width: 230px;
  align-items: center;
  gap: 10px;
  border: 1px solid #dbe5dc;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 35px rgba(20, 36, 63, .16);
  padding: 13px 16px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast svg { width: 17px; color: var(--green); }
.sidebar-scrim { display: none; }

/* ---------- "why the number moved" ----------
   Sentences, not figures in boxes. The card next to it counts alert rules; this one explains
   the arithmetic behind the KPI row, so it reads as prose and the first line is the one that
   outranks the rest (server/narrator.py decides that order, not the CSS). */
.analysis-panel .rail-heading { justify-content: space-between; }
.analysis-lines { margin: 0; padding: 12px 17px 4px; list-style: none; display: grid; gap: 9px; }
.analysis-lines li { position: relative; padding-left: 14px; color: #3c4557; font-size: 13px; line-height: 1.6; }
.analysis-lines li::before { position: absolute; left: 0; top: 0; color: #b6becd; content: "—"; }
.analysis-lines li:first-child { color: var(--ink); font-weight: 500; }
.analysis-source { margin: 0; padding: 0 17px 13px; color: var(--muted); font-size: 11px; }
.analysis-panel .plain-icon { width: 28px; height: 28px; color: var(--muted); }
.analysis-panel .plain-icon svg { width: 15px; height: 15px; }

/* ---------- Panel states ----------
   Every panel that shows fetched numbers carries data-state. While it loads, a skeleton
   stands in; when the source has nothing to say, a sentence explains why. The numbers
   themselves are hidden in both cases, so a stale or empty panel can never read as zero. */
.panel-state { display: none; min-height: 60px; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 12px 17px; text-align: center; }
.panel-state .state-text { margin: 0; max-width: 32ch; color: var(--muted); font-size: 13px; line-height: 1.5; }
[data-state="loading"] > .panel-state,
[data-state="empty"] > .panel-state,
[data-state="error"] > .panel-state { display: flex; }
[data-state="loading"] > [data-panel-body],
[data-state="empty"] > [data-panel-body],
[data-state="error"] > [data-panel-body] { display: none !important; }

.skeleton { display: block; border-radius: 6px; background: linear-gradient(90deg, #eef1f5 25%, #f6f8fb 50%, #eef1f5 75%); background-size: 200% 100%; color: transparent !important; animation: skeleton-shimmer 1.2s linear infinite; }
.skel-value { width: 74px; height: 17px; }
.skel-note { width: 96px; height: 9px; }
.skel-chart { width: 100%; height: 120px; }
.skel-lines { width: 100%; height: 74px; }
@keyframes skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- Sidebar status card ---------- */
.status-card {
  position: absolute;
  right: 8px;
  bottom: -2px;
  left: 8px;
  border: 1px solid #dfe4eb;
  border-radius: 14px;
  padding: 16px 16px 14px;
  background: #fff;
  box-shadow: var(--shadow);
}
.status-card h2 { margin: 0; font-size: 16px; font-weight: 600; text-align: center; }
.status-counts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.status-count { display: flex; flex-direction: column; align-items: center; border-radius: 10px; padding: 9px 4px; }
.status-count strong { font-size: 27px; line-height: 1; }
.status-count span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.status-count.red { background: #fff2f2; } .status-count.red strong { color: var(--red); }
.status-count.orange { background: #fff5eb; } .status-count.orange strong { color: var(--orange); }
.status-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; text-align: center; }
.status-note[data-tone="ok"] { color: var(--green); }
.status-card .wide-btn { margin-top: 12px; height: 30px; }

/* ---------- Banner ---------- */
.page-banner { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; border: 1px solid #f3ddc0; border-radius: 10px; background: #fffaf2; padding: 10px 14px; color: #7a4a10; font-size: 14px; }
.page-banner svg { width: 15px; height: 15px; flex: 0 0 15px; color: var(--orange); }
.page-banner-action { margin-left: auto; border-radius: 7px; background: #fff; border: 1px solid #e7cfae; padding: 4px 12px; font-weight: 600; }

/* ---------- KPI cards ----------
   Labels here are written by the data, not by the template: an account selling in chat says
   "ต้นทุนต่อการทักแชท", one running lead forms says something else. They used to wrap onto a
   second line, which dropped two of the five values a line below the other three and broke
   the row. One line each now, at a size where the longest label these accounts produce still
   fits; anything longer ends in an ellipsis and keeps the whole text in its tooltip, which
   overview.js sets. The card is a little tighter all round to pay for the extra width. */
#overview .kpi-card { height: auto; min-height: 116px; gap: 10px; padding: 16px 13px; }
#overview .metric-icon { width: 34px; height: 34px; flex-basis: 34px; }
#overview .metric-icon svg { width: 18px; height: 18px; }
#overview .kpi-label { display: block; overflow: hidden; font-size: 13px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
#overview .kpi-value-row .trend { font-size: 13.5px; }
/* A note with nowhere to go used to slide under the next card, where it read as a word cut
   in half. It says so with an ellipsis instead, and the tooltip holds the rest. */
#overview .kpi-content > small { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; }
#overview .kpi-cols small { font-size: 11.5px; }
#overview .kpi-cols strong { font-size: 18px; }

.kpi-cols { display: grid; grid-template-columns: repeat(3, minmax(0, auto)); justify-content: space-between; gap: 10px; margin-top: 4px; }
.kpi-cols > div { display: flex; min-width: 0; flex-direction: column; }
.kpi-cols small { color: #737c90; font-size: 12px; white-space: nowrap; }
.kpi-cols strong { margin-top: 2px; font-size: 19px; line-height: 1.2; white-space: nowrap; }
.kpi-card-wide .kpi-content > small { display: block; margin-top: 5px; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

/* Five across only while the cards are wider than the names they carry, which takes about a
   1,500px window. Below that the row was cutting labels and notes off mid-number; three cards
   over two rows say the same things whole, with the ROAS card spanning the space the missing
   fifth one leaves. Under 681px the two- and one-column rules further down take over. */
@media (min-width: 681px) and (max-width: 1500px) {
  #overview .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #overview .kpi-card-wide { grid-column: span 2; }
  /* Spanning two columns leaves that card far wider than its three small figures need; keep
     them together rather than stretched to both edges. */
  #overview .kpi-card-wide .kpi-cols { max-width: 400px; }
}

/* ---------- Overview panels ---------- */
/* The two panels in this row were locked to a fixed height with the overflow hidden, so
   the Meta panel — one row taller than the box — had its last line pressed against the
   card edge and trimmed. A floor instead of a ceiling: the grid still holds the two to
   the same height, and a panel that has something more to say can say it. */
#overview .cost-panel, #overview .meta-panel { height: auto; min-height: 254px; }
.cost-panel .panel-state { min-height: 140px; }
.meta-panel { display: flex; flex-direction: column; padding: 15px 17px 13px; }
.meta-panel .panel-header { align-items: center; }
.meta-panel h2 { display: flex; align-items: center; gap: 9px; }
.meta-rows { display: flex; flex: 1; flex-direction: column; justify-content: center; }
.meta-rows .site-row { height: 32px; }
.meta-rows .panel-link { margin-top: 10px; }
.daily-chart-section, .products-section { display: flex; flex-direction: column; }
.daily-chart-section > [data-panel-body] { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.products-section > [data-panel-body] { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.products-section table { flex: 1; }

/* ---------- Campaign league table ---------- */
.campaign-ranking { display: flex; flex-direction: column; padding: 14px 17px 12px; }
/* The title holds its line and the note is what gives way — a heading broken over two lines
   to make room for its own footnote is the wrong way round. The note keeps the whole
   explanation in its tooltip. */
.ranking-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.ranking-head h2 { flex: 0 0 auto; font-size: 17.5px; white-space: nowrap; }
.ranking-head small { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.ranking-body { margin-top: 12px; }
.ranking-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
/* One row per campaign, the cost right-aligned so the column of figures can be read down
   the page — that is the whole point of a table of places. */
.ranking-list li { display: grid; grid-template-columns: 18px 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; border-left: 3px solid transparent; border-radius: 8px; padding: 7px 10px 7px 8px; background: var(--surface-soft); }
/* Green under the ceiling, red over it, read down the page in one glance. The band answers
   the only question the figures are there for: is this result costing more than it is worth? */
.ranking-list li[data-tone="good"] { border-left-color: var(--green); background: #f1faf3; }
.ranking-list li[data-tone="bad"] { border-left-color: var(--red); background: #fff4f4; }
.rank-no { display: grid; width: 18px; height: 18px; place-items: center; border-radius: 50%; background: #fff; font-size: 12px; font-weight: 700; }
.ranking-list li[data-tone="good"] .rank-no { color: var(--green); }
.ranking-list li[data-tone="bad"] .rank-no { color: var(--red); }
.ranking-list strong { display: block; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.ranking-list small { display: block; margin-top: 1px; color: #5b6578; font-size: 12px; }
.ranking-empty { color: var(--muted); font-size: 13px; background: transparent !important; }
/* The creative, so the row is a campaign the owner recognises rather than a name they have
   to remember. Videos wear a play mark: Meta hands back one frame either way. */
.rank-thumb { position: relative; display: block; width: 34px; height: 34px; }
.rank-thumb img { display: block; width: 34px; height: 34px; border-radius: 6px; background: #e9edf4; object-fit: cover; }
.rank-thumb[data-empty] { border-radius: 6px; background: repeating-linear-gradient(135deg, #eef1f6 0 4px, #e6eaf2 4px 8px); }
.rank-thumb[data-format="video"]::after { position: absolute; right: 3px; bottom: 3px; width: 0; height: 0; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 7px solid #fff; content: ""; filter: drop-shadow(0 0 1.5px rgba(12, 18, 28, .75)); }
/* When the campaign actually ran, on its own line under the verdict. Quieter than the line
   above it: it is background, not the reason the row is where it is. */
.rank-ran { color: #7b8495 !important; font-size: 11.5px !important; }
/* Two figures on the right, side by side: what it spent, and what that bought. Same size on
   purpose — a sum of money set in 11.5px grey under the name read as a footnote, and the spend
   is what says whether a cheap-looking cost per result means anything. Narrow screens stack
   them instead of squeezing the campaign's name out of the row. */
.rank-figures { display: flex; align-items: baseline; justify-content: flex-end; gap: 16px; }
.rank-spend, .rank-cost { text-align: right; white-space: nowrap; }
.rank-spend strong, .rank-cost strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.rank-spend small, .rank-cost small { color: #737c90; }
.rank-spend strong { color: #3f4859; }
@media (max-width: 900px) {
  .rank-figures { flex-direction: column; align-items: flex-end; gap: 3px; }
}
.ranking-fix { margin: 10px 0 0; color: #5b6578; font-size: 12px; line-height: 1.5; }

/* ---------- Right rail with real, variable-length content ---------- */
.alerts-panel { display: flex; flex-direction: column; }
.alerts-panel > [data-panel-body] { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.alert-list { flex: 1; min-height: 0; overflow-y: auto; }
.alert-item { height: auto; min-height: 62px; padding-bottom: 12px; }
.alert-item[data-severity="orange"] .alert-top strong { color: var(--orange); }
.alert-item p { white-space: normal; }
.recommendations-panel { height: auto; min-height: 150px; }
.recommendation-list li { white-space: normal; }
.activity-panel { height: auto; min-height: 218px; }
.activity-list li { align-items: start; }
.activity-list span { overflow-wrap: anywhere; }

@media (max-width: 1320px) {
  .content-grid { grid-template-columns: minmax(0, 1fr) 330px; }
  .overview-row { grid-template-columns: minmax(0, 1.35fr) 325px; }
  .channel-card { padding-inline: 12px; }
  .download-btn { margin-left: 4px; }
}

@media (max-width: 1180px) {
  .content-grid { grid-template-columns: 1fr; }
  .right-rail { grid-template-columns: repeat(3, 1fr); }
  .alerts-panel, .recommendations-panel, .activity-panel { height: auto; min-height: 300px; }
  .recommendations-panel .rail-heading, .activity-panel .rail-heading { min-height: 48px; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .kpi-card { height: 116px; }
  .topbar-right .company-copy { display: none; }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 210px; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; z-index: 25; inset: 0; display: block; background: rgba(14, 19, 31, .32); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .status-card { display: none; }
  .workspace { margin-left: 0; }
  .mobile-menu { display: grid; }
  .topbar-left h1 { font-size: 20.5px; }
  .topbar-left time, .date-divider, .calendar-btn { display: none; }
  .overview-row { grid-template-columns: 1fr; }
  .sales-panel, .channel-chart-panel { height: 270px; }
  #overview .cost-panel, #overview .meta-panel { min-height: 270px; }
  .channel-chart-panel .donut-content { justify-content: center; grid-template-columns: 185px 220px; }
  .channel-cards { grid-template-columns: repeat(2, 1fr); }
  .bottom-overview { grid-template-columns: 1fr; height: auto; }
  .daily-chart-section { height: 260px; }
  .products-section { border-top: 1px solid var(--line); border-left: 0; }
  .right-rail { grid-template-columns: 1fr; }
  .alerts-panel { height: 340px; }
  .recommendations-panel { height: 170px; }
  .activity-panel { height: 230px; }
}

@media (max-width: 680px) {
  .topbar { height: 60px; padding-inline: 12px; }
  .topbar-left h1 { margin-right: 10px; }
  .compact-dropdown, .topbar-right .header-separator, .topbar-right .plain-icon:not(.notification-btn) { display: none; }
  /* The account switch is not one of the dropdowns that fold away here: it is the only way to
     move between accounts, and hiding it would strand the owner on whichever one a phone
     happened to open. It gives up its width instead. */
  .account-switch .select-btn { min-width: 0; gap: 6px; padding: 0 8px; }
  .account-label { max-width: 104px; }
  .account-label .channel-logo { display: none; }
  .greeting-bar { align-items: flex-start; margin-inline: 12px; padding: 12px; }
  .greeting-bar > div:first-child { min-width: 150px; }
  .filter-actions { max-width: calc(100vw - 195px); overflow-x: auto; padding-bottom: 2px; }
  .filter-actions .compare-btn, .filter-actions .period-filter, .download-btn span { display: none; }
  .download-btn { width: 35px; justify-content: center; padding: 0; }
  .channel-filter { width: 120px; }
  .dashboard { padding-inline: 12px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-card { height: 105px; padding: 14px 12px; }
  .kpi-value-row strong { font-size: 23px; }
  /* On a phone the card is narrower than the metric's name and vertical space is the cheap
     one, so the label and the note wrap here instead of ending in an ellipsis. */
  #overview .kpi-label { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.3; white-space: normal; }
  #overview .kpi-content > small { line-height: 1.35; white-space: normal; }
  /* The ROAS card carries three figures side by side; in half a phone's width their names
     ran into each other, so it takes the whole width here. */
  #overview .kpi-card-wide { grid-column: span 2; }
  .metric-icon { width: 32px; height: 32px; flex-basis: 32px; }
  .overview-row { display: block; }
  .channel-chart-panel { margin-top: 10px; }
  .channel-cards { grid-template-columns: 1fr; }
  .channel-card { height: 190px; }
  .channel-chart-panel .donut-content { grid-template-columns: 145px 1fr; }
  .donut-wrap { width: 140px; height: 140px; }
}

@media (max-width: 420px) {
  .topbar-left h1 { font-size: 18px; }
  .company-profile { margin-left: 0; }
  .greeting-bar > div:first-child p { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-card { height: 94px; }
  .channel-chart-panel { height: auto; min-height: 390px; }
  .channel-chart-panel .donut-content { grid-template-columns: 1fr; height: auto; justify-items: center; }
  .legend-list { width: 100%; }
  .products-section { overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
