/* ============================================================
   ระบบสารสนเทศ สพม.เพชรบูรณ์ — Portal (Sidebar + iframe + Admin)
   ============================================================ */

:root {
  --primary:   #1e3a8a;
  --primary-2: #2563eb;
  --accent:    #f5b301;
  --sb-bg:     #0f1e3d;
  --sb-bg-2:   #142850;
  --sb-text:   #cbd5e1;
  --sb-w:      272px;
  --sb-mini:   76px;

  --bg:        #eef2f7;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --line:      #e2e8f0;
  --line-strong:#cbd5e1;
  --text:      #1e293b;
  --muted:     #64748b;
  --blue-tint: #eaf1ff;
  --blue-ink:  #1d4ed8;
  --danger:    #e11d48;
  --danger-tint:#fff1f3;
  --pink:      #e11d63;
  --pink-tint: #fff0f5;
  --pink-line: #fbc8da;
  --focus:     #3b82f6;

  --font:      "Sarabun", "Kanit", "Segoe UI", Tahoma, sans-serif;
  --font-head: "Kanit", "Sarabun", sans-serif;
  --r:  14px;
  --r-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow:    0 4px 14px rgba(15, 23, 42, .07);
  --ease: cubic-bezier(.4, 0, .2, 1);
}

/* ============================================================ BASE */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, legend, .btn, .nav-link, .sb-title { font-family: var(--font-head); }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ============================================================ BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: 0 1.15rem;
  border: 1px solid transparent; border-radius: 12px;
  font-weight: 500; font-size: .95rem; line-height: 1;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: transform .15s, box-shadow .15s, background-color .15s, border-color .15s, color .15s;
}
.btn--sm { min-height: 38px; padding: 0 .85rem; font-size: .88rem; border-radius: 10px; }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: linear-gradient(135deg, #3b82f6, #4f46e5); color: #fff;
  box-shadow: 0 6px 16px rgba(59, 100, 246, .3);
}
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(59, 100, 246, .38); }
.btn--plain { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-sm); }
.btn--plain:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn--danger {
  background: linear-gradient(135deg, #f43f5e, #e11d48); color: #fff;
  box-shadow: 0 6px 16px rgba(225, 29, 72, .28);
}
.btn--danger-text { color: var(--danger); }
.btn--danger-text:hover { background: var(--danger-tint); border-color: var(--pink-line); }
.btn--glass {
  background: rgba(255, 255, 255, .12); color: #fff;
  border-color: rgba(255, 255, 255, .25);
}
.btn--glass:hover { background: rgba(255, 255, 255, .22); }
.btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: progress; transform: none; }

/* ============================================================ 1. HEADER */
.site-header {
  position: relative; overflow: hidden;
  background: linear-gradient(120deg, #0f1e3d 0%, var(--primary) 45%, var(--primary-2) 100%);
  color: #fff;
  padding: 18px 28px;
  border-bottom: 4px solid var(--accent);
  box-shadow: 0 4px 18px rgba(15, 30, 61, .25);
}
.site-header::before, .site-header::after {
  content: ""; position: absolute; border-radius: 50%;
  background: rgba(255, 255, 255, .06); pointer-events: none;
}
.site-header::before { width: 340px; height: 340px; right: -80px; top: -170px; }
.site-header::after  { width: 220px; height: 220px; right: 260px; bottom: -150px; }

.header-inner { position: relative; z-index: 1; display: flex; align-items: center; gap: 18px; }

.logo-wrap {
  width: 78px; height: 78px; flex-shrink: 0;
  border-radius: 50%; background: #fff; padding: 6px;
  box-shadow: 0 0 0 3px rgba(245, 179, 1, .7), 0 6px 16px rgba(0, 0, 0, .25);
  display: grid; place-items: center;
}
.logo-wrap img { width: 100%; height: 100%; object-fit: contain; border-radius: 50%; }
.logo-fallback {
  display: none; width: 100%; height: 100%; place-items: center; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: var(--accent); font-size: 2rem;
}

.header-text { flex: 1; min-width: 0; }
.header-text .org { font-family: var(--font-head); font-size: 1.55rem; font-weight: 600; line-height: 1.3; }
.header-text .dept { font-family: var(--font-head); font-weight: 300; font-size: 1.05rem; color: #fde68a; margin-top: 2px; }
.header-text .tagline { font-size: .9rem; opacity: .8; margin-top: 4px; }

.header-side { display: flex; align-items: center; gap: 14px; }
.clock {
  display: flex; flex-direction: column; align-items: flex-end;
  font-family: var(--font-head); font-weight: 300; font-size: .88rem; line-height: 1.35;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18);
  padding: 8px 14px; border-radius: 10px; white-space: nowrap;
}
.clock i { color: var(--accent); margin-right: 6px; }
.clock__time { font-size: 1.1rem; font-weight: 500; font-variant-numeric: tabular-nums; }

/* ============================================================ LAYOUT */
.layout { flex: 1; display: flex; min-height: 0; }

/* ============================================================ 2. SIDEBAR */
.sidebar {
  width: var(--sb-w); flex-shrink: 0;
  background: linear-gradient(180deg, var(--sb-bg) 0%, var(--sb-bg-2) 100%);
  color: var(--sb-text);
  display: flex; flex-direction: column;
  transition: width .3s var(--ease), transform .3s var(--ease);
  position: relative; z-index: 40;
}
.sb-top {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; min-height: 64px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.toggle-btn {
  width: 46px; height: 46px; flex-shrink: 0;
  border: none; border-radius: 12px;
  background: rgba(255, 255, 255, .08); color: #fff; font-size: 1.15rem;
  cursor: pointer; transition: background .2s, transform .2s;
}
.toggle-btn:hover { background: var(--primary-2); }
.toggle-btn:active { transform: scale(.94); }
.sb-title { font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; transition: opacity .2s; line-height: 1.3; }
.sb-title small { display: block; font-weight: 300; font-size: .75rem; color: var(--sb-text); }

.nav { list-style: none; padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-section {
  font-family: var(--font-head); font-size: .72rem; letter-spacing: 1px;
  color: #64748b; padding: 12px 14px 6px; white-space: nowrap; overflow: hidden;
}
.nav-empty { padding: 8px 14px; font-size: .85rem; color: #64748b; }

.nav-link {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; margin-bottom: 4px; border-radius: 10px;
  color: var(--sb-text); text-decoration: none;
  font-size: .92rem; font-weight: 400; white-space: nowrap;
  transition: background .2s, color .2s;
}
.nav-link .ico {
  width: 30px; height: 30px; flex-shrink: 0; display: grid; place-items: center;
  border-radius: 8px; font-size: 1rem;
  color: var(--c, #93c5fd); background: rgba(255, 255, 255, .05);
  transition: background .2s, color .2s;
}
.nav-link .label { flex: 1; overflow: hidden; text-overflow: ellipsis; transition: opacity .2s; }
.nav-link .ext { font-size: .7rem; opacity: .55; }
.nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-link.active {
  background: linear-gradient(90deg, rgba(37, 99, 235, .9), rgba(37, 99, 235, .45));
  color: #fff; box-shadow: 0 4px 12px rgba(37, 99, 235, .35);
}
.nav-link.active .ico { background: rgba(255, 255, 255, .2); color: #fff; }
.nav-link.active::before {
  content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--accent);
}

.sb-tools { padding: 10px; border-top: 1px solid rgba(255, 255, 255, .08); display: none; }
body.system-mode .sb-tools { display: block; }

/* Sidebar ย่อ */
body.sb-collapsed .sidebar { width: var(--sb-mini); }
body.sb-collapsed .sb-title,
body.sb-collapsed .nav-link .label,
body.sb-collapsed .nav-link .ext,
body.sb-collapsed .nav-empty { display: none; }
body.sb-collapsed .nav-section { height: 1px; padding: 0; margin: 8px 6px; background: rgba(255,255,255,.08); color: transparent; }
body.sb-collapsed .nav-link { justify-content: center; padding: 10px 0; gap: 0; }
body.sb-collapsed .nav { overflow: visible; }
body.sb-collapsed .nav-link::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 14px); top: 50%;
  transform: translateY(-50%) translateX(-6px);
  background: #0f172a; color: #fff; font-size: .82rem;
  padding: 7px 12px; border-radius: 8px; white-space: nowrap;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 100;
}
body.sb-collapsed .nav-link:hover::after { opacity: 1; transform: translateY(-50%) translateX(0); }

/* ============================================================ 3. CONTENT */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.welcome { width: 100%; max-width: 1280px; margin: 0 auto; padding: 28px; animation: fadeUp .4s var(--ease); }

/* แถบ Admin */
.admin-bar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: .6rem 1rem; margin-bottom: 18px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--pink-line); border-radius: var(--r);
  box-shadow: var(--shadow);
}
.admin-badge {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .3rem .85rem; border-radius: 999px;
  background: var(--pink-tint); color: var(--pink); border: 1px solid var(--pink-line);
  font-family: var(--font-head); font-weight: 500; font-size: .9rem;
}
.admin-bar__actions { display: flex; gap: .45rem; flex-wrap: wrap; }

/* Hero */
.hero {
  display: flex; gap: 20px; align-items: flex-start;
  background:
    radial-gradient(600px 240px at 100% 0%, rgba(191, 219, 254, .55), transparent 60%),
    radial-gradient(500px 220px at 85% 100%, rgba(253, 230, 138, .35), transparent 60%),
    var(--surface);
  border-radius: var(--r-lg); padding: 26px 28px; margin-bottom: 26px;
  border-left: 6px solid var(--primary-2); box-shadow: var(--shadow);
}
.hero-ico {
  width: 64px; height: 64px; flex-shrink: 0; border-radius: 16px;
  display: grid; place-items: center; font-size: 1.7rem; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.hero-body { flex: 1; min-width: 0; }
.hero h1 { font-size: 1.45rem; font-weight: 500; color: var(--primary); line-height: 1.35; }
.hero p { color: var(--muted); margin-top: 4px; }

.search {
  margin-top: 16px; max-width: 640px;
  display: flex; align-items: center; gap: .7rem;
  height: 52px; padding: 0 .55rem 0 1rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-sm);
}
.search:focus-within { border-color: var(--primary-2); box-shadow: 0 0 0 4px var(--blue-tint); }
.search__icon { color: var(--primary-2); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; font-size: 1rem; outline: none; }
.search__kbd {
  font: 600 .78rem var(--font-head); color: var(--blue-ink);
  background: var(--blue-tint); border-radius: 8px; padding: .15rem .55rem;
}

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.section-head h2 { font-size: 1.1rem; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.section-head h2 i { color: var(--primary-2); }
.count-pill {
  padding: .2rem .8rem; border-radius: 999px;
  background: var(--blue-tint); color: var(--blue-ink);
  font-family: var(--font-head); font-size: .88rem; font-variant-numeric: tabular-nums;
}

/* การ์ด */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.note {
  grid-column: 1 / -1; padding: 2.2rem 1.5rem; text-align: center; color: var(--muted);
  border: 1.5px dashed var(--line-strong); border-radius: var(--r); background: var(--surface);
}

.card {
  --c: var(--primary-2);
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-sm); overflow: hidden;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .25s;
}
.card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); }
.card:hover, .card:focus-within {
  transform: translateY(-4px); border-color: var(--c);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .12);
}
.card.is-hidden { display: none; }

.card__link {
  flex: 1; display: flex; flex-direction: column; gap: 10px;
  padding: 22px 20px 18px; color: inherit; text-decoration: none;
}
.card__link:focus-visible { outline: none; }
.card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.c-ico {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.4rem; color: var(--c);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--c) 13%, white);
}
.card__meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: .76rem; }
.badge {
  padding: 0 .55rem; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.badge--tab { border-color: #fcd9b6; background: #fff7ed; color: #c2410c; border-radius: 999px; }
.card h3 { font-size: 1.03rem; font-weight: 500; line-height: 1.45; }
.card p { font-size: .88rem; color: var(--muted); flex: 1; }
.card .go { font-family: var(--font-head); font-size: .86rem; color: var(--c); display: flex; align-items: center; gap: 6px; }
.card .go i { transition: transform .2s; }
.card:hover .go i { transform: translateX(4px); }

.card__admin {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 10px 14px 14px; border-top: 1px dashed var(--line); background: var(--surface-2);
}
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 34px; min-width: 34px; padding: 0 .65rem;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  font-size: .84rem; cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn--move:not(:disabled):hover,
.icon-btn--edit:hover { background: var(--blue-tint); border-color: #b9ccff; color: var(--blue-ink); }
.icon-btn--delete { margin-left: auto; }
.icon-btn--delete:hover { background: var(--danger-tint); border-color: var(--pink-line); color: var(--danger); }

.card--add {
  border: 1.5px dashed var(--line-strong); background: transparent; box-shadow: none;
  min-height: 180px; cursor: pointer;
  align-items: center; justify-content: center; gap: 10px;
  color: var(--blue-ink); font-family: var(--font-head); font-size: 1rem;
}
.card--add::before { display: none; }
.card--add:hover { border-color: var(--primary-2); background: var(--blue-tint); transform: none; box-shadow: none; }
.card--add .c-ico { background: linear-gradient(135deg, #3b82f6, #4f46e5); color: #fff; }

/* พื้นที่ iframe */
.frames { flex: 1; display: none; position: relative; min-height: 0; }
body.system-mode .frames { display: block; }
body.system-mode .welcome { display: none; }
.system-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: none; background: #fff; display: none; }
.system-frame.active { display: block; }

.loader {
  position: absolute; inset: 0; z-index: 5;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(238, 242, 247, .94); font-family: var(--font-head); color: var(--muted);
  padding: 20px; text-align: center;
}
.loader.show { display: flex; }
.loader__hint { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 420px; font-family: var(--font); font-size: .9rem; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid #cbd5e1; border-top-color: var(--primary-2);
  animation: spin .8s linear infinite;
}

/* ============================================================ 4. FOOTER */
.site-footer {
  background: #0f1e3d; color: #94a3b8; text-align: center;
  padding: 16px 20px; font-size: .86rem; border-top: 3px solid var(--accent);
}
.site-footer strong { color: #e2e8f0; font-weight: 500; }
.site-footer p + p { margin-top: 4px; }

/* ============================================================ โหมดแสดงระบบ */
body.system-mode { height: 100vh; height: 100dvh; overflow: hidden; }
body.system-mode .site-header,
body.system-mode .site-footer { display: none; }

.fab-menu {
  display: none; position: fixed; left: 14px; bottom: 18px; z-index: 60;
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  font-size: 1.25rem; box-shadow: 0 8px 20px rgba(30, 58, 138, .45); cursor: pointer;
}
.backdrop { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 35; }

/* ============================================================ MODAL */
.modal {
  width: min(600px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  margin: auto; padding: 0; border: 0; border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 60px rgba(15, 27, 51, .25);
  overflow: auto; overscroll-behavior: contain;
}
.modal--sm { width: min(440px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal[open] { animation: modal-in .18s ease-out; }

.modal__head { position: relative; padding: 1.4rem 3.5rem .25rem 1.5rem; }
.modal__head h2 { font-size: 1.3rem; font-weight: 500; }
.modal__head h2 i { color: var(--primary-2); margin-right: 4px; }
.modal__title-row { display: flex; align-items: center; gap: 14px; }
.modal__sub { margin-top: .15rem; color: var(--muted); font-size: .92rem; }
.modal__close {
  position: absolute; top: 1rem; right: 1rem;
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--muted); cursor: pointer; font-size: 1.05rem;
}
.modal__close:hover { background: var(--surface-2); color: var(--text); }
.modal__body { padding: 1.1rem 1.5rem .25rem; }
.modal__foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.5rem 1.5rem; }

.icon-preview {
  --c: var(--primary-2);
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 14px;
  display: grid; place-items: center; font-size: 1.4rem; color: #fff; background: var(--c);
  box-shadow: 0 6px 14px rgba(15, 23, 42, .15);
}

/* ============================================================ FORM */
.field { margin-bottom: 1.05rem; min-width: 0; border: 0; }
.field-row { display: grid; grid-template-columns: 11rem 1fr; gap: 0 .9rem; }
.field label, .field legend { display: block; margin-bottom: .35rem; font-weight: 500; font-size: .92rem; }
.req { color: var(--danger); }
.field input[type="text"], .field input[type="password"], .field textarea {
  display: block; width: 100%; padding: .62rem .85rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
  font-size: 1rem; line-height: 1.6; outline: none;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field textarea:focus {
  background: var(--surface); border-color: var(--primary-2);
  outline: 3px solid var(--blue-tint); outline-offset: 0;
}
.field [aria-invalid="true"] { border-color: var(--danger) !important; outline-color: var(--danger-tint) !important; }
.field__password { position: relative; }
.field__password input { padding-right: 3rem !important; }
.field__toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer;
}
.field__toggle:hover { background: var(--blue-tint); color: var(--blue-ink); }
.field__error { margin-top: .3rem; font-size: .85rem; color: var(--danger); }
.field__error:empty { display: none; }
.field__hint { margin-top: .25rem; font-size: .8rem; color: var(--muted); text-align: right; }
.field__hint--left { text-align: left; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented input, .icon-picker input, .color-picker input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: 0 .75rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); cursor: pointer; font-size: .92rem; text-align: center;
}
.segmented input:checked + span { border-color: var(--primary-2); background: var(--blue-tint); color: var(--blue-ink); font-weight: 600; }
.segmented input:focus-visible + span,
.icon-picker input:focus-visible + span,
.color-picker input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.icon-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.icon-picker label { position: relative; margin: 0; }
.icon-picker span {
  display: grid; place-items: center; height: 44px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
  color: var(--muted); font-size: 1.1rem; cursor: pointer; transition: all .15s;
}
.icon-picker span:hover { color: var(--text); border-color: var(--line-strong); }
.icon-picker input:checked + span { background: var(--pick, var(--primary-2)); border-color: transparent; color: #fff; }

.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-picker label { position: relative; margin: 0; }
.color-picker span {
  display: block; width: 36px; height: 36px; border-radius: 50%;
  background: var(--sw); cursor: pointer; border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line-strong);
}
.color-picker input:checked + span { box-shadow: 0 0 0 3px var(--sw); }

.shake { animation: shake .35s; }

/* ============================================================ TOAST */
.toast-stack {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000;
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  width: calc(100vw - 24px); pointer-events: none;
}
.toast {
  max-width: 100%; padding: .75rem 1.15rem; border-radius: 12px;
  background: linear-gradient(135deg, #10b981, #0ea5a4); color: #fff;
  font-size: .94rem; font-weight: 500; box-shadow: 0 10px 28px rgba(16, 185, 129, .3);
  animation: toast-in .2s ease-out;
}
.toast--error { background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 10px 28px rgba(225, 29, 72, .3); }
.toast.is-leaving { animation: toast-out .2s ease-in forwards; }

/* ============================================================ ANIMATIONS */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ============================================================ RESPONSIVE */
@media (max-width: 980px) {
  .clock { display: none; }
}

@media (max-width: 768px) {
  .site-header { padding: 14px 16px; }
  .logo-wrap { width: 58px; height: 58px; padding: 4px; }
  .header-text .org { font-size: 1.02rem; }
  .header-text .dept { font-size: .86rem; }
  .header-text .tagline { display: none; }
  #btn-login span { display: none; }
  #btn-login { padding: 0 .9rem; }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: var(--sb-w) !important; transform: translateX(-100%);
    box-shadow: 8px 0 24px rgba(0, 0, 0, .3);
  }
  body.sb-open .sidebar { transform: none; }
  body.sb-open .backdrop { display: block; }
  .fab-menu { display: grid; place-items: center; }

  /* มือถือไม่ใช้โหมดย่อ */
  body.sb-collapsed .sb-title, body.sb-collapsed .nav-link .label,
  body.sb-collapsed .nav-link .ext, body.sb-collapsed .nav-empty { display: initial; }
  body.sb-collapsed .nav-link .label { display: block; }
  body.sb-collapsed .nav-section { height: auto; padding: 12px 14px 6px; margin: 0; background: none; color: #64748b; }
  body.sb-collapsed .nav-link { justify-content: flex-start; padding: 10px 14px; gap: 14px; }
  body.sb-collapsed .nav-link::after { display: none; }

  .welcome { padding: 16px 14px 96px; }
  .hero { flex-direction: column; padding: 20px 18px; }
  .hero-ico { width: 52px; height: 52px; font-size: 1.4rem; }
  .search__kbd { display: none; }
  .admin-bar__actions .btn { flex: 1 1 auto; }

  .field-row { grid-template-columns: 1fr; }
  .modal__foot { flex-direction: column-reverse; }
  .modal__foot .btn { width: 100%; }
}

@media (hover: none) { .search__kbd { display: none; } }

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