/* =====================================================
   Nasan CRS — Premium Stylesheet (Pro UI + Responsive)
   ===================================================== */

:root {
  --brand-50:  #eff6ff;
  --brand-100: #dbeafe;
  --brand-200: #bfdbfe;
  --brand-400: #60a5fa;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-800: #1e40af;
  --brand-900: #1e3a8a;

  --accent-400: #fbbf24;
  --accent-500: #f59e0b;
  --accent-600: #d97706;

  --success: #16a34a;
  --warn:    #d97706;
  --danger:  #dc2626;
  --info:    #0ea5e9;

  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-700: #334155;
  --ink-600: #475569;
  --ink-500: #64748b;
  --ink-400: #94a3b8;
  --ink-300: #cbd5e1;
  --ink-200: #e2e8f0;
  --ink-100: #f1f5f9;
  --ink-50:  #f8fafc;

  --surface: #ffffff;
  --bg:      #f4f7fc;

  --radius-lg: 18px;
  --radius:    14px;
  --radius-sm: 10px;
  --radius-xs: 8px;

  --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
  --shadow-md: 0 4px 14px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 28px rgba(15,23,42,.14);
  --shadow-xl: 0 24px 48px rgba(15,23,42,.18);

  --grad-brand: linear-gradient(135deg, #3b82f6 0%, #1e40af 100%);
  --grad-success: linear-gradient(135deg, #34d399 0%, #059669 100%);
  --grad-warn: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
  --grad-danger: linear-gradient(135deg, #f87171 0%, #b91c1c 100%);
  --grad-purple: linear-gradient(135deg, #a78bfa 0%, #6d28d9 100%);
  --grad-info: linear-gradient(135deg, #38bdf8 0%, #0369a1 100%);

  --font: 'Sarabun', 'Segoe UI', system-ui, -apple-system, sans-serif;

  --header-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink-900);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--brand-600); text-decoration: none; transition: color .15s; }
a:hover { color: var(--brand-700); text-decoration: underline; }

::selection { background: var(--brand-200); color: var(--brand-900); }

/* Custom scrollbar (desktop) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-400); }

/* ============ AUTH PAGE ============ */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 0%, rgba(59,130,246,.18), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(167,139,250,.18), transparent 50%),
    linear-gradient(135deg, #eef2ff 0%, #f5f7fb 50%, #ecfeff 100%);
  position: relative;
}
.auth-body::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(15,23,42,.04) 1px, transparent 0);
  background-size: 24px 24px;
  pointer-events: none;
}
.auth-wrap { width: 100%; max-width: 460px; position: relative; z-index: 1; }
.auth-card {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px;
  box-shadow: var(--shadow-xl);
  padding: 40px 34px;
  border: 1px solid rgba(255,255,255,.8);
  animation: cardIn .5s cubic-bezier(.16,1,.3,1);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand .brand-icon {
  font-size: 38px;
  width: 78px; height: 78px;
  margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 22px;
  background: var(--grad-brand);
  color: #fff;
  box-shadow: 0 12px 32px rgba(37,99,235,.4), inset 0 1px 0 rgba(255,255,255,.3);
  position: relative;
}
.auth-brand .brand-icon::after {
  content: '';
  position: absolute; inset: 4px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.18), transparent);
  pointer-events: none;
}
.auth-brand h1 {
  font-size: 19px; margin: 6px 0 4px;
  line-height: 1.35; white-space: nowrap; font-weight: 700;
  background: linear-gradient(135deg, var(--ink-900), var(--brand-700));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.auth-brand p { margin: 0; font-weight: 500; }
.muted { color: var(--ink-500); font-size: 14px; }

@media (max-width: 520px) {
  .auth-card { padding: 28px 22px; border-radius: 20px; }
  .auth-brand h1 { font-size: 17px; white-space: normal; }
  .auth-brand .brand-icon { width: 64px; height: 64px; font-size: 30px; border-radius: 18px; }
}

/* ============ FORM ============ */
.form-row { margin-bottom: 16px; }
.form-row label {
  display: block;
  font-weight: 600;
  margin-bottom: 7px;
  font-size: 14px;
  color: var(--ink-700);
}
.form-row label .req { color: var(--danger); margin-left: 2px; }
.input, select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--ink-200);
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  background: #fff;
  color: var(--ink-900);
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.input:hover, select:hover, textarea:hover { border-color: var(--ink-300); }
.input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 4px rgba(59,130,246,.15);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.6; }
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-help { font-size: 12.5px; color: var(--ink-500); margin-top: 5px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.split  { display: grid; grid-template-columns: 1.3fr .9fr; gap: 18px; }

@media (max-width: 1024px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 10px; }
}

/* ============ BUTTON ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  border-radius: 10px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s, background .15s, color .15s, border-color .15s;
  text-decoration: none;
  background: #fff;
  color: var(--ink-900);
  border-color: var(--ink-200);
  white-space: nowrap;
  user-select: none;
  min-height: 40px;
}
.btn:hover { box-shadow: var(--shadow-sm); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.btn-primary {
  background: var(--grad-brand);
  color: #fff !important;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(37,99,235,.3);
}
.btn-primary:hover { box-shadow: 0 8px 20px rgba(37,99,235,.4); }
.btn-secondary { background: var(--ink-100); }
.btn-secondary:hover { background: var(--ink-200); }
.btn-success { background: var(--grad-success); color: #fff !important; border-color: transparent; box-shadow: 0 4px 12px rgba(22,163,74,.3); }
.btn-warn    { background: var(--grad-warn);    color: #fff !important; border-color: transparent; }
.btn-danger  { background: var(--grad-danger);  color: #fff !important; border-color: transparent; box-shadow: 0 4px 12px rgba(220,38,38,.25); }
.btn-ghost   { background: transparent; border-color: var(--ink-200); }
.btn-ghost:hover { background: var(--ink-50); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; min-height: 32px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ============ ALERT / FLASH ============ */
.alert { padding: 12px 14px; border-radius: 12px; font-weight: 500; margin: 8px 0 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert::before { font-size: 18px; line-height: 1; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-success::before { content: '✅'; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-error::before { content: '⚠️'; }
.alert-warn    { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-warn::before { content: '⚡'; }
.alert-info    { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }
.alert-info::before { content: 'ℹ️'; }

.toast-wrap {
  position: fixed; right: 20px; top: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  max-width: calc(100% - 40px);
}
.toast {
  background: #fff; border-left: 4px solid var(--brand-500);
  padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow-lg); min-width: 260px; max-width: 380px;
  animation: slideIn .3s cubic-bezier(.16,1,.3,1);
  font-weight: 500;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warn    { border-color: var(--warn); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@media (max-width: 600px) {
  .toast-wrap { right: 10px; left: 10px; top: 10px; }
  .toast { min-width: 0; max-width: 100%; }
}

/* ============ APP LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: linear-gradient(180deg, #1e3a8a 0%, #0f172a 100%);
  color: #e6eefc;
  padding: 18px 14px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(15,23,42,.06);
}
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-color: transparent; }
.sidebar .brand {
  display: flex; gap: 11px; align-items: center;
  padding: 4px 8px 16px; border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 14px;
}
.sidebar .brand .logo {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  border-radius: 13px; display: grid; place-items: center;
  font-size: 22px; box-shadow: 0 6px 16px rgba(59,130,246,.5), inset 0 1px 0 rgba(255,255,255,.3);
  flex-shrink: 0;
}
.sidebar .brand h2 { font-size: 15px; margin: 0; letter-spacing: .2px; color: #fff; font-weight: 700; }
.sidebar .brand small { color: #94a3b8; font-size: 11.5px; display: block; margin-top: 1px; }

.sidebar .nav-group { margin-top: 6px; }
.sidebar .nav-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.4px;
  color: #94a3b8; padding: 12px 12px 6px; font-weight: 700;
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px;
  color: #cbd5e1; font-weight: 500; font-size: 14.5px;
  margin-bottom: 2px; transition: background .15s, color .15s, transform .15s;
  text-decoration: none;
  position: relative;
}
.sidebar a.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar a.nav-item.active {
  background: linear-gradient(90deg, rgba(59,130,246,.25), rgba(59,130,246,.05));
  color: #fff; font-weight: 600;
}
.sidebar a.nav-item.active::before {
  content: '';
  position: absolute; left: -14px; top: 8px; bottom: 8px;
  width: 4px; border-radius: 0 4px 4px 0;
  background: var(--accent-500);
}
.sidebar .nav-item .ico { width: 22px; display: inline-block; text-align: center; font-size: 16px; }

.sidebar .user-box {
  margin-top: auto; border-top: 1px solid rgba(255,255,255,.1);
  padding-top: 14px;
}
.sidebar .user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; background: rgba(255,255,255,.05); border-radius: 12px;
  border: 1px solid rgba(255,255,255,.06);
}
.sidebar .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-400), var(--accent-600));
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(217,119,6,.4);
}
.sidebar .user-card .name { font-size: 13.5px; color: #fff; font-weight: 600; line-height: 1.25; word-break: break-word; }
.sidebar .user-card .role { font-size: 11.5px; color: #94a3b8; margin-top: 1px; word-break: break-word; }
.sidebar .logout {
  margin-top: 10px; color: #fff !important;
  border-color: rgba(255,255,255,.18); background: rgba(255,255,255,.05);
}
.sidebar .logout:hover { background: rgba(255,255,255,.12); }

/* main */
.main { padding: 22px 30px 60px; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; margin-bottom: 22px; flex-wrap: wrap;
}
.topbar h1 {
  font-size: 22px; margin: 0;
  color: var(--ink-900); letter-spacing: .2px; font-weight: 700;
}
.topbar .crumb { font-size: 13px; color: var(--ink-500); margin-top: 3px; }
.topbar .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar .tools .btn { min-height: 36px; }

/* ============ CARD ============ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--ink-200);
  box-shadow: var(--shadow-xs);
  padding: 22px;
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 18px; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: -4px 0 16px; gap: 12px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 17px; font-weight: 700; }

/* ============ STAT CARDS ============ */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border-radius: 16px;
  padding: 20px 22px; border: 1px solid var(--ink-200);
  box-shadow: var(--shadow-xs);
  position: relative; overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--grad-brand);
}
.stat .label { color: var(--ink-500); font-size: 13.5px; font-weight: 500; padding-right: 56px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .num { font-size: 32px; font-weight: 700; margin-top: 6px; color: var(--ink-900); line-height: 1.1; letter-spacing: -.5px; }
.stat .ico {
  position: absolute; right: 16px; top: 16px;
  width: 46px; height: 46px; border-radius: 13px;
  display: grid; place-items: center; font-size: 22px;
  color: #fff;
  box-shadow: var(--shadow-md);
}
.stat.brand   { } .stat.brand   .ico { background: var(--grad-brand); }
.stat.warn    { } .stat.warn    .ico { background: var(--grad-warn); }
.stat.warn::before    { background: var(--grad-warn); }
.stat.info    { } .stat.info    .ico { background: var(--grad-info); }
.stat.info::before    { background: var(--grad-info); }
.stat.success { } .stat.success .ico { background: var(--grad-success); }
.stat.success::before { background: var(--grad-success); }
.stat.danger  { } .stat.danger  .ico { background: var(--grad-danger); }
.stat.danger::before  { background: var(--grad-danger); }
.stat.purple  { } .stat.purple  .ico { background: var(--grad-purple); }
.stat.purple::before  { background: var(--grad-purple); }

@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px 16px; border-radius: 14px; }
  .stat .label { font-size: 12px; padding-right: 40px; }
  .stat .num { font-size: 22px; }
  .stat .ico { width: 34px; height: 34px; font-size: 16px; right: 10px; top: 10px; border-radius: 10px; }
}
@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr; }
}

/* ============ TABLE ============ */
.table-wrap {
  overflow-x: auto; border-radius: 12px; border: 1px solid var(--ink-200);
  -webkit-overflow-scrolling: touch;
}
table.table {
  width: 100%; border-collapse: collapse; background: #fff;
  font-size: 14.5px; min-width: 600px;
}
.table thead th {
  background: var(--ink-50); color: var(--ink-700);
  text-align: left; font-weight: 600;
  padding: 12px 14px; border-bottom: 1px solid var(--ink-200);
  font-size: 13px; text-transform: none; letter-spacing: .1px;
  position: sticky; top: 0;
}
.table tbody td {
  padding: 12px 14px; border-bottom: 1px solid var(--ink-100); vertical-align: top;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: linear-gradient(90deg, #f8fafc, #fff); }
.table tbody tr:last-child td { border-bottom: none; }
.table .actions { white-space: nowrap; display: flex; gap: 4px; flex-wrap: wrap; }
.table .empty { text-align: center; color: var(--ink-500); padding: 40px 0; }

/* hint scroll on mobile */
.table-wrap { position: relative; }
@media (max-width: 800px) {
  .table-wrap::after {
    content: '← เลื่อนซ้าย-ขวา';
    position: absolute; right: 8px; bottom: 6px;
    font-size: 11px; color: var(--ink-400);
    background: rgba(255,255,255,.85);
    padding: 2px 8px; border-radius: 99px;
    pointer-events: none;
  }
}

/* ============ BADGE ============ */
.badge {
  display: inline-block; padding: 3px 10px; font-size: 12.5px;
  font-weight: 600; border-radius: 999px; line-height: 1.6;
  white-space: nowrap;
}
.badge-wait   { background: #f1f5f9; color: #334155; }
.badge-recv   { background: #e0f2fe; color: #075985; }
.badge-fwd    { background: #ede9fe; color: #5b21b6; }
.badge-fix    { background: #fef3c7; color: #92400e; }
.badge-done   { background: #dcfce7; color: #166534; }
.badge-cancel { background: #fee2e2; color: #991b1b; }
.badge-admin  { background: #fde68a; color: #78350f; }
.badge-user   { background: #e0eaff; color: #1e40af; }

.pri {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pri-normal { background: #e2e8f0; color: #334155; }
.pri-high   { background: #fed7aa; color: #9a3412; }
.pri-urgent { background: #fecaca; color: #991b1b; }

/* ============ MODAL ============ */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: none; z-index: 999; backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center; justify-content: center; padding: 20px;
}
.modal-bg.show { display: flex; animation: fadeIn .15s ease; }
.modal {
  background: #fff; border-radius: 18px; max-width: 560px; width: 100%;
  box-shadow: var(--shadow-xl); overflow: hidden;
  animation: scaleIn .25s cubic-bezier(.16,1,.3,1);
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
}
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--ink-200); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--ink-200); background: var(--ink-50); display: flex; gap: 10px; justify-content: flex-end; flex-shrink: 0; flex-wrap: wrap; }
.modal-close { background: transparent; border: 0; font-size: 24px; cursor: pointer; color: var(--ink-500); width: 32px; height: 32px; border-radius: 8px; }
.modal-close:hover { background: var(--ink-100); color: var(--ink-900); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.92) translateY(8px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

@media (max-width: 600px) {
  .modal-bg { padding: 12px; align-items: flex-end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 90vh; }
}

.confirm-icon {
  width: 68px; height: 68px; margin: 0 auto 14px;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 34px; background: #fef3c7; color: #b45309;
  box-shadow: 0 0 0 8px rgba(254,243,199,.5);
}
.confirm-text { text-align: center; }
.confirm-text h4 { margin: 4px 0 6px; font-size: 18px; font-weight: 700; }
.confirm-text p { margin: 0; color: var(--ink-500); font-size: 14px; }

.review-box {
  background: var(--ink-50); border-radius: 12px; padding: 14px 16px;
  margin: 12px 0; border: 1px dashed var(--ink-300);
}
.review-box dt { font-weight: 600; color: var(--ink-700); font-size: 13px; }
.review-box dd { margin: 0 0 8px; color: var(--ink-900); }

/* ============ SEARCH BAR / TOOLBAR ============ */
.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .search { flex: 1; min-width: 200px; }
.toolbar .input, .toolbar select { min-height: 40px; }

@media (max-width: 600px) {
  .toolbar { gap: 8px; }
  .toolbar .btn { flex: 1; }
}

/* ============ PAGINATION ============ */
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pager a, .pager span {
  padding: 7px 13px; border-radius: 9px;
  background: #fff; border: 1px solid var(--ink-200);
  color: var(--ink-700); font-weight: 500;
  min-width: 38px; text-align: center;
  transition: all .15s;
}
.pager a:hover { background: var(--ink-50); text-decoration: none; transform: translateY(-1px); }
.pager .current {
  background: var(--grad-brand); color: #fff; border-color: transparent;
  box-shadow: 0 4px 10px rgba(37,99,235,.3);
}

/* ============ TIMELINE ============ */
.timeline { padding-left: 18px; border-left: 2px solid var(--ink-200); }
.timeline .tl-item { position: relative; padding: 6px 0 14px 18px; }
.timeline .tl-item::before {
  content: ''; position: absolute; left: -7px; top: 12px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand-500); border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--brand-500);
}
.timeline .tl-time { font-size: 12.5px; color: var(--ink-500); }
.timeline .tl-text { font-size: 14px; }

/* ============ PROGRESS BARS ============ */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { width: 100px; font-size: 13.5px; color: var(--ink-700); flex-shrink: 0; }
.bar-bg { flex: 1; background: var(--ink-100); border-radius: 99px; height: 10px; overflow: hidden; min-width: 60px; }
.bar-fg { height: 100%; background: var(--grad-brand); border-radius: 99px; transition: width .8s cubic-bezier(.16,1,.3,1); }
.bar-val { width: 40px; text-align: right; font-size: 13px; color: var(--ink-700); font-weight: 600; flex-shrink: 0; }

@media (max-width: 480px) {
  .bar-label { width: auto; max-width: 110px; font-size: 12.5px; }
}

/* ============ INSTALL LOG ============ */
.install-log { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 12px; font-family: Consolas, Monaco, monospace; font-size: 13.5px; max-height: 280px; overflow-y: auto; margin-bottom: 14px; }
.log-line.ok { color: #86efac; }
.log-line.err { color: #fca5a5; }
.log-line.info { color: #fcd34d; }

/* ============ RESPONSIVE LAYOUT ============ */
.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1024px) {
  .main { padding: 18px 20px 60px; }
  .stats { gap: 12px; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: -300px; top: 0; bottom: 0; width: 280px;
    z-index: 200; transition: left .25s cubic-bezier(.16,1,.3,1);
  }
  .sidebar.open { left: 0; box-shadow: 0 0 60px rgba(0,0,0,.5); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.5); z-index: 150;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0; transition: opacity .2s;
  }
  .sidebar-backdrop.show { display: block; animation: fadeIn .2s forwards; }
  .sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--ink-200);
    background: #fff; cursor: pointer; font-size: 20px;
    box-shadow: var(--shadow-xs);
    transition: all .15s;
  }
  .sidebar-toggle:hover { background: var(--ink-50); }
  .topbar h1 { font-size: 19px; }
}

@media (max-width: 600px) {
  .main { padding: 14px 14px 40px; }
  .card { padding: 16px; border-radius: 14px; }
  .topbar { margin-bottom: 16px; }
  .topbar h1 { font-size: 17px; }
  .topbar .crumb { font-size: 12.5px; }
  .topbar .tools { width: 100%; }
  .topbar .tools .btn { flex: 1; min-height: 38px; font-size: 13.5px; padding: 8px 10px; }
  .card-head h2 { font-size: 15.5px; }
  .table thead th, .table tbody td { padding: 10px 12px; font-size: 13.5px; }
  .btn-sm { font-size: 12px; padding: 6px 9px; }
}

@media (max-width: 380px) {
  .main { padding: 12px 10px 30px; }
  .stat .num { font-size: 20px; }
  .topbar h1 { font-size: 16px; }
}

/* Fade-in for content (subtle) */
.main > * { animation: fadeUp .35s cubic-bezier(.16,1,.3,1); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============ PRINT (A4 REPORT) ============ */
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
}

.a4-sheet {
  width: 21cm;
  min-height: 29.7cm;
  padding: 2.5cm 2.5cm 2cm;
  background: #fff;
  margin: 20px auto;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  font-family: 'Sarabun', 'TH Sarabun New', 'TH SarabunPSK', serif;
  font-size: 14pt;
  line-height: 1.7;
  color: #000;
}
@page { size: A4; margin: 0; }
@media print {
  .a4-sheet { margin: 0; box-shadow: none; width: 100%; min-height: 100vh; }
}
.a4-title {
  font-size: 24pt;
  font-weight: 700;
  text-align: center;
  margin-bottom: 22pt;
}
.a4-right  { text-align: right; }
.a4-indent { text-indent: 3em; }
.a4-sign   { margin-top: 40pt; text-align: center; }
.a4-sign .line { display: inline-block; min-width: 260px; border-bottom: 1px dotted #000; }
.a4-ticket { text-align: right; color: #555; font-size: 11pt; margin-bottom: 8pt; }

.print-actions {
  max-width: 21cm; margin: 14px auto 0; text-align: center;
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 0 12px;
}
@media (max-width: 800px) {
  .a4-sheet { width: 100%; max-width: 21cm; padding: 1.6cm 1.4cm 1.4cm; }
}

/* ============ DASHBOARD WIDGETS ============ */
.stat .trend {
  margin-top: 10px; font-size: 12.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px;
  background: var(--ink-50); color: var(--ink-500);
}
.stat .trend.muted-trend { background: var(--ink-50); color: var(--ink-500); }
.stat .trend.up   { background: #dcfce7; color: #15803d; }
.stat .trend.down { background: #fee2e2; color: #b91c1c; }

/* Donut chart */
.donut-wrap {
  display: grid; grid-template-columns: 200px 1fr;
  gap: 28px; align-items: center; padding: 8px 0;
}
.donut {
  width: 200px; height: 200px; border-radius: 50%;
  background: var(--ring); position: relative;
  display: grid; place-items: center;
  filter: drop-shadow(0 4px 12px rgba(15,23,42,.08));
}
.donut::before {
  content: ''; position: absolute; inset: 22%;
  border-radius: 50%; background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--ink-100);
}
.donut-center { position: relative; text-align: center; z-index: 1; }
.donut-num {
  font-size: 30px; font-weight: 800; color: var(--ink-900);
  letter-spacing: -.5px; line-height: 1;
}
.donut-label { font-size: 12px; color: var(--ink-500); margin-top: 4px; }
.donut-legend { display: flex; flex-direction: column; gap: 4px; }
.legend-row {
  display: grid; grid-template-columns: 14px 1fr auto auto;
  gap: 12px; align-items: center;
  font-size: 13.5px; padding: 7px 10px; border-radius: 10px;
  transition: background .15s;
}
.legend-row:hover { background: var(--ink-50); }
.legend-row .dot {
  width: 11px; height: 11px; border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255,255,255,.6);
}
.legend-label { color: var(--ink-700); font-weight: 500; }
.legend-pct {
  color: var(--ink-500); font-size: 12px;
  min-width: 36px; text-align: right; font-variant-numeric: tabular-nums;
}
.legend-num {
  font-weight: 700; color: var(--ink-900);
  font-size: 14px; min-width: 42px; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* 14-day trend chart */
.trend-chart { padding: 6px 0 0; }
.trend-svg { width: 100%; height: 130px; display: block; overflow: visible; }
.trend-axis {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--ink-400);
  margin-top: 6px; padding: 0 2px;
  font-variant-numeric: tabular-nums;
}
.trend-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; margin-top: 16px; padding-top: 16px;
  border-top: 1px dashed var(--ink-200); text-align: center;
}
.bignum {
  font-size: 22px; font-weight: 800; color: var(--ink-900);
  letter-spacing: -.3px; font-variant-numeric: tabular-nums;
}

/* Top divisions ranked */
.div-row {
  display: grid; grid-template-columns: 32px 1fr auto;
  gap: 14px; align-items: center; margin-bottom: 12px;
}
.div-rank {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink-100); color: var(--ink-700);
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px;
}
.div-rank.rank-1 { background: linear-gradient(135deg, #fbbf24, #d97706); color: #fff; box-shadow: 0 4px 10px rgba(217,119,6,.3); }
.div-rank.rank-2 { background: linear-gradient(135deg, #cbd5e1, #64748b); color: #fff; box-shadow: 0 4px 10px rgba(100,116,139,.25); }
.div-rank.rank-3 { background: linear-gradient(135deg, #fb923c, #c2410c); color: #fff; box-shadow: 0 4px 10px rgba(194,65,12,.25); }
.div-body { min-width: 0; }
.div-name {
  font-size: 13.5px; font-weight: 600; color: var(--ink-700);
  margin-bottom: 5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.div-num {
  font-weight: 800; color: var(--ink-900); font-size: 17px;
  font-variant-numeric: tabular-nums; min-width: 32px; text-align: right;
}

.mini-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; text-align: center;
}
.mini-grid .muted { font-size: 12.5px; }

/* KPI tiles */
.kpi-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.kpi {
  background: linear-gradient(180deg, var(--ink-50), #fff);
  border: 1px solid var(--ink-100);
  border-radius: 14px; padding: 18px 16px; text-align: center;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--ink-200);
}
.kpi-label {
  font-size: 12.5px; color: var(--ink-500);
  margin-bottom: 10px; font-weight: 600;
  letter-spacing: .2px;
}
.kpi-num {
  font-size: 28px; font-weight: 800; color: var(--ink-900);
  letter-spacing: -.5px; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-num .kpi-unit {
  font-size: 14px; color: var(--ink-500);
  font-weight: 600; margin-left: 4px;
}
.kpi-sub { font-size: 11.5px; color: var(--ink-400); margin-top: 6px; }

.kpi-ring {
  width: 84px; height: 84px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--ink-200) 0);
  display: grid; place-items: center;
  margin: 4px auto 0; position: relative;
  filter: drop-shadow(0 2px 6px rgba(15,23,42,.08));
}
.kpi-ring::before {
  content: ''; position: absolute; inset: 8px;
  border-radius: 50%; background: var(--surface);
}
.kpi-ring-num {
  position: relative; font-size: 17px; font-weight: 800;
  color: var(--ink-900); font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; gap: 18px; }
  .donut { width: 170px; height: 170px; }
  .donut-num { font-size: 26px; }
  .donut-legend { width: 100%; }
}
@media (max-width: 480px) {
  .kpi { padding: 14px 10px; }
  .kpi-num { font-size: 22px; }
  .kpi-ring { width: 70px; height: 70px; }
  .kpi-ring-num { font-size: 14px; }
}

/* ============ NOTIFICATIONS (Facebook-like) ============ */
.notif { position: relative; display: inline-flex; }
.notif-btn {
  background: var(--ink-50); border: 1px solid var(--ink-200);
  border-radius: 50%; width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; transition: background .15s, transform .15s;
  padding: 0;
}
.notif-btn:hover { background: var(--ink-100); }
.notif-btn:active { transform: scale(.95); }
.notif-btn .bell { font-size: 18px; line-height: 1; }
.notif-btn.has-unread .bell { animation: bellRing 1.6s ease-in-out 1; transform-origin: top center; }
@keyframes bellRing {
  0%, 100% { transform: rotate(0); }
  10%, 30%, 50% { transform: rotate(-14deg); }
  20%, 40%, 60% { transform: rotate(14deg); }
  70% { transform: rotate(-6deg); }
  80% { transform: rotate(6deg); }
  90% { transform: rotate(0); }
}
.notif-badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; display: inline-flex;
  align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px var(--surface);
}
.notif-panel {
  position: absolute; top: calc(100% + 10px); right: 0;
  width: 380px; max-width: 92vw;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  animation: notifFade .18s ease-out;
}
@keyframes notifFade {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.notif-head {
  padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--ink-100);
}
.notif-head h3 {
  margin: 0; font-size: 17px; font-weight: 700; color: var(--ink-900);
}
.notif-mark {
  background: none; border: none; color: var(--brand-600);
  font-size: 12.5px; cursor: pointer; padding: 4px 6px;
  border-radius: var(--radius-xs); font-weight: 500;
}
.notif-mark:hover { background: var(--brand-50); text-decoration: none; }
.notif-list { max-height: 440px; overflow-y: auto; }
.notif-list::-webkit-scrollbar { width: 8px; }
.notif-list::-webkit-scrollbar-thumb { background: var(--ink-200); border-radius: 4px; }
.notif-item {
  display: flex; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--ink-100);
  text-decoration: none; color: inherit;
  transition: background .15s;
  position: relative;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--ink-50); }
.notif-item.unread { background: var(--brand-50); }
.notif-item.unread:hover { background: var(--brand-100); }
.notif-item .ico {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--ink-100);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.notif-item.urgent .ico { background: #fee2e2; }
.notif-item .body { flex: 1; min-width: 0; }
.notif-item .title {
  font-weight: 600; font-size: 13.5px; line-height: 1.4;
  color: var(--ink-800);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.notif-item .meta {
  font-size: 12px; color: var(--ink-500); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-item .time {
  font-size: 12px; color: var(--brand-600); margin-top: 4px; font-weight: 500;
}
.notif-item .notif-dot {
  width: 10px; height: 10px; background: var(--brand-600); border-radius: 50%;
  flex-shrink: 0; align-self: center; box-shadow: 0 0 0 3px var(--brand-100);
}
.notif-empty {
  padding: 38px 16px; text-align: center; color: var(--ink-500); font-size: 13.5px;
}
.notif-foot {
  padding: 10px 16px; text-align: center;
  border-top: 1px solid var(--ink-100);
  background: var(--ink-50);
}
.notif-foot a {
  color: var(--brand-600); font-size: 13px; text-decoration: none; font-weight: 600;
}
.notif-foot a:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .notif-panel { width: calc(100vw - 24px); right: -8px; }
}
