/* ================================================================
   SCHOOL COOPERATIVE SYSTEM — DESIGN SYSTEM
   White • Blue • Yellow Theme • Sarabun Font
================================================================ */

/* ── VARIABLES ─────────────────────────────────────────── */
:root {
  --bg: #eef2ff;
  --bg2: #ffffff;
  --bg3: #e0e7ff;
  --surface: rgba(255, 255, 255, 0.97);
  --surface2: rgba(240, 245, 255, 0.9);
  --border: rgba(29, 78, 216, 0.1);
  --border2: rgba(29, 78, 216, 0.2);

  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-light: #3b82f6;
  --primary-glow: rgba(29, 78, 216, 0.18);
  --primary-bg: rgba(29, 78, 216, 0.06);

  --sky: #0284c7;
  --indigo: #4f46e5;
  --amber: #d97706;
  --yellow: #f59e0b;
  --rose: #dc2626;
  --purple: #7c3aed;

  --success: #047857;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #1d4ed8;

  --text: #0f172a;
  --text-2: #334155;
  --text-3: #64748b;

  --sidebar-bg: #1a3a6b;
  --sidebar-w: 260px;
  --sidebar-cw: 72px;
  --topbar-h: 60px;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 24px;

  --sh-sm: 0 2px 8px rgba(15, 23, 42, .07);
  --sh-md: 0 4px 20px rgba(15, 23, 42, .1);
  --sh-lg: 0 8px 40px rgba(15, 23, 42, .14);
  --sh-glow: 0 0 24px var(--primary-glow);

  --ease: cubic-bezier(.4, 0, .2, 1);
  --dur: .2s;
  --dur-slow: .35s;
}

/* ── RESET ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input,
select,
textarea {
  font-family: inherit;
}

ul,
ol {
  list-style: none;
}

img {
  max-width: 100%;
}

/* ── SCROLLBAR ─────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .15);
  border-radius: 99px;
}

/* ── UTILITY ───────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.flex {
  display: flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-2 {
  gap: 8px;
}

.gap-3 {
  gap: 12px;
}

.gap-4 {
  gap: 16px;
}

.mt-1 {
  margin-top: 4px;
}

.mt-2 {
  margin-top: 8px;
}

.mt-3 {
  margin-top: 12px;
}

.mt-4 {
  margin-top: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.text-sm {
  font-size: .825rem;
}

.text-muted {
  color: var(--text-2);
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.font-bold {
  font-weight: 700;
}

.font-semibold {
  font-weight: 600;
}

.w-full {
  width: 100%;
}

/* ── GLASS CARD ─────────────────────────────────────────── */
.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--r-lg);
}

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

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===================================================================
   LOGIN SCREEN
=================================================================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 45%, #ffffff 72%, #fef9c3 100%);
  position: relative;
  overflow: hidden;
}

/* Animated orbs */
.login-orbs {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .13;
  animation: floatOrb 8s ease-in-out infinite alternate;
}

.orb-1 {
  width: 400px;
  height: 400px;
  background: var(--primary);
  top: -100px;
  left: -100px;
  animation-delay: 0s;
}

.orb-2 {
  width: 300px;
  height: 300px;
  background: #f59e0b;
  bottom: -80px;
  right: -80px;
  animation-delay: 2.5s;
}

.orb-3 {
  width: 250px;
  height: 250px;
  background: var(--indigo);
  top: 50%;
  left: 50%;
  animation-delay: 5s;
}

@keyframes floatOrb {
  from {
    transform: translate(0, 0) scale(1);
  }

  to {
    transform: translate(30px, 20px) scale(1.1);
  }
}

.login-card {
  position: relative;
  z-index: 10;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(29, 78, 216, 0.15);
  border-radius: var(--r-xl);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--sh-lg), 0 0 40px rgba(29, 78, 216, .08);
  backdrop-filter: blur(20px);
  animation: slideUp .5s var(--ease);
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #1d4ed8 0%, #3b82f6 55%, #f59e0b 100%);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-branding {
  text-align: center;
  margin-bottom: 32px;
}

.login-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px var(--primary-glow));
}

.login-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: .9rem;
  color: var(--text-2);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── FIELD ── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: .825rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .03em;
}

.field-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.field-pfx {
  position: absolute;
  left: 13px;
  font-size: .9rem;
  pointer-events: none;
  color: var(--text-3);
  z-index: 1;
}

.field-input {
  width: 100%;
  background: rgba(240, 245, 255, 0.85);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  padding: 11px 14px 11px 40px;
  color: var(--text);
  font-size: .95rem;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  outline: none;
}

.field-input::placeholder {
  color: var(--text-3);
}

.field-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.field-eye {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-3);
  transition: color var(--dur);
}

.field-eye:hover {
  color: var(--text);
}

.login-error {
  background: rgba(239, 68, 68, .12);
  border: 1px solid rgba(239, 68, 68, .3);
  color: var(--rose);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: .875rem;
  text-align: center;
}

.login-note {
  text-align: center;
  font-size: .775rem;
  color: var(--text-3);
  margin-top: 24px;
}

/* ── BUTTONS ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-size: .9rem;
  font-weight: 600;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
  cursor: pointer;
  border: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: .8rem;
  border-radius: var(--r-sm);
}

.btn-lg {
  padding: 13px 24px;
  font-size: 1rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--r-sm);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--primary-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border2);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, .12);
}

.btn-danger {
  background: rgba(239, 68, 68, .12);
  color: var(--rose);
  border: 1px solid rgba(239, 68, 68, .25);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, .2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

.btn-sky {
  background: rgba(56, 189, 248, .12);
  color: var(--sky);
  border: 1px solid rgba(56, 189, 248, .25);
}

.btn-sky:hover {
  background: rgba(56, 189, 248, .2);
}

.btn-amber {
  background: rgba(251, 191, 36, .12);
  color: var(--amber);
  border: 1px solid rgba(251, 191, 36, .25);
}

.btn-amber:hover {
  background: rgba(251, 191, 36, .2);
}

/* ── BADGE ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
}

.badge-success {
  background: rgba(4, 120, 87, .1);
  color: #047857;
}

.badge-warning {
  background: rgba(217, 119, 6, .12);
  color: #d97706;
}

.badge-danger {
  background: rgba(220, 38, 38, .1);
  color: #dc2626;
}

.badge-info {
  background: rgba(29, 78, 216, .1);
  color: #1d4ed8;
}

.badge-purple {
  background: rgba(124, 58, 237, .1);
  color: #7c3aed;
}

.badge-sky {
  background: rgba(2, 132, 199, .1);
  color: #0284c7;
}

.badge-neutral {
  background: rgba(100, 116, 139, .1);
  color: #64748b;
}

/* ===================================================================
   APP LAYOUT
=================================================================== */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #1a3a6b;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  transition: width var(--dur-slow) var(--ease);
  position: relative;
  z-index: 200;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-cw);
}

/* Sidebar header */
.sb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.sb-brand-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.sb-brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sb-brand-name {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.sb-brand-ver {
  font-size: .7rem;
  color: var(--text-3);
}

.sidebar.collapsed .sb-brand-text {
  display: none;
}

.sb-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 1.1rem;
  font-weight: bold;
  background: var(--surface2);
  transition: transform var(--dur-slow) var(--ease), background var(--dur);
  flex-shrink: 0;
}

.sb-toggle:hover {
  background: var(--surface2);
  color: var(--text);
}

.sidebar.collapsed .sb-toggle {
  transform: rotate(180deg);
}

/* Sidebar nav */
.sb-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  margin-bottom: 6px;
}

.nav-section-label {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-3);
  text-transform: uppercase;
  padding: 8px 8px 4px;
  white-space: nowrap;
  overflow: hidden;
  display: block;
}

.sidebar.collapsed .nav-section-label {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: .9rem;
  font-weight: 500;
  transition: background var(--dur), color var(--dur), padding var(--dur-slow);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);
}

.nav-icon {
  font-size: 1.05rem;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar.collapsed .nav-label {
  display: none;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .nav-item.active {
  box-shadow: inset 0 -2px 0 var(--primary);
}

/* Sidebar footer */
.sb-foot {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.sb-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.sb-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-bg);
  border: 2px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .9rem;
  color: var(--primary);
  flex-shrink: 0;
}

.sb-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sb-user-name {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-user-role {
  font-size: .72rem;
  color: var(--primary);
  font-weight: 500;
}

.sidebar.collapsed .sb-user-text {
  display: none;
}

.sidebar.collapsed .sb-logout {
  display: none;
}

.sb-logout {
  padding: 7px;
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: .95rem;
  transition: background var(--dur), color var(--dur);
  flex-shrink: 0;
}

.sb-logout:hover {
  background: rgba(239, 68, 68, .12);
  color: var(--rose);
}

/* ── TOPBAR ──────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 16px rgba(15, 23, 42, .06);
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  z-index: 100;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.burger {
  padding: 6px 8px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 1.1rem;
  transition: background var(--dur), color var(--dur);
  display: none;
}

.burger:hover {
  background: var(--surface2);
  color: var(--text);
}

.page-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.topbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.topbar-time {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.topbar-date {
  font-size: .75rem;
  color: var(--text-2);
}

/* ── PAGE AREA ──────────────────────────────────────────── */
.page-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.page-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── KPI CARDS ──────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform var(--dur), box-shadow var(--dur);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.kpi-card.green::before {
  background: var(--primary);
}

.kpi-card.sky::before {
  background: var(--sky);
}

.kpi-card.amber::before {
  background: var(--amber);
}

.kpi-card.purple::before {
  background: var(--purple);
}

.kpi-card.rose::before {
  background: var(--rose);
}

.kpi-card.indigo::before {
  background: var(--indigo);
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--sh-md);
}

.kpi-icon {
  font-size: 1.6rem;
  margin-bottom: 2px;
}

.kpi-label {
  font-size: .78rem;
  color: var(--text-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}

.kpi-sub {
  font-size: .78rem;
  color: var(--text-3);
}

/* ── GRID LAYOUTS ───────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

/* ── TABLE ──────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-lg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table thead th {
  background: rgba(29, 78, 216, .04);
  padding: 12px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
}

.data-table tbody tr:hover td {
  background: rgba(29, 78, 216, .04);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.table-actions {
  display: flex;
  gap: 6px;
}

/* ── SEARCH & TOOLBAR ───────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: .95rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 14px 9px 36px;
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: border-color var(--dur);
}

.search-input::placeholder {
  color: var(--text-3);
}

.search-input:focus {
  border-color: var(--primary);
}

/* ── FORM ───────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.col-span-2 {
  grid-column: span 2;
}

.col-span-3 {
  grid-column: span 3;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-2);
}

.form-label .required {
  color: var(--rose);
  margin-left: 3px;
}

.form-input,
.form-select,
.form-textarea {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  padding: 9px 13px;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  transition: border-color var(--dur), box-shadow var(--dur);
  width: 100%;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-3);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-select {
  appearance: none;
  cursor: pointer;
}

.form-select option {
  background: var(--bg2);
  color: var(--text);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-hint {
  font-size: .75rem;
  color: var(--text-3);
  margin-top: 2px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ── INPUT WITH ADDON ───────────────────────────────────── */
.input-group {
  display: flex;
  align-items: center;
}

.input-group .form-input {
  border-radius: var(--r-md) 0 0 var(--r-md);
  border-right: 0;
}

.input-addon {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text-2);
  padding: 9px 12px;
  font-size: .875rem;
  border-radius: 0 var(--r-md) var(--r-md) 0;
  white-space: nowrap;
}

/* ── MODAL ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
  padding: 16px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--sh-lg);
  animation: slideUp .2s var(--ease);
  overflow: hidden;
}

.modal-box.modal-lg {
  max-width: 780px;
}

.modal-box.modal-sm {
  max-width: 400px;
}

.modal-box.modal-xl {
  max-width: 1000px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  font-size: 1.2rem;
  color: var(--text-2);
  background: var(--surface2);
  transition: background var(--dur), color var(--dur);
}

.modal-close:hover {
  background: rgba(239, 68, 68, .15);
  color: var(--rose);
}

.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ── TOAST ──────────────────────────────────────────────── */
.toast-host {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  max-width: 340px;
}

.toast {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--sh-lg);
  animation: toastIn .25s var(--ease);
  cursor: pointer;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.removing {
  animation: toastOut .25s var(--ease) forwards;
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(60px);
  }
}

.toast-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-msg {
  font-size: .875rem;
  color: var(--text);
  line-height: 1.5;
}

.toast.success {
  border-color: rgba(4, 120, 87, .3);
}

.toast.error {
  border-color: rgba(220, 38, 38, .3);
}

.toast.warning {
  border-color: rgba(217, 119, 6, .3);
}

.toast.info {
  border-color: rgba(29, 78, 216, .3);
}

/* ── ALERT / EMPTY STATE ─────────────────────────────────── */
.alert {
  padding: 14px 18px;
  border-radius: var(--r-md);
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-warning {
  background: rgba(217, 119, 6, .08);
  border: 1px solid rgba(217, 119, 6, .22);
  color: #d97706;
}

.alert-danger {
  background: rgba(220, 38, 38, .08);
  border: 1px solid rgba(220, 38, 38, .22);
  color: #dc2626;
}

.alert-info {
  background: rgba(29, 78, 216, .08);
  border: 1px solid rgba(29, 78, 216, .22);
  color: #1d4ed8;
}

.alert-success {
  background: rgba(4, 120, 87, .08);
  border: 1px solid rgba(4, 120, 87, .22);
  color: #047857;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: .5;
}

.empty-text {
  font-size: 1rem;
  color: var(--text-2);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: .85rem;
}

/* ═══════════════════════════════════════════════════════════
   PAGE: DASHBOARD
═══════════════════════════════════════════════════════════ */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-wrap-sm {
  height: 200px;
}

.chart-wrap-lg {
  height: 300px;
}

.low-stock-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.low-stock-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--r-md);
  border-left: 3px solid var(--rose);
}

.low-stock-name {
  font-weight: 600;
  font-size: .875rem;
}

.low-stock-qty {
  font-size: .8rem;
  color: var(--rose);
  font-weight: 700;
}

/* ═══════════════════════════════════════════════════════════
   PAGE: POS
═══════════════════════════════════════════════════════════ */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 18px;
  height: calc(100vh - var(--topbar-h) - 48px);
}

.pos-products-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

.pos-search-bar {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.pos-product-grid {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  align-content: start;
}

.pos-product-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 12px;
  cursor: pointer;
  transition: all var(--dur);
  text-align: center;
}

.pos-product-card:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
  transform: translateY(-2px);
}

.pos-product-card.out-of-stock {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

.pos-prod-icon {
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.pos-prod-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.3;
}

.pos-prod-price {
  font-size: .9rem;
  font-weight: 700;
  color: var(--primary);
}

.pos-prod-stock {
  font-size: .7rem;
  color: var(--text-3);
  margin-top: 3px;
}

/* Cart panel */
.pos-cart-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.pos-cart-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pos-member-bar {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.pos-cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pos-cart-item {
  background: var(--surface2);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.pos-item-name {
  flex: 1;
  font-size: .875rem;
  font-weight: 600;
}

.pos-item-price {
  font-size: .8rem;
  color: var(--text-2);
}

.pos-item-qty {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pos-qty-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  font-size: 1rem;
  font-weight: bold;
  color: var(--text);
  cursor: pointer;
  transition: background var(--dur);
}

.pos-qty-btn:hover {
  background: var(--primary-bg);
  color: var(--primary);
}

.pos-qty-num {
  font-size: .9rem;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}

.pos-item-subtotal {
  font-size: .875rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 60px;
  text-align: right;
}

.pos-item-del {
  color: var(--text-3);
  font-size: .85rem;
  cursor: pointer;
  transition: color var(--dur);
  padding: 4px;
}

.pos-item-del:hover {
  color: var(--rose);
}

.pos-cart-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.pos-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.pos-total-label {
  font-size: .875rem;
  color: var(--text-2);
}

.pos-total-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
}

.pos-discount-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.pos-discount-row .form-input {
  font-size: .875rem;
  padding: 7px 10px;
}

/* ═══════════════════════════════════════════════════════════
   PAGE: PRODUCTS
═══════════════════════════════════════════════════════════ */
.stock-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stock-bar-track {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .3s;
}

.stock-bar-fill.ok {
  background: var(--primary);
}

.stock-bar-fill.warning {
  background: var(--amber);
}

.stock-bar-fill.danger {
  background: var(--rose);
}

.stock-num {
  font-size: .8rem;
  font-weight: 700;
  min-width: 36px;
  text-align: right;
}

/* ═══════════════════════════════════════════════════════════
   PAGE: POS - RECEIPT
═══════════════════════════════════════════════════════════ */
.receipt-box {
  font-family: 'Courier New', monospace;
  background: #fff;
  color: #000;
  padding: 24px;
  max-width: 320px;
  margin: 0 auto;
  line-height: 1.5;
}

.receipt-box h2 {
  text-align: center;
  font-size: 1rem;
  margin-bottom: 4px;
}

.receipt-box .receipt-shop {
  text-align: center;
  font-size: .8rem;
  margin-bottom: 12px;
}

.receipt-box hr {
  border: none;
  border-top: 1px dashed #000;
  margin: 8px 0;
}

.receipt-box .receipt-row {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
}

.receipt-box .receipt-total {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
  font-weight: bold;
  margin-top: 8px;
}

.receipt-box .receipt-footer {
  text-align: center;
  font-size: .75rem;
  margin-top: 12px;
  color: #555;
}

@media print {
  body>*:not(#receipt-area) {
    display: none !important;
  }

  #receipt-area {
    display: block !important;
  }
}

/* ═══════════════════════════════════════════════════════════
   PAGE: DIVIDEND
═══════════════════════════════════════════════════════════ */
.dividend-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.div-summary-card {
  background: var(--surface2);
  border-radius: var(--r-md);
  padding: 16px;
  text-align: center;
}

.div-summary-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.div-summary-lbl {
  font-size: .78rem;
  color: var(--text-2);
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════
   PAGE: REPORTS
═══════════════════════════════════════════════════════════ */
.report-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

/* ═══════════════════════════════════════════════════════════
   PAGINATION
═══════════════════════════════════════════════════════════ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  font-size: .85rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--dur);
}

.page-btn:hover {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary);
}

.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.page-btn:disabled {
  opacity: .35;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════
   TAB COMPONENT
═══════════════════════════════════════════════════════════ */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  border-radius: var(--r-md);
  padding: 4px;
  margin-bottom: 20px;
  width: fit-content;
}

.tab-btn {
  padding: 7px 18px;
  border-radius: var(--r-sm);
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-2);
  transition: all var(--dur);
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--sh-sm);
}

/* ═══════════════════════════════════════════════════════════
   MISC
═══════════════════════════════════════════════════════════ */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.text-primary {
  color: var(--primary);
}

.text-danger {
  color: var(--rose);
}

.text-amber {
  color: var(--amber);
}

.text-sky {
  color: var(--sky);
}

.loading-spin {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ═══════════════════════════════════════════════════════════
   RECEIPT PRINT AREA
═══════════════════════════════════════════════════════════ */
.receipt-area {
  display: none;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .pos-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: auto;
  }

  .pos-cart-panel {
    max-height: 420px;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .grid-3 {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .col-span-2 {
    grid-column: span 1;
  }

  .col-span-3 {
    grid-column: span 1;
  }

  .report-grid {
    grid-template-columns: 1fr;
  }

  .dividend-summary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    left: -var(--sidebar-w);
    z-index: 500;
    transition: left var(--dur-slow) var(--ease), width var(--dur-slow) var(--ease);
  }

  .sidebar.mobile-open {
    left: 0;
  }

  .burger {
    display: flex;
  }

  .page-area {
    padding: 16px;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .modal-box {
    border-radius: var(--r-lg);
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════
   BARCODE SCANNER
═══════════════════════════════════════════════════════════ */
@keyframes scanLine {

  0%,
  100% {
    top: 20%;
    opacity: 1;
  }

  50% {
    top: 75%;
    opacity: .7;
  }
}

@keyframes scanPulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 var(--primary-glow);
  }

  50% {
    box-shadow: 0 0 0 8px transparent;
  }
}

.barcode-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--primary-bg);
  border: 1px dashed var(--primary);
  border-radius: var(--r-md);
  margin-bottom: 10px;
}

.barcode-zone-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.barcode-zone-label {
  font-size: .75rem;
  color: var(--text-2);
  margin-bottom: 3px;
}

.barcode-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border2);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--text);
  font-size: .9rem;
  outline: none;
  font-family: 'Sarabun', monospace;
  letter-spacing: .05em;
  transition: border-color var(--dur), box-shadow var(--dur);
}

.barcode-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.barcode-input::placeholder {
  color: var(--text-3);
  letter-spacing: 0;
}

.btn-scan {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  color: var(--primary);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--dur);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-scan:hover {
  background: var(--primary);
  color: #fff;
}

.btn-scan.scanning {
  animation: scanPulse 1s ease infinite;
  background: var(--primary);
  color: #fff;
}

/* Camera modal */
.camera-wrap {
  position: relative;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #000;
  margin-bottom: 12px;
}

.camera-video {
  width: 100%;
  display: block;
  max-height: 300px;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-frame {
  width: 220px;
  height: 140px;
  border: 2px solid var(--primary);
  border-radius: 8px;
  box-shadow: 0 0 0 1000px rgba(0, 0, 0, .5);
  position: relative;
}

.scan-frame::before,
.scan-frame::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: var(--primary-light);
  border-style: solid;
}

.scan-frame::before {
  top: -2px;
  left: -2px;
  border-width: 3px 0 0 3px;
  border-radius: 4px 0 0 0;
}

.scan-frame::after {
  bottom: -2px;
  right: -2px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 4px 0;
}

.scan-laser {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: scanLine 2s linear infinite;
  box-shadow: 0 0 8px var(--primary);
}

.scan-status {
  text-align: center;
  font-size: .85rem;
  color: var(--text-2);
  padding: 8px 0;
  min-height: 32px;
}

.scan-status.found {
  color: var(--primary);
  font-weight: 700;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR NAVY BLUE OVERRIDES
═══════════════════════════════════════════════════════════ */
.sidebar .nav-item {
  color: rgba(255, 255, 255, 0.72);
}

.sidebar .nav-item:hover {
  background: rgba(255, 255, 255, 0.09);
  color: rgba(255, 255, 255, 0.95);
}

.sidebar .nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  box-shadow: inset 3px 0 0 #f59e0b;
}

.sidebar .nav-section-label {
  color: rgba(255, 255, 255, 0.35);
}

.sidebar .sb-brand-name {
  color: #ffffff;
}

.sidebar .sb-brand-ver {
  color: rgba(255, 255, 255, 0.4);
}

.sidebar .sb-toggle {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.72);
}

.sidebar .sb-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.sidebar .sb-head {
  border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}

.sidebar .sb-foot {
  border-top-color: rgba(255, 255, 255, 0.08) !important;
}

.sidebar .sb-user-name {
  color: #ffffff;
}

.sidebar .sb-user-role {
  color: #f59e0b;
}

.sidebar .sb-avatar {
  background: rgba(245, 158, 11, 0.15);
  border-color: #f59e0b;
  color: #f59e0b;
}

.sidebar .sb-logout {
  color: rgba(255, 255, 255, 0.5);
}

.sidebar .sb-logout:hover {
  background: rgba(220, 38, 38, 0.12);
  color: #fca5a5;
}

.sidebar.collapsed .nav-item.active {
  box-shadow: inset 0 -2px 0 #f59e0b;
}

/* ═══════════════════════════════════════════════════════════
   UTILITY ADDITIONS
═══════════════════════════════════════════════════════════ */
.text-success {
  color: var(--success);
}

.btn-purple {
  background: rgba(124, 58, 237, .1);
  color: #7c3aed;
  border: 1px solid rgba(124, 58, 237, .25);
}

.btn-purple:hover {
  background: rgba(124, 58, 237, .18);
}

.kpi-card.blue::before {
  background: var(--primary);
}

/* ═══════════════════════════════════════════════════════════
   PAGE: FINANCE (รายรับ-รายจ่าย)
═══════════════════════════════════════════════════════════ */
.fin-filter-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 20px;
  box-shadow: var(--sh-sm);
}