/* ============================================================
   WWA Sci Tracker — style.css (light mode only)
   ============================================================ */

:root {
  --primary:#6366F1; --primary-dark:#4F46E5; --primary-light:#EEF2FF;
  --accent:#059669; --accent-light:#ECFDF5;
  --bg:#F6F5FB; --card:#FFFFFF; --fg:#1E1B4B;
  --muted:#EBEFF9; --muted-fg:#64748B; --border:#E2E4F0;
  --danger:#DC2626; --danger-light:#FEF2F2;
  --warn:#D97706; --warn-light:#FFFBEB;
  --info:#2563EB; --info-light:#EFF6FF;
  --violet:#7C3AED; --violet-light:#F5F3FF;
  --slate:#475569; --slate-light:#F1F5F9;
  --radius:14px; --radius-sm:9px; --shadow:0 1px 3px rgba(30,27,75,.07),0 4px 14px rgba(30,27,75,.06);
  /* extras (not overriding spec vars) */
  --gray:#4B5563; --gray-light:#F3F4F6;
  /* โทนเข้มสำหรับ "ตัวอักษร" บนพื้นอ่อน ให้ contrast ≥4.5:1 (SPEC §11 DoD #6) */
  --warn-strong:#92400E;    /* บน --warn-light ≈7.4:1, บนขาว ≈7.6:1 */
  --accent-strong:#047857;  /* บน --accent-light ≈5.2:1, ขาวบนพื้นนี้ ≈5.5:1 */
  --danger-strong:#B91C1C;  /* บน --danger-light ≈5.9:1 */
  --primary-darker:#4338CA; /* hover ของปุ่ม primary */
}

*, *::before, *::after { box-sizing: border-box; }

/* attribute hidden ต้องชนะ display ที่ประกาศไว้ (เช่น #app-shell{display:flex}) */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Noto Sans Thai', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 600; }
a { color: var(--primary-dark); }
img, svg { vertical-align: middle; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============ Layout: sidebar + main ============ */

#app-shell { display: flex; min-height: 100vh; }

#sidebar {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 240px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 60;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
}

.logo-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.logo-mark svg { width: 22px; height: 22px; }
.logo-text { font-weight: 700; font-size: 17px; letter-spacing: .1px; }

#nav-menu {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--muted-fg);
  font-weight: 500;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
  cursor: pointer;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
.nav-item:hover { background: var(--muted); color: var(--fg); }
.nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.nav-item .nav-label { flex: 1; }

.notif-badge {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  flex: none;
}

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted-fg);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.logout-btn:hover { background: var(--danger-light); color: var(--danger); }
.logout-btn svg { width: 20px; height: 20px; }

.main-area {
  flex: 1;
  min-width: 0;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
}

#view {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px 60px;
}

#topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-title { flex: 1; font-weight: 700; font-size: 17px; }

.bell-btn { position: relative; color: var(--muted-fg); }
.bell-btn .notif-badge {
  position: absolute;
  top: 2px; right: 0;
  min-width: 18px; height: 18px;
  line-height: 18px;
  font-size: 11px;
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 50;
  border: none;
}

@media (max-width: 1023.98px) {
  #sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: none;
  }
  body.drawer-open #sidebar { transform: none; box-shadow: var(--shadow); }
  body.drawer-open .scrim { display: block; }
  body.drawer-open { overflow: hidden; }
  .main-area { margin-left: 0; }
  #topbar { display: flex; }
  #view { padding: 16px 16px 48px; }
  h1 { font-size: 22px; }
}

/* ============ Buttons ============ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ใช้ --primary-dark เป็นพื้นปกติ: ขาวบน --primary ได้แค่ 4.47:1 (ไม่ถึง 4.5:1 ตาม DoD #6) */
.btn-primary { background: var(--primary-dark); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-darker); }

.btn-secondary { background: var(--card); border-color: var(--border); color: var(--fg); }
.btn-secondary:hover:not(:disabled) { background: var(--muted); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #B91C1C; }

.btn-danger-outline { background: var(--card); border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-light); }

.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted-fg);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  flex: none;
}
.icon-btn:hover { background: var(--muted); color: var(--fg); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.danger:hover { background: var(--danger-light); color: var(--danger); }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
.spinner-dark { border-color: rgba(30,27,75,.2); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Chips ============ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.5;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

.chip-slate   { background: var(--slate-light);   color: var(--slate); }
.chip-blue    { background: var(--info-light);    color: var(--info); }
.chip-violet  { background: var(--violet-light);  color: var(--violet); }
/* emerald/red/amber: ตัวอักษรใช้โทน *-strong ให้ ≥4.5:1 บนพื้น *-light — จุดกลมคงสีสดไว้ */
.chip-emerald { background: var(--accent-light);  color: var(--accent-strong); }
.chip-red     { background: var(--danger-light);  color: var(--danger-strong); }
.chip-amber   { background: var(--warn-light);    color: var(--warn-strong); }
.chip-emerald .dot { background: var(--accent); }
.chip-red .dot     { background: var(--danger); }
.chip-amber .dot   { background: var(--warn); }
.chip-gray    { background: var(--gray-light);    color: var(--gray); }
.chip-indigo  { background: var(--primary-light); color: var(--primary-dark); }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* filter chips */
.fchip {
  display: inline-flex;
  align-items: center;
  padding: 10px 16px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted-fg);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.fchip:hover { border-color: var(--primary); color: var(--primary-dark); }
.fchip.active { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.fchip-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============ Cards ============ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
}
.card-title svg { width: 18px; height: 18px; color: var(--primary); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
@media (max-width: 639.98px) { .card-grid { grid-template-columns: 1fr; } }

.click-card { cursor: pointer; transition: transform .15s ease, border-color .15s ease; }
.click-card:hover { transform: translateY(-2px); border-color: var(--primary); }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head .grow { flex: 1; min-width: 200px; }
.page-sub { color: var(--slate); font-size: 14px; } /* --muted-fg บน --bg ได้แค่ 4.39:1 */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.search-box { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search-box svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  color: var(--muted-fg);
  pointer-events: none;
}
.search-box input { padding-left: 40px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted-fg);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 10px;
  min-height: 44px;
}
.back-link:hover { color: var(--primary-dark); }
.back-link svg { width: 18px; height: 18px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
@media (max-width: 1023.98px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-grid .span-2 { grid-column: 1 / -1; }

.info-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; }
.info-list .info-item .info-label { font-size: 13px; color: var(--muted-fg); font-weight: 600; }
.info-list .info-item .info-value { font-size: 15px; overflow-wrap: anywhere; }

/* ============ KPI ============ */

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
@media (max-width: 1023.98px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 479.98px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}
.kpi-num { font-size: 38px; font-weight: 700; line-height: 1.15; }
.kpi-label { font-size: 14px; color: var(--muted-fg); font-weight: 600; }
.kpi-icon {
  width: 46px; height: 46px;
  border-radius: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-emerald .kpi-icon { background: var(--accent-light); color: var(--accent); }
.kpi-emerald .kpi-num  { color: var(--accent); }
.kpi-amber .kpi-icon   { background: var(--warn-light); color: var(--warn); }
.kpi-amber .kpi-num    { color: var(--warn); }
.kpi-violet .kpi-icon  { background: var(--violet-light); color: var(--violet); }
.kpi-violet .kpi-num   { color: var(--violet); }
.kpi-indigo .kpi-icon  { background: var(--primary-light); color: var(--primary-dark); }
.kpi-indigo .kpi-num   { color: var(--primary-dark); }

.dash-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1023.98px) { .dash-cols { grid-template-columns: 1fr; } }
.dash-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* deadline rows */
.dl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.dl-row a, .notif-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: background .15s ease;
}
.dl-row a:hover { background: var(--primary-light); }
.dl-row + .dl-row { border-top: 1px solid var(--border); }
.date-badge {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  flex: none;
}
.date-badge b { font-size: 17px; }
.date-badge small { font-size: 11px; font-weight: 600; }
.dl-info { flex: 1; min-width: 0; }
.dl-name { display: block; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-stage { display: block; font-size: 13px; color: var(--muted-fg); }
.dl-count { font-size: 13px; color: var(--muted-fg); white-space: nowrap; }
/* จอแคบ: ซ่อนเฉพาะตัวเลขจำนวนโครงงาน (ข้อมูลรอง) แต่คงป้ายเตือน 0 โครงงานไว้เพราะเป็น alert */
@media (max-width: 479.98px) {
  .dl-count:not(.no-entry-warn) { display: none; }
  .dl-count.no-entry-warn { white-space: normal; font-size: 12.5px; }
}

/* status bars */
.sbar-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.sbar-row .chip { width: 128px; justify-content: flex-start; }
.hbar { flex: 1; height: 10px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; min-width: 2px; }
.bar-slate { background: var(--slate); }
.bar-blue { background: var(--info); }
.bar-violet { background: var(--violet); }
.bar-emerald { background: var(--accent); }
.bar-red { background: var(--danger); }
.bar-amber { background: var(--warn); }
.bar-gray { background: var(--gray); }
.sbar-num { width: 28px; text-align: right; font-weight: 700; font-size: 14px; }

/* recent events */
.ev-list { list-style: none; margin: 0; padding: 0; }
.ev-list li { padding: 9px 2px; }
.ev-list li + li { border-top: 1px solid var(--border); }
.ev-date { font-size: 12.5px; color: var(--muted-fg); font-weight: 600; }
.ev-line { font-size: 14px; }
.ev-line a { color: inherit; text-decoration: none; font-weight: 600; }
.ev-line a:hover { color: var(--primary-dark); }
.ev-title { font-size: 14px; color: var(--slate); }

/* ============ Competition / project cards ============ */

.comp-card, .proj-card { display: flex; flex-direction: column; gap: 9px; }
.comp-card-top { display: flex; align-items: flex-start; gap: 8px; }
.comp-card-top h3 { flex: 1; font-size: 16.5px; line-height: 1.4; }
/* คง 44×44 จาก .icon-btn (touch target ≥44px) — ใช้ negative margin กันเบียดมุมการ์ด */
.ext-link { color: var(--muted-fg); margin: -10px -10px 0 0; }
.comp-org { color: var(--muted-fg); font-size: 14px; }
.comp-meta { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--muted-fg); }
.comp-meta svg { width: 16px; height: 16px; flex: none; }
.comp-meta.urgent { color: var(--danger); font-weight: 600; }
.comp-meta.soon { color: var(--warn-strong); font-weight: 600; } /* --warn บนขาวได้แค่ 3.19:1 */
/* เตือนเวทีที่ยังไม่มีโครงงานส่งประกวด — อยู่หลัง .dl-count/.comp-meta เพื่อชนะสีเทาด้วย specificity เท่ากัน */
.no-entry-warn { color: var(--warn-strong); font-weight: 600; } /* #92400E บนขาว ≈7.6:1 */

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid var(--card);
  flex: none;
}
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar + .avatar { margin-left: -8px; }
.people-line { display: flex; align-items: center; gap: 8px; font-size: 14px; min-width: 0; }
.people-line .names { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-line svg { width: 16px; height: 16px; color: var(--muted-fg); flex: none; }

/* ============ Tables ============ */

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; min-width: 660px; }
.table-wrap.table-sm table { min-width: 420px; }
th {
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--slate); /* --muted-fg บน --muted ได้แค่ 4.13:1 */
  background: var(--muted);
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 14.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tr.row-click { cursor: pointer; transition: background .15s ease; }
tr.row-click:hover { background: var(--primary-light); }
td.td-actions { white-space: nowrap; text-align: right; }
.td-muted { color: var(--muted-fg); }

/* ============ Forms ============ */

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.req { color: var(--danger); }

input[type="text"], input[type="password"], input[type="url"], input[type="tel"],
input[type="email"], input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--fg);
  font: inherit;
  font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  outline: none;
}
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; margin-top: 5px; min-height: 0; }
.field-hint { color: var(--muted-fg); font-size: 13px; margin-top: 4px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 479.98px) { .form-row { grid-template-columns: 1fr; } }

.input-group { position: relative; }
.input-group input { padding-right: 50px; }
.input-group .input-affix { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); }

/* pick lists (students/advisors in project form) */
.pick-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 210px;
  overflow-y: auto;
  padding: 4px;
}
.pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  min-height: 44px; /* touch target ≥44px */
  border-radius: 7px;
  cursor: pointer;
}
.pick-row:hover { background: var(--muted); }
.pick-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); flex: none; }
.pick-row .pick-name { flex: 1; font-size: 14.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-row select { width: 138px; min-height: 44px; padding: 5px 8px; font-size: 13.5px; flex: none; }
.pick-empty { padding: 12px; color: var(--muted-fg); font-size: 14px; text-align: center; }

/* dynamic stage rows */
.stage-rows { display: flex; flex-direction: column; gap: 8px; }
.stage-row { display: flex; gap: 8px; align-items: flex-start; }
.stage-row .st-name { flex: 1.4; min-width: 0; }
.stage-row .st-date { flex: 1; min-width: 0; }

/* ============ Modal ============ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(30,27,75,.25);
  animation: popIn .18s ease;
}
.modal-wide { max-width: 760px; }
.modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { flex: 1; font-size: 17px; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
}
.confirm-msg { font-size: 15px; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ============ Toast ============ */

#toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--fg);
  color: #fff;
  font-size: 14.5px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(30,27,75,.28);
  animation: toastIn .2s ease;
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast-success { background: var(--accent-strong); } /* ขาวบน --accent ได้แค่ 3.77:1 */
.toast-error { background: var(--danger); }
.toast-out { opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ============ Skeleton ============ */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--muted);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton-stack { display: flex; flex-direction: column; gap: 12px; }
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

/* ============ Timeline ============ */

.timeline { list-style: none; margin: 0; padding: 4px 0 0; position: relative; }
.timeline::before {
  content: '';
  position: absolute;
  left: 7px; top: 10px; bottom: 10px;
  width: 2px;
  background: var(--border);
}
.timeline li { position: relative; padding: 0 0 18px 30px; }
.timeline li:last-child { padding-bottom: 4px; }
.tl-dot {
  position: absolute;
  left: 0; top: 6px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--primary-light);
}
.tl-head { display: flex; align-items: center; gap: 8px; }
.tl-date { font-size: 12.5px; font-weight: 700; color: var(--muted-fg); }
.tl-title { font-weight: 600; font-size: 15px; }
.tl-note { font-size: 14px; color: var(--slate); white-space: pre-wrap; overflow-wrap: anywhere; }
/* คง 44×44 จาก .icon-btn (touch target ≥44px) — หด layout ด้วย negative margin, ย่อเฉพาะไอคอน */
.tl-del { margin: -12px -10px -12px auto; }
.tl-del svg { width: 16px; height: 16px; }

/* ============ Tabs ============ */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  padding: 10px 18px;
  min-height: 44px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--slate); /* --muted-fg บน --bg ได้แค่ 4.39:1 */
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ============ Notifications ============ */

.notif-list { display: flex; flex-direction: column; gap: 12px; }
.notif-card { border-left: 4px solid var(--primary); padding: 14px 16px; }
.notif-card.notif-soon { border-left-color: var(--warn); }
.notif-card.notif-overdue { border-left-color: var(--danger); }
.notif-link { padding: 0; }
.notif-link:hover .dl-name { color: var(--primary-dark); }
.notif-overdue-text { color: var(--danger); font-size: 13.5px; font-weight: 600; }

/* ============ Empty / error states ============ */

.empty {
  text-align: center;
  padding: 42px 16px;
  color: var(--muted-fg);
}
.empty svg { width: 42px; height: 42px; opacity: .55; margin-bottom: 8px; }
.empty .empty-title { font-weight: 700; font-size: 16px; color: var(--slate); }
.empty .empty-sub { font-size: 14px; margin-top: 2px; }
.empty .btn { margin-top: 14px; }

.error-box {
  text-align: center;
  padding: 34px 16px;
  color: var(--danger);
}
.error-box svg { width: 36px; height: 36px; margin-bottom: 6px; }
.error-box p { margin-bottom: 12px; font-weight: 600; }

/* ============ Login ============ */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card { width: 100%; max-width: 400px; padding: 34px 30px; text-align: center; }
.login-logo {
  width: 62px; height: 62px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-logo svg { width: 32px; height: 32px; }
.login-title { font-size: 23px; }
.login-sub { color: var(--muted-fg); font-size: 14.5px; margin-bottom: 22px; }
.login-card form { text-align: left; }

/* ============ Misc ============ */

.section-gap { margin-top: 16px; }
.mt-8 { margin-top: 8px; }
.muted { color: var(--muted-fg); }
.nowrap { white-space: nowrap; }

.detail-header { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px; }
.detail-header .grow { flex: 1; min-width: 220px; }
.detail-header .chip-row { margin-top: 8px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.inline-link { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.inline-link svg { width: 15px; height: 15px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
