/* LINE OA Dashboard — สีกราฟใช้พาเลตต์ที่ผ่าน validator แล้ว (light/dark คนละชุด ไม่ใช่พลิกอัตโนมัติ) */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --good: #006300;
  --bad: #d03b3b;
  --brand: #06c755;            /* LINE green — ใช้เฉพาะ UI ไม่ใช่สีข้อมูล */


  /* สลอตสีข้อมูล 1-8 (พาเลตต์ที่ผ่าน validator) — ไล่ตามลำดับซีรีส์ในกราฟ */
  --slot-1: #2a78d6;
  --slot-2: #eb6834;
  --slot-3: #1baf7a;
  --slot-4: #eda100;
  --slot-5: #e87ba4;
  --slot-6: #008300;
  --slot-7: #4a3aa7;
  --slot-8: #e34948;

  /* สีข้อมูล (คงไว้เพื่อความเข้ากันได้ย้อนหลัง) */
  --s-followers: #2a78d6;
  --s-targetreach: #1baf7a;
  --s-blocks: #e34948;
  --s-broadcast: #4a3aa7;
  --s-auto: #eb6834;
  --s-greeting: #1baf7a;
  --s-chatactive: #eda100;
  --s-chatrecv: #e87ba4;
  --s-primary: #2a78d6;

  --r: 12px;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 8px 24px -18px rgba(11, 11, 11, .18);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --good: #0ca30c;
    --bad: #e66767;

    --slot-1: #3987e5;
    --slot-2: #d95926;
    --slot-3: #199e70;
    --slot-4: #c98500;
    --slot-5: #d55181;
    --slot-6: #008300;
    --slot-7: #9085e9;
    --slot-8: #e66767;

    --s-followers: #3987e5;
    --s-targetreach: #199e70;
    --s-blocks: #e66767;
    --s-broadcast: #9085e9;
    --s-auto: #d95926;
    --s-greeting: #199e70;
    --s-chatactive: #c98500;
    --s-chatrecv: #d55181;
    --s-primary: #3987e5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -18px rgba(0, 0, 0, .9);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --good: #0ca30c;
  --bad: #e66767;

  --slot-1: #3987e5;
  --slot-2: #d95926;
  --slot-3: #199e70;
  --slot-4: #c98500;
  --slot-5: #d55181;
  --slot-6: #008300;
  --slot-7: #9085e9;
  --slot-8: #e66767;

  --s-followers: #3987e5;
  --s-targetreach: #199e70;
  --s-blocks: #e66767;
  --s-broadcast: #9085e9;
  --s-auto: #d95926;
  --s-greeting: #199e70;
  --s-chatactive: #c98500;
  --s-chatrecv: #d55181;
  --s-primary: #3987e5;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -18px rgba(0, 0, 0, .9);
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--plane);
  color: var(--text-primary);
  font-family: Prompt, system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--s-primary); }
.hidden { display: none !important; }

/* ---------- โครงหน้า ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -.01em; }
.brand .dot {
  width: 24px; height: 24px; border-radius: 7px; background: var(--brand);
  display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700; flex: none;
}
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--text-muted); line-height: 1.2; }
.topbar .spacer { flex: 1; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 18px 20px 64px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button {
  background: transparent; border: 1px solid transparent; border-radius: 999px;
  padding: 7px 15px; cursor: pointer; color: var(--text-secondary); font-weight: 500;
}
.tabs button:hover { background: var(--surface-1); }
.tabs button[aria-selected="true"] {
  background: var(--surface-1); border-color: var(--border);
  color: var(--text-primary); box-shadow: var(--shadow);
}

/* แถวฟิลเตอร์ — แถวเดียว อยู่เหนือทุกอย่างที่มันคุม */
.filters {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 16px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
}
.filters .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 3px; }
.filters label { font-size: 12px; color: var(--text-muted); }

.btn {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 13px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--brand); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

select, input[type="date"], input[type="text"], input[type="number"], input[type="password"], textarea {
  background: var(--plane); border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; min-width: 0;
}
select:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--s-primary); outline-offset: 1px;
}

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button {
  background: transparent; border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; font-size: 12.5px; color: var(--text-secondary);
}
.chips button:hover { background: var(--plane); }
.chips button[aria-pressed="true"] {
  background: var(--text-primary); color: var(--surface-1);
  border-color: transparent; font-weight: 500;
}

/* ---------- การ์ด / ตัวเลข ---------- */

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.card-head .grow { flex: 1; min-width: 0; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; overflow-wrap: anywhere; }
.card-head .sub { margin: 1px 0 0; font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; }

.hero { display: flex; align-items: flex-end; gap: 24px; flex-wrap: wrap; }
.hero .label { font-size: 13px; color: var(--text-secondary); }
.hero .figure { font-size: 52px; font-weight: 600; line-height: 1.05; letter-spacing: -.025em; }
.hero .meta { font-size: 12.5px; color: var(--text-muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r);
  padding: 13px 15px; box-shadow: var(--shadow);
}
.tile .label { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.tile .label .key { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; }
.tile .value .unit { font-size: 14px; font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.tile .delta { font-size: 12px; margin-top: 2px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.tile .delta .up { color: var(--good); font-weight: 500; }
.tile .delta .down { color: var(--bad); font-weight: 500; }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 14px; }
.stack { display: grid; gap: 14px; }

/* ---------- กราฟ ---------- */

.chart-wrap { position: relative; }
/* clip ไว้เสมอ — ถ้าเรขาคณิตของกราฟผิดพลาด จะได้ไม่วาดทะลุไปทับหัวการ์ด */
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: hidden; }
.chart-wrap.loading { opacity: .45; transition: opacity .15s; }   /* โหลดใหม่ = คงภาพเดิมไว้ ไม่ flash */

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 10px; }
.legend .item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend .swatch.line { height: 3px; width: 16px; border-radius: 2px; }

.tip {
  position: absolute; z-index: 12; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 6px 22px -8px rgba(0, 0, 0, .35);
  padding: 8px 10px; min-width: 158px; font-size: 12px;
  transform: translate(-50%, -100%);
}
.tip .when { color: var(--text-muted); margin-bottom: 5px; font-size: 11.5px; }
.tip .row { display: flex; align-items: center; gap: 7px; margin-top: 3px; }
.tip .row .key { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.tip .row .name { color: var(--text-secondary); flex: 1; white-space: nowrap; }
.tip .row .val { font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { padding: 34px 16px; text-align: center; color: var(--text-muted); }

/* ---------- ตาราง ---------- */

.table-scroll { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td {
  padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid);
}
table.data th:first-child, table.data td:first-child {
  text-align: left; position: sticky; left: 0; background: var(--surface-1);
}
table.data thead th {
  color: var(--text-secondary); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--axis);
}
table.data td { font-variant-numeric: tabular-nums; }
table.data tbody tr:hover td { background: var(--plane); }
table.data tfoot td { font-weight: 600; border-top: 1px solid var(--axis); }

/* ---------- นำเข้าข้อมูล ---------- */

.drop {
  border: 1.5px dashed var(--axis); border-radius: var(--r);
  padding: 30px 20px; text-align: center; color: var(--text-secondary); cursor: pointer;
  background: var(--plane);
}
.drop.over { border-color: var(--brand); background: var(--surface-1); }
.drop strong { color: var(--text-primary); }

.map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; align-items: center; }
.map-grid .col-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-grid .col-name em { color: var(--text-muted); font-style: normal; font-size: 11.5px; }

.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; }
.entry-grid label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 3px; }
.entry-grid input { width: 100%; }

.note { font-size: 12.5px; color: var(--text-muted); }
.warn { font-size: 12.5px; color: var(--bad); }
.ok { font-size: 12.5px; color: var(--good); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text-primary); color: var(--surface-1);
  padding: 10px 16px; border-radius: 999px; z-index: 90; font-size: 13px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5);
}

/* ---------- หน้าล็อกอิน ---------- */

#login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
#login .card { width: min(380px, 100%); }
#login h1 { margin: 0 0 4px; font-size: 19px; }

@media (max-width: 640px) {
  .topbar { padding: 9px 12px; gap: 8px; }
  .brand { font-size: 13px; min-width: 0; }
  .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand small { display: none; }          /* จอแคบ: เหลือแค่ชื่อ ไม่ให้หัวข้อตกบรรทัด */
  .wrap { padding: 14px 12px 56px; }
  .hero .figure { font-size: 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .map-grid { grid-template-columns: 1fr; }
}

/* ---------- ป้ายแพลตฟอร์ม (สีแบรนด์ ใช้กับ UI เท่านั้น ห้ามใช้เป็นสีข้อมูล) ---------- */

.pf { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pf .mark { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.pf-line      { background: #06c755; }
.pf-facebook  { background: #1877f2; }
.pf-instagram { background: #d62976; }
.pf-tiktok    { background: #25f4ee; }
.pf-youtube   { background: #ff0033; }
.pf-other     { background: var(--text-muted); }

.group-empty { padding: 22px 8px; text-align: center; color: var(--text-muted); font-size: 12.5px; }

/* ---------- แนววางแดชบอร์ด ---------- */
/* แนวนอน = ค่าเริ่มต้น (การ์ด 2 คอลัมน์ กว้าง 1240) เหมาะกับสไลด์ 16:9
   แนวตั้ง = คอลัมน์เดียว กว้างเท่ากระดาษ A4 แนวตั้ง เหมาะกับรายงานที่ปรินต์ */

body[data-layout="tall"] .wrap { max-width: 860px; }
body[data-layout="tall"] .grid2 { grid-template-columns: 1fr; }
body[data-layout="tall"] .kpis { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
body[data-layout="tall"] .hero .figure { font-size: 46px; }

/* ---------- หัวกระดาษของไฟล์ที่ส่งออก ---------- */

.print-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding: 0 2px 14px; margin-bottom: 4px; border-bottom: 1px solid var(--border);
}
.print-head .ph-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.print-head .ph-brand .dot {
  width: 22px; height: 22px; border-radius: 6px; background: var(--brand);
  display: grid; place-items: center; color: #fff; font-size: 10px; font-weight: 700;
}
.print-head .ph-title { font-weight: 600; font-size: 15px; }
.print-head .ph-meta { color: var(--text-muted); font-size: 12px; margin-left: auto; }

/* ตอนกำลังถ่ายภาพ/พิมพ์ ให้ซ่อนส่วนควบคุมทั้งหมด เหลือเฉพาะเนื้อหา */
body.exporting .topbar,
body.exporting .filters,
body.exporting .tabs,
body.exporting .btn,
body.exporting #kpiNote { display: none !important; }
body.exporting .print-head { display: flex !important; }
body.exporting .wrap { padding-top: 14px; }
body.exporting .card { box-shadow: none; break-inside: avoid; page-break-inside: avoid; }
body.exporting .table-scroll { overflow: visible; }

@media print {
  .topbar, .filters, .tabs, .btn, #kpiNote { display: none !important; }
  .print-head { display: flex !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; page-break-inside: avoid; border-color: #d8d7d1; }
  .table-scroll { overflow: visible; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  body[data-layout="tall"] .kpis { grid-template-columns: repeat(3, 1fr); }
}
