/* ===========================================================
   GUPACK — Realtime Packing Dashboard
   style.css — responsive (TV 1080p → desktop → tablet → mobile)
   =========================================================== */

:root {
  --bg:        #eef2f9;
  --card:      #ffffff;
  --ink:       #1f2a44;
  --ink-soft:  #5b6b8c;
  --muted:     #93a0bd;
  --line:      #e7ecf5;

  --blue:      #3b6ef0;
  --blue-d:    #2f55c8;
  --green:     #18b26b;
  --green-bg:  #e6f7ef;
  --orange:    #f59e2c;
  --orange-bg: #fdf1df;
  --red:       #ef4d5a;
  --red-bg:    #fdeaec;

  --radius:    20px;
  --radius-sm: 14px;
  --shadow:    0 10px 30px rgba(40,68,128,.08);
  --shadow-sm: 0 4px 14px rgba(40,68,128,.06);

  --gap: clamp(12px, 1.4vw, 20px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

b { font-weight: 700; }
.muted  { color: var(--muted); }
.small  { font-size: .78em; }

.dash {
  max-width: 1640px;
  margin: 0 auto;
  padding: clamp(12px, 1.6vw, 26px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* โครงหลัก: 2 คอลัมน์เต็มความสูง (ซ้าย = header+kpi+welcome, ขวา = rank+feed) */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: var(--gap);
  align-items: stretch;
}
.main-col {
  display: flex; flex-direction: column; gap: var(--gap); min-width: 0;
}

/* ───────── panels ───────── */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel__head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 16px 20px 0;
}
.panel__head h3 { margin: 0; font-size: clamp(15px, 1.15vw, 19px); font-weight: 800; }

/* ═════════ HEADER ═════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(12px, 1.2vw, 18px) clamp(16px, 1.6vw, 26px);
}
.topbar__brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.logo-box {
  flex: none;
  width: 54px; height: 54px;
  border-radius: 16px;
  background: linear-gradient(135deg, #4f7bf5, #6a5af9);
  display: grid; place-items: center;
  box-shadow: 0 8px 18px rgba(79,123,245,.35);
}
.topbar__title h1 {
  margin: 0;
  font-size: clamp(18px, 1.7vw, 28px);
  font-weight: 800;
  letter-spacing: -.01em;
  line-height: 1.15;
}
.topbar__sub {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 5px;
  font-size: clamp(12px, .95vw, 14px);
  color: var(--ink-soft);
}
.topbar__meta b { font-variant-numeric: tabular-nums; }
.live {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--green); font-weight: 800; letter-spacing: .04em;
}
.live__dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(24,178,107,.6);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(24,178,107,.55); }
  70%  { box-shadow: 0 0 0 10px rgba(24,178,107,0); }
  100% { box-shadow: 0 0 0 0 rgba(24,178,107,0); }
}
.topbar__logo { display: flex; align-items: center; gap: 9px; flex: none; }
.gupack-mark {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #fb7a3c, #f0414e);
  color: #fff; font-weight: 900; font-size: 20px;
  font-family: "Inter", sans-serif;
  display: grid; place-items: center;
}
.gupack-name { font-family: "Inter", sans-serif; font-weight: 800; font-size: 24px; color: #2a3556; }

/* ═════════ KPI ═════════ */
.kpis {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 1.6vw, 26px);
}
.kpi-row {
  display: flex; align-items: stretch; gap: clamp(8px, 1vw, 16px);
}
.op {
  flex: none; align-self: center;
  font-size: clamp(20px, 2.2vw, 34px); font-weight: 800; color: var(--muted);
}
.kpi {
  flex: 1 1 0; min-width: 0;
  display: flex; gap: 14px; align-items: flex-start;
  padding: clamp(14px, 1.3vw, 20px);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fbfcfe;
}
.kpi--total { background: linear-gradient(180deg,#f4f7ff,#eef3ff); border-color:#dde7fb; }
.kpi__icon {
  flex: none; width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; font-size: 26px;
}
.kpi--total .kpi__icon { background: #e3ecff; }
.kpi--ok    .kpi__icon { background: var(--green-bg); }
.kpi--warn  .kpi__icon { background: var(--orange-bg); }
.kpi--rest  .kpi__icon { background: var(--red-bg); }
.kpi__body { min-width: 0; }
.kpi__label { font-size: clamp(13px,1vw,15px); font-weight: 700; color: var(--ink-soft); }
.kpi__num { display: flex; align-items: baseline; gap: 7px; margin: 2px 0; }
.kpi__num b {
  font-family: "Inter", sans-serif; font-weight: 900;
  font-size: clamp(30px, 3.4vw, 52px); line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.kpi__num i { font-style: normal; font-size: clamp(12px,.95vw,14px); color: var(--muted); }
.kpi--total .kpi__num b { color: var(--blue); }
.kpi--ok    .kpi__num b { color: var(--green); }
.kpi--warn  .kpi__num b { color: var(--orange); }
.kpi--rest  .kpi__num b { color: var(--red); }
.kpi__foot { font-size: clamp(11px,.85vw,13px); color: var(--muted); }
.kpi--ok   .kpi__foot b { color: var(--green); }
.kpi--warn .kpi__foot b { color: var(--orange); }
.kpi--rest .kpi__foot b { color: var(--red); }

/* progress bar */
.progress {
  display: flex; gap: 4px; height: 12px; margin-top: 22px;
  border-radius: 99px; overflow: hidden; background: #eef1f7;
}
.progress__seg { transition: width .6s cubic-bezier(.4,0,.2,1); min-width: 0; }
.progress__seg--ok   { background: var(--green);  border-radius: 99px; }
.progress__seg--warn { background: var(--orange); border-radius: 99px; }
.progress__seg--rest { background: var(--red);    border-radius: 99px; }
.progress__labels {
  display: flex; justify-content: space-around; margin-top: 8px;
  font-weight: 800; font-size: clamp(12px,1vw,15px);
}
.tag--ok { color: var(--green); }
.tag--warn { color: var(--orange); }
.tag--rest { color: var(--red); }
.formula {
  text-align: center; margin: 14px 0 0;
  color: var(--ink-soft); font-size: clamp(12px,1vw,15px); line-height: 1.7;
}
.formula__hl { color: var(--red); }

/* ═════════ BREAK CARDS — เวลาพักคงเหลือ ═════════ */
.breaks__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
}
.emp {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.emp--working   { border-left-color: var(--green);  background: linear-gradient(180deg,#f4fbf7,#fff); }
.emp--break     { border-left-color: var(--orange); background: linear-gradient(180deg,#fef9f0,#fff); }
.emp--exhausted { border-left-color: var(--red);    background: linear-gradient(180deg,#fdf2f3,#fff); }
.emp--off       { border-left-color: var(--muted); }

.emp__head { display: flex; align-items: center; gap: 10px; }
.emp__avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px;
}
.emp__id { flex: 1 1 auto; min-width: 0; }
.emp__name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emp__role { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emp__badge {
  flex: none; font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 99px;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.emp__badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.emp__badge--working   { color: var(--green);  background: var(--green-bg); }
.emp__badge--break     { color: var(--orange); background: var(--orange-bg); }
.emp__badge--exhausted { color: var(--red);    background: var(--red-bg); }
.emp__badge--off       { color: var(--muted);  background: #f1f4f9; }

.emp__body { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.emp__time { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.emp__cap { font-size: 12px; color: var(--ink-soft); }
.emp__mmss {
  font-family: "Inter", sans-serif; font-weight: 800; font-size: clamp(26px, 2.4vw, 34px);
  line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
.emp--working   .emp__mmss { color: var(--green); }
.emp--break     .emp__mmss { color: var(--orange); }
.emp--exhausted .emp__mmss { color: var(--red); }
.emp--off       .emp__mmss { color: var(--ink-soft); }
.emp__quota { font-size: 11px; color: var(--muted); }

.emp__ring { flex: none; position: relative; width: 62px; height: 62px; }
.emp__ring svg { transform: rotate(-90deg); }
.emp__ring-track { stroke: #eef1f7; }
.emp__ring-fill  { transition: stroke-dashoffset .5s ease; stroke-linecap: round; }
.emp--working   .emp__ring-fill { stroke: var(--green); }
.emp--break     .emp__ring-fill { stroke: var(--orange); }
.emp--exhausted .emp__ring-fill { stroke: var(--red); }
.emp--off       .emp__ring-fill { stroke: var(--muted); }
.emp__ring-pct {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: "Inter", sans-serif; font-weight: 800; font-size: 14px; color: var(--ink);
}

/* ═════════ WELCOME PANEL ═════════ */
.welcome {
  position: relative; overflow: hidden;
  padding: clamp(18px,1.7vw,30px);
  display: flex; flex-direction: column;
  flex: 1 1 auto;             /* ดันให้คอลัมน์ซ้ายเต็มความสูง */
}
/* คลื่นตกแต่งด้านล่าง (เหมือนภาพต้นฉบับ) */
.welcome__wave {
  position: absolute; left: 0; right: 0; bottom: -1px; height: 46%;
  background:
    radial-gradient(120% 90% at 18% 120%, #eaf1ff 0%, rgba(234,241,255,0) 60%),
    radial-gradient(120% 90% at 88% 120%, #eef1fb 0%, rgba(238,241,251,0) 60%);
  pointer-events: none; z-index: 0;
}
.welcome > * { position: relative; z-index: 1; }

.welcome__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.welcome__hi { display: flex; gap: 12px; align-items: center; }
.welcome__avatar {
  width: 46px; height: 46px; border-radius: 14px; background: #eef2fd;
  display: grid; place-items: center; font-size: 22px;
}
.welcome__hi h2 { margin: 0; font-size: clamp(16px,1.3vw,21px); font-weight: 800; }
.welcome__hi p { margin: 2px 0 0; font-size: 13px; }
.chip {
  font-size: 13px; font-weight: 600; padding: 9px 15px; border-radius: 99px;
  border: 1px solid var(--line); white-space: nowrap;
}
.chip--soft { background: #f6f8fd; color: var(--ink-soft); }

/* body 3 ส่วน: [วันที่] [นาฬิกา+มินิ] [ความสำเร็จ] */
.welcome__body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 190px minmax(0,1fr) 200px;
  gap: clamp(14px,1.6vw,26px);
  align-items: center;
  margin: clamp(16px,2vw,28px) 0;
}

.datebox {
  align-self: stretch;
  background: linear-gradient(180deg,#f6f9ff,#e9f0ff);
  border: 1px solid #dce6fb; border-radius: var(--radius-sm);
  padding: clamp(16px,1.6vw,24px) 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.datebox__cap { font-size: 12px; color: var(--muted); }
.datebox__day { font-family: "Inter",sans-serif; font-weight: 900; font-size: clamp(40px,4vw,60px); line-height: 1; color: var(--blue); }
.datebox__mon { font-weight: 700; font-size: clamp(13px,1.1vw,16px); }
.datebox__dow { font-size: 13px; }

.welcome__center { text-align: center; min-width: 0; }
.clockwrap__cap { color: var(--ink-soft); font-weight: 600; margin: 0 0 6px; }
.bigclock {
  display: flex; align-items: center; justify-content: center; gap: clamp(4px,.6vw,12px);
  font-family: "Inter", sans-serif; font-weight: 800;
  font-size: clamp(50px, 8.5vw, 118px); line-height: .9;
  color: #2b3556; font-variant-numeric: tabular-nums;
}
.bigclock em { color: var(--blue); font-style: normal; transform: translateY(-.08em); }
.clockwrap__units {
  display: flex; justify-content: center; gap: clamp(36px,7vw,120px);
  margin-top: 10px; color: var(--blue); font-weight: 600; font-size: clamp(12px,1vw,15px);
}
.mini {
  display: grid; grid-template-columns: repeat(3,1fr); gap: 10px;
  margin-top: clamp(16px,2vw,26px);
}
.mini__cell {
  background: rgba(255,255,255,.75); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 12px; display: flex; align-items: center; gap: 10px; text-align: left;
  font-size: 12px; color: var(--ink-soft);
}
.mini__cell b { font-size: 14px; color: var(--ink); }
.wx-desc { font-style: normal; font-size: 12px; color: var(--muted); }
.mini__ic {
  flex: none; width: 38px; height: 38px; border-radius: 11px; background: #eef2fd;
  display: grid; place-items: center; font-size: 18px;
}

.successbox {
  align-self: stretch; position: relative;
  background: linear-gradient(180deg,#fbfcff,#f1f5ff);
  border: 1px solid #e2e9f8; border-radius: var(--radius-sm);
  padding: clamp(16px,1.6vw,22px) 16px; text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.successbox__quote {
  position: absolute; top: 6px; left: 14px;
  font-family: Georgia, serif; font-size: 46px; color: #cdd9f3; line-height: 1;
}
.successbox__ic { font-size: 34px; }
.successbox p { margin: 0; font-size: clamp(12px,1vw,14px); color: var(--ink-soft); line-height: 1.7; }
.successbox p b { color: var(--blue); }

.welcome__foot {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  margin-top: auto; padding-top: 16px;
  border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-soft);
}

/* ═════════ SIDEBAR (คอลัมน์ขวา) ═════════ */
.side { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.side .feed { flex: 1 1 auto; display: flex; flex-direction: column; }
.side .feed__list { flex: 1 1 auto; }

/* leaderboard */
.rank__list { list-style: none; margin: 10px 0 6px; padding: 6px 14px; display: flex; flex-direction: column; gap: 4px; }
.rank__item { display: flex; align-items: center; gap: 12px; padding: 9px 8px; border-radius: 12px; }
.rank__item:hover { background: #f7f9fd; }
.rank__medal { flex: none; width: 30px; text-align: center; font-size: 20px; font-weight: 800; color: var(--muted); font-family:"Inter",sans-serif; }
.rank__avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px;
}
.rank__info { flex: 1 1 auto; min-width: 0; }
.rank__name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank__bar { height: 6px; border-radius: 99px; background: #eef1f7; margin-top: 6px; overflow: hidden; }
.rank__bar > i { display: block; height: 100%; border-radius: 99px; background: var(--green); transition: width .6s; }
.rank__count { flex: none; text-align: right; }
.rank__count b { font-family:"Inter",sans-serif; font-size: 20px; color: var(--green); font-variant-numeric: tabular-nums; }
.rank__count span { display: block; font-size: 11px; color: var(--muted); }
.rank__item--1 .rank__medal { color: #f0a818; }
.rank__item--2 .rank__medal { color: #9aa7bd; }
.rank__item--3 .rank__medal { color: #cd7f43; }

/* activity feed */
.feed__list { list-style: none; margin: 10px 0 6px; padding: 6px 14px; display: flex; flex-direction: column; gap: 6px; }
.feed__item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; background: #fbfcfe; border: 1px solid var(--line); }
.feed__time { flex: none; font-family:"Inter",sans-serif; font-weight: 700; font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; min-width: 62px; }
.feed__ic { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 15px; }
.feed__ic--pack { background: var(--green-bg); color: var(--green); }
.feed__ic--ret  { background: var(--orange-bg); color: var(--orange); }
.feed__info { flex: 1 1 auto; min-width: 0; }
.feed__top { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed__top b { font-weight: 700; }
.feed__status--pack { color: var(--green); font-weight: 700; }
.feed__status--ret  { color: var(--orange); font-weight: 700; }
.feed__order { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-ghost {
  display: block; width: calc(100% - 28px); margin: 4px 14px 16px;
  padding: 11px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--blue); font-weight: 700; font-size: 14px; cursor: pointer;
  font-family: inherit; transition: background .15s;
}
.btn-ghost:hover { background: #f4f7ff; }

.empty { list-style: none; text-align: center; color: var(--muted); padding: 22px; font-size: 14px; }

/* ═════════ FOOTER ═════════ */
.footbar {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 6px 10px; font-size: 13px; color: var(--ink-soft);
}
.footbar__status.is-error { color: var(--red); }
.footbar__status.is-ok b { color: var(--green); }

/* fade-in update */
.flash { animation: flash .5s ease; }
@keyframes flash { from { background: #fff7d6; } to { background: transparent; } }

/* ═════════ RESPONSIVE ═════════ */

/* large tablet / small laptop: sidebar narrows + welcome ตัดกล่องความสำเร็จออก */
@media (max-width: 1240px) {
  .layout { grid-template-columns: minmax(0,1fr) 320px; }
  .welcome__body { grid-template-columns: 180px minmax(0,1fr); }
  .successbox { display: none; }
  .breaks__grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* tablet: ยุบเป็นคอลัมน์เดียว, sidebar ไปอยู่ล่างแบบ 2-col */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .side { flex-direction: row; }
  .side > .panel { flex: 1 1 0; }
  .welcome__body { grid-template-columns: 200px minmax(0,1fr); }
  .breaks__grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* KPI wraps to 2×2 when cramped, hide operators */
@media (max-width: 860px) {
  .kpi-row { flex-wrap: wrap; }
  .kpi { flex: 1 1 calc(50% - 8px); }
  .op { display: none; }
  .welcome__body { grid-template-columns: 1fr; }
  .datebox { flex-direction: row; justify-content: center; gap: 14px; padding: 16px; }
}

/* phones */
@media (max-width: 680px) {
  .side { flex-direction: column; }
  .kpi { flex: 1 1 100%; }
  .topbar__sub { gap: 8px; }
  .mini { grid-template-columns: 1fr; }
  .clockwrap__units { gap: 18vw; }
  .feed__time { min-width: 54px; }
  .welcome__head .chip { display: none; }
  .datebox { flex-direction: column; }
  .breaks__grid { grid-template-columns: 1fr; }
}

/* big TV / kiosk: scale up comfortably */
@media (min-width: 1920px) {
  .dash { max-width: 1840px; }
  html { font-size: 18px; }
}

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