/* ── Custom properties ─────────────────────────────────────────────────────── */
:root {
  --color-primary:  #fa7921;
  --color-info:     #0f82aa;
  --color-success:  #10b981;
  --color-danger:   #ef4444;
  --color-warning:  #f59e0b;

  --sidebar-w: 260px;
  --header-h:  64px;

  --font-sans: 'Sarabun', 'Inter', system-ui, sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  background: #f1f5f9;
  color: #1e293b;
  transition: background 0.2s, color 0.2s;
}

/* ── Dark mode base ───────────────────────────────────────────────────────── */
html.dark body            { background: #0f172a; color: #e2e8f0; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout        { display: flex; min-height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform 0.25s ease;
  overflow-y: auto;
}
html.dark .sidebar { background: #0f172a; }

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo .logo-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}
.sidebar-logo .logo-sub {
  font-size: .72rem;
  color: #94a3b8;
  margin-top: 2px;
}

.nav-section {
  padding: 12px 12px 4px;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #475569;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 2px 8px;
  border-radius: 8px;
  color: #94a3b8;
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item:hover             { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active            { background: var(--color-primary); color: #fff; }
.nav-item .nav-icon         { width: 18px; text-align: center; flex-shrink: 0; font-size: 1rem; }
.nav-item .nav-badge        {
  margin-left: auto;
  background: rgba(255,255,255,.15);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: .7rem;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  z-index: 30;
  transition: background .2s, border-color .2s;
}
html.dark .header { background: #1e293b; border-color: #334155; }

.header-title  { font-weight: 600; font-size: 1rem; flex: 1; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  padding: 24px;
  flex: 1;
  min-width: 0;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  border: 1px solid #e2e8f0;
}
html.dark .card { background: #1e293b; border-color: #334155; }

.stat-card {
  padding: 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid transparent;
}
.stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: filter .15s, transform .1s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--color-primary); color: #fff; }
.btn-info     { background: var(--color-info);    color: #fff; }
.btn-success  { background: var(--color-success); color: #fff; }
.btn-danger   { background: var(--color-danger);  color: #fff; }
.btn-ghost    { background: transparent; color: #64748b; border: 1px solid #e2e8f0; }
.btn-sm       { padding: 5px 10px; font-size: .8rem; }
.btn-lg       { padding: 11px 22px; font-size: 1rem; }

html.dark .btn-ghost { color: #94a3b8; border-color: #334155; }
.btn-primary:hover  { filter: brightness(1.08); }
.btn-danger:hover   { filter: brightness(1.08); }
.btn-success:hover  { filter: brightness(1.08); }
.btn-ghost:hover    { background: #f1f5f9; }
html.dark .btn-ghost:hover { background: #0f172a; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group   { margin-bottom: 16px; }
.form-label   { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 5px; color: #64748b; }
html.dark .form-label { color: #94a3b8; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 13px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: .9rem;
  background: #fff;
  color: #1e293b;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: var(--font-sans);
}
html.dark .form-input,
html.dark .form-select,
html.dark .form-textarea { background: #0f172a; border-color: #334155; color: #e2e8f0; }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(250,121,33,.15);
}
.form-input.error { border-color: var(--color-danger); }
.form-error { font-size: .75rem; color: var(--color-danger); margin-top: 4px; }

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: 8px; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.data-table th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
html.dark .data-table th { background: #0f172a; border-color: #334155; color: #94a3b8; }

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}
html.dark .data-table td { border-color: #1e293b; color: #cbd5e1; }
.data-table tbody tr:hover td { background: #f8fafc; }
html.dark .data-table tbody tr:hover td { background: #1e293b; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-success  { background: #d1fae5; color: #065f46; }
.badge-danger   { background: #fee2e2; color: #991b1b; }
.badge-info     { background: #dbeafe; color: #1e40af; }
.badge-warning  { background: #fef3c7; color: #92400e; }
.badge-neutral  { background: #f1f5f9; color: #475569; }

html.dark .badge-success  { background: #064e3b; color: #6ee7b7; }
html.dark .badge-danger   { background: #7f1d1d; color: #fca5a5; }
html.dark .badge-info     { background: #1e3a5f; color: #93c5fd; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; transition: opacity .2s;
}
.modal-backdrop.show { opacity: 1; }

.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: translateY(16px); transition: transform .2s;
}
.modal-backdrop.show .modal { transform: translateY(0); }
html.dark .modal { background: #1e293b; }

.modal-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: space-between;
}
html.dark .modal-header { border-color: #334155; }
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: #94a3b8; line-height: 1; padding: 0; }
.modal-body   { padding: 20px 24px; }
.modal-footer {
  padding: 14px 24px 18px;
  border-top: 1px solid #e2e8f0;
  display: flex; justify-content: flex-end; gap: 8px;
}
html.dark .modal-footer { border-color: #334155; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 4px; }
.page-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 500;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  transition: all .15s;
}
html.dark .page-btn { background: #1e293b; border-color: #334155; color: #94a3b8; }
.page-btn:hover     { border-color: var(--color-primary); color: var(--color-primary); }
.page-btn.active    { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.page-btn:disabled  { opacity: .4; cursor: not-allowed; }

/* ── Loader ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}
html.dark .skeleton {
  background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
  background-size: 200% 100%;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Sidebar toggle on mobile ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .header { left: 0; }
  .main   { margin-left: 0; }
  .overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 35;
  }
  .overlay.show { display: block; }
}

/* ── Search input ─────────────────────────────────────────────────────────── */
.search-box {
  position: relative;
  display: flex; align-items: center;
}
.search-box input {
  padding-left: 36px;
}
.search-box .search-icon {
  position: absolute;
  left: 11px;
  color: #94a3b8;
  font-size: .95rem;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 48px 24px;
  color: #94a3b8;
  gap: 12px;
  text-align: center;
}
.empty-state .empty-icon { font-size: 3rem; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.text-muted     { color: #94a3b8; }
.text-primary   { color: var(--color-primary); }
.text-success   { color: var(--color-success); }
.text-danger    { color: var(--color-danger); }
.text-info      { color: var(--color-info); }
.font-mono      { font-family: 'JetBrains Mono', monospace; }
.truncate       { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gap-row        { display: flex; align-items: center; gap: 8px; }
.grid-2         { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-4         { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }
