/* Tokens from Figma variables (Pre Sale > Back Office) */
:root {
  --primary: #181871;
  --sidebar: #33408c;
  --link: #2563eb;
  --bg: #f7f8fa;
  --border: #e5e5ea;
  --surface: #ffffff;
  --text: #1f1f29;
  --text-muted: #6b6b78;
  --text-subtle: #8e8e99;
  --thead: #f3f4f6;
  --danger: #dc2626;
  --success: #16a34a;
  --avatar-bg: #eaddff;
  --avatar-fg: #4f378a;
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 87px;
  --sidebar-w: 250px;
  --font: 'Sarabun', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* ---------- Header ---------- */
.header {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h); z-index: 30;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: space-between; padding: 16px 32px;
}
.header .logo { display: block; width: 150px; height: 47px; }
.header .logo img { width: 150px; height: 47px; display: block; }
.header-right { display: flex; align-items: center; gap: 38px; }
.icon-btn { background: none; border: 0; color: inherit; cursor: pointer; padding: 4px; display: inline-flex; border-radius: 8px; position: relative; }
.icon-btn:hover { background: rgba(255,255,255,0.08); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; border: 2px solid var(--primary); }
.user-chip { display: flex; align-items: center; gap: 16px; cursor: pointer; position: relative; background: none; border: 0; color: #fff; padding: 0; }
.user-chip .name { font-weight: 700; font-size: 20px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--avatar-bg); color: var(--avatar-fg); display: grid; place-items: center; font-size: 22px; font-weight: 500; }
.hamburger { display: none; }

.dropdown {
  position: absolute; top: calc(100% + 10px); right: 0; min-width: 240px; background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(24,24,113,0.14); padding: 8px; z-index: 40;
}
.dropdown .dd-label { font-size: 13px; color: var(--text-subtle); padding: 8px 12px 4px; }
.dropdown button { display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.dropdown button:hover { background: var(--bg); }
.dropdown button.on { color: var(--link); font-weight: 600; }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.notif-item { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.notif-item:hover { background: var(--bg); }
.notif-item small { display: block; color: var(--text-subtle); margin-top: 2px; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; top: var(--header-h); left: 0; bottom: 0; width: var(--sidebar-w); z-index: 20;
  background: var(--sidebar); color: #fff; overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 16px; padding: 16px; width: 100%; cursor: pointer;
  background: none; border: 0; color: #fff; font-weight: 500; font-size: 16px; text-align: left; text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.nav-item .label { flex: 1; }
.nav-item svg { flex-shrink: 0; }
.nav-item.active { background: #fff; color: var(--primary); }
.nav-item .chev { transition: transform .15s; }
.nav-group.open > .nav-item .chev { transform: rotate(180deg); }
.nav-sub { display: none; }
.nav-group.open .nav-sub { display: block; }
.nav-sub a {
  display: block; padding: 12px 16px 12px 56px; color: #fff; font-size: 16px; font-weight: 500; text-decoration: none;
}
.nav-sub a:hover { background: rgba(255,255,255,0.06); }
.nav-sub a.active { background: #fff; color: var(--primary); }
.scrim { display: none; }

/* ---------- Main ---------- */
.main { margin-left: var(--sidebar-w); padding: calc(var(--header-h) + 28px) 32px 40px; min-height: 100vh; }
.page { max-width: 1440px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 30px; font-weight: 700; line-height: 1.5; color: var(--text); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.card + .card, .stack > * + * { margin-top: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-title { font-size: 20px; font-weight: 700; }
.card-sub { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-2 > .card + .card { margin-top: 0; }
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 24px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; }
.kpi .k-label { font-size: 16px; color: var(--text-muted); font-weight: 500; }
.kpi .k-value { font-size: 30px; font-weight: 700; margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 41px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: #fff; cursor: pointer; font-weight: 500; font-size: 16px; white-space: nowrap; color: var(--text);
}
.btn:hover { background: #f4f5f8; text-decoration: none; }
.btn-primary { background: var(--link); border-color: var(--link); color: #fff; }
.btn-primary:hover { background: #1d4fd7; }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: #fef2f2; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link-danger { color: var(--danger); }
.actions-cell a { margin-right: 10px; font-size: 15px; }
.actions-cell a.disabled { color: #c3c3cc; pointer-events: none; }

/* ---------- Forms ---------- */
.filters { display: grid; gap: 8px 8px; margin-bottom: 24px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 16px; color: var(--text-muted); font-weight: 500; }
.req { color: var(--danger); margin-left: 2px; }
.hint-red { color: var(--danger); font-size: 13px; margin-top: -2px; }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; outline: none;
}
.textarea { height: auto; min-height: 90px; padding: 10px 14px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--link); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.input.invalid, .textarea.invalid { border-color: var(--danger); }
.select { appearance: none; padding-right: 40px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%231f1f29' stroke-width='1.6' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 14px center; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.input-icon.left svg { left: 14px; }
.input-icon.left .input { padding-left: 40px; }
.input-icon.right svg { right: 14px; }
.input-icon.right .input { padding-right: 42px; }
.form-grid { display: grid; gap: 16px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.form-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.counter { font-size: 13px; color: var(--text-subtle); text-align: right; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--link); margin: 0; }
.radio-row { display: flex; gap: 24px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.radio-row input { width: 20px; height: 20px; accent-color: var(--link); margin: 0; }
.option-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px 20px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.option-card + .option-card { margin-top: 14px; }
.option-card input { width: 20px; height: 20px; margin-top: 4px; accent-color: var(--link); }
.option-card.on { background: #f3f7ff; border-color: #bfd3fb; }
.option-card small, .check-block small { display: block; color: var(--text-muted); font-size: 14px; }
.check-block { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check-block + .check-block { margin-top: 16px; }
.check-block input { width: 18px; height: 18px; margin-top: 4px; accent-color: var(--link); }

.dropzone {
  border: 1.5px dashed #d6d6de; border-radius: var(--radius-sm); background: #f6f6f9; padding: 28px 16px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.drag { background: #eef3ff; border-color: var(--link); }
.dropzone .dz-title { font-weight: 500; margin-top: 6px; }
.dropzone .dz-hint { font-size: 14px; color: var(--text-subtle); }
.dropzone .dz-file { margin-top: 6px; font-size: 14px; color: var(--link); font-weight: 600; }
.image-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 28px 16px 20px; text-align: center; }
.image-box img { width: 292px; height: 292px; object-fit: cover; display: block; margin: 0 auto 8px; max-width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { background: var(--thead); color: var(--text-muted); font-weight: 500; font-size: 14px; text-align: left; padding: 10px 16px; white-space: nowrap; }
.tbl th:first-child { border-top-left-radius: 6px; }
.tbl th:last-child { border-top-right-radius: 6px; }
.tbl td { padding: 16px; border-bottom: 1px solid var(--border); font-weight: 500; vertical-align: middle; }
.tbl.compact td { padding: 12px 16px; font-size: 15px; white-space: nowrap; }
.tbl tr.row-click { cursor: pointer; }
.tbl tr.row-click:hover td { background: #fafbff; }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl .empty { text-align: center; color: var(--text-subtle); padding: 40px; }
.th-sort { cursor: pointer; user-select: none; }
.th-sort svg { vertical-align: -3px; }
.ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap; line-height: 1.6; }
.b-green { background: #dcfce7; color: #16a34a; }
.b-amber { background: #fef3c7; color: #c2410c; }
.b-sky { background: #e0f2fe; color: #0284c7; }
.b-purple { background: #f3e8ff; color: #7e22ce; }
.b-red { background: #fee2e2; color: #dc2626; }
.b-gray { background: #f1f1f4; color: #6b6b78; }
.b-blue { background: #e0e9ff; color: #3b5bdb; }
.pill-outline { display: inline-block; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 15px; white-space: nowrap; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; flex-wrap: wrap; }
.pager .info { display: flex; align-items: center; gap: 16px; color: var(--text-muted); flex-wrap: wrap; }
.pager .select { width: auto; height: 34px; padding-left: 12px; font-weight: 500; color: var(--text); }
.pages { display: flex; align-items: center; gap: 4px; }
.pages button { min-width: 30px; height: 34px; padding: 0 8px; border: 0; background: none; border-radius: 6px; cursor: pointer; font-weight: 500; color: var(--text-muted); }
.pages button.on { background: var(--link); color: #fff; }
.pages button.nav { border: 1px solid var(--border); padding: 0 12px; color: var(--text); background: #fff; }
.pages button:disabled { color: #c3c3cc; cursor: not-allowed; }

/* ---------- Dashboard ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 14px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.stats-4 { display: grid; grid-template-columns: repeat(4, 1fr); margin: 8px 0 28px; }
.stat { text-align: center; padding: 4px 12px; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat .s-label { font-size: 14px; color: var(--text-muted); }
.stat .s-value { font-size: 28px; font-weight: 700; margin: 2px 0 4px; }
.delta { display: inline-block; font-size: 12px; font-weight: 700; color: #16a34a; background: #dcfce7; padding: 1px 8px; border-radius: 999px; }
.delta.down { color: #dc2626; background: #fee2e2; }
.delta.flat { color: var(--text-muted); background: #f1f1f4; }
.legend { display: flex; gap: 16px; font-size: 14px; color: var(--text-muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.chart-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px 16px 8px; position: relative; margin-bottom: 28px; }
.chart-box svg { display: block; width: 100%; height: auto; }
.chart-tip { position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,0.08); padding: 8px 12px; font-size: 13px; white-space: nowrap; display: none; }
.chart-tip b { font-weight: 700; }
.donut-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 40px; align-items: center; margin-bottom: 28px; }
.donut-list { display: grid; gap: 14px; }
.donut-list .row { display: flex; justify-content: space-between; gap: 16px; font-weight: 500; }
.donut-list .row i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 10px; }
.bar-track { height: 8px; border-radius: 999px; background: #e7e8ee; min-width: 120px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--primary); }

/* ---------- Order detail ---------- */
.stepper { display: flex; justify-content: center; gap: 0; padding: 12px 0 4px; overflow-x: auto; }
.step { width: 156px; flex-shrink: 0; position: relative; }
.step .circle { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: #e5e7eb; color: #6b7280; position: relative; z-index: 1; }
.step.done .circle { background: var(--link); color: #fff; }
.step.current .circle { background: #f5a300; color: #fff; }
.step:not(:last-child)::after { content: ''; position: absolute; left: 34px; right: 0; top: 16px; height: 2px; background: #e5e7eb; }
.step.done:not(:last-child)::after { background: #16a34a; }
.step .s-name { margin-top: 6px; font-size: 14px; font-weight: 500; }
.step:not(.done):not(.current) .s-name { color: var(--text-subtle); }
.step .s-time { font-size: 12px; color: var(--text-subtle); }
.kv-grid { display: grid; gap: 14px 24px; }
.kv-grid.c2 { grid-template-columns: 1fr 1fr; }
.kv-grid.c3 { grid-template-columns: repeat(3, 1fr); }
.kv .k { font-size: 14px; color: var(--text-subtle); }
.kv .v { font-weight: 500; }
.total-row td { background: var(--thead); font-weight: 700; }
.tbl .total-row td.big { font-size: 22px; }

/* ---------- Stock ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button { height: 44px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.seg button.in.on { background: #e8f9ee; border-color: #16a34a; color: #15803d; }
.seg button.out.on { background: #fef2f2; border-color: #dc2626; color: #b91c1c; }
.calc { display: flex; align-items: center; gap: 18px; justify-content: center; border: 1px solid var(--border); background: #f8f9fb; border-radius: var(--radius-sm); padding: 16px 20px; margin: 24px auto; width: fit-content; max-width: 100%; flex-wrap: wrap; }
.calc .c-label { font-size: 14px; color: var(--text-muted); }
.calc .c-val { font-size: 20px; font-weight: 700; }
.calc .eq { font-size: 26px; color: var(--text-muted); }
.alert-warn { background: #fef3c7; color: #b45309; border-radius: var(--radius-sm); padding: 12px 16px; font-weight: 500; margin: 16px 0; }

/* ---------- Category accordion ---------- */
.cat-row .tog { color: var(--link); display: inline-flex; vertical-align: middle; margin-right: 10px; transition: transform .15s; }
.cat-row.open .tog { transform: rotate(180deg); }
.cat-row.open td { background: #dbe6ff; border-bottom-color: transparent; }
.cat-detail > td { background: #dbe6ff; padding: 0 16px 16px !important; }
.cat-detail .inner { background: #fff; border-radius: var(--radius); overflow: hidden; }
.cat-detail .inner .tbl th { background: #f3f4f6; }
.cat-detail .inner .tbl tr:last-child td { border-bottom: 0; }

/* ---------- SEO ---------- */
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tabs button { background: none; border: 0; padding: 10px 16px; cursor: pointer; font-weight: 500; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--link); border-bottom-color: var(--link); font-weight: 700; }
.serp-wrap { border: 1.5px dashed #c9c9d2; border-radius: var(--radius-sm); padding: 24px; display: flex; justify-content: center; }
.serp { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; max-width: 600px; width: 100%; }
.serp .site { display: flex; gap: 14px; align-items: center; font-size: 14px; }
.serp .site img { width: 32px; height: 32px; }
.serp .s-title { color: #1a0dab; font-size: 22px; margin: 6px 0 4px; word-break: break-word; }
.serp .s-desc { font-size: 13px; color: var(--text-muted); }
.bot-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); gap: 16px; }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d4d4dc; border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--link); }
.switch input:checked + span::before { transform: translateX(20px); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }

/* ---------- Editor ---------- */
.editor { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.editor .toolbar { display: flex; align-items: center; gap: 4px; padding: 10px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.editor .toolbar select { border: 0; background: none; font-size: 14px; padding: 4px; cursor: pointer; }
.editor .toolbar button { background: none; border: 0; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-weight: 700; }
.editor .toolbar button:hover { background: var(--bg); }
.editor .toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }
.editor .content { min-height: 300px; padding: 20px; outline: none; line-height: 1.6; }
.editor .content h2 { color: var(--primary); font-size: 22px; margin-bottom: 6px; }

/* ---------- Placeholder ---------- */
.placeholder { text-align: center; padding: 64px 24px; color: var(--text-muted); }
.placeholder svg { color: #c3c3cc; margin-bottom: 12px; }
.placeholder h2 { color: var(--text); font-size: 20px; margin-bottom: 6px; }

/* ---------- Login ---------- */
.login { display: grid; grid-template-columns: 760fr 752fr; min-height: 100vh; }
.login-brand { background: var(--primary); color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 80px; }
.login-brand img { width: 220px; max-width: 100%; margin-bottom: 24px; }
.login-brand h1 { font-size: 30px; font-weight: 700; margin-bottom: 24px; }
.login-brand p { font-size: 16px; line-height: 1.4; max-width: 580px; opacity: .92; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.login-form form { width: 360px; max-width: 100%; }
.login-form h2 { font-size: 30px; font-weight: 700; }
.login-form .lead { color: var(--text-muted); margin: 4px 0 24px; }
.login-form .field + .field { margin-top: 16px; }
.login-row { display: flex; justify-content: space-between; align-items: center; margin: 20px 0; font-size: 16px; }
.login-row .check { color: var(--text-muted); }
.login-row a { font-weight: 600; color: var(--primary); }
.err { color: var(--danger); font-size: 14px; margin-top: 10px; display: none; }

/* ---------- Modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15,15,40,0.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); width: 480px; max-width: 100%; max-height: 90vh; overflow: auto; padding: 24px; box-shadow: 0 24px 60px rgba(0,0,0,0.2); }
.modal h3 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.modal .m-body { color: var(--text-muted); }
.modal .form-grid { margin-top: 16px; }
.toast-host { position: fixed; right: 24px; bottom: 24px; z-index: 200; display: grid; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); display: flex; align-items: center; gap: 10px; font-size: 15px; animation: tin .2s ease-out; max-width: 360px; }
.toast.ok svg { color: #4ade80; }
.toast.warn svg { color: #fbbf24; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .kpi-row, .stats-4 { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .stats-4 { row-gap: 20px; }
  .form-grid.cols-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 960px) {
  .hamburger { display: inline-flex; }
  .header { padding: 12px 16px; height: 72px; }
  :root { --header-h: 72px; }
  .header .logo { width: 120px; height: 38px; }
  .header .logo img { width: 120px; height: 38px; }
  .header-left { display: flex; align-items: center; gap: 12px; }
  .header-right { gap: 16px; }
  .user-chip .name { display: none; }
  .avatar { width: 40px; height: 40px; font-size: 18px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; z-index: 50; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(0,0,0,0.35); z-index: 45; }
  .main { margin-left: 0; padding: calc(var(--header-h) + 20px) 16px 32px; }
  .grid-2, .form-grid.cols-2, .kv-grid.c2, .kv-grid.c3, .donut-wrap { grid-template-columns: 1fr; }
  .grid-2 > .card + .card { margin-top: 0; }
  .donut-wrap svg { margin: 0 auto; }
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 40px 24px; }
  .filters { grid-template-columns: 1fr !important; }
}
@media (max-width: 600px) {
  .kpi-row, .stats-4, .form-grid.cols-5 { grid-template-columns: 1fr; }
  .stat + .stat { border-left: 0; border-top: 1px solid var(--border); padding-top: 16px; }
  .card { padding: 16px; }
  .page-title { font-size: 24px; }
}

@media print {
  .header, .sidebar, .page-actions, .form-footer, .btn { display: none !important; }
  .main { margin: 0; padding: 0; }
  body { background: #fff; }
}

/* ---------- Total Features additions ---------- */
.modal.wide { width: 760px; }
.form-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 32px; }
.form-card + .form-card { margin-top: 24px; }
.form-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.form-card hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid .span-2 { grid-column: span 2; }

/* permission groups */
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 24px; }
.perm-group .head { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; font-weight: 500; cursor: pointer; }
.perm-group .head input, .perm-group .items input { width: 16px; height: 16px; accent-color: var(--link); margin: 0; }
.perm-group .items { display: grid; gap: 8px; padding-left: 26px; }
.perm-group .items label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.perm-group .items label.off { color: var(--text-subtle); }

/* role chips (user form) */
.role-box { background: #f3f4f6; border-radius: var(--radius-sm); padding: 16px; }
.role-box .lbl { color: var(--text-muted); margin-bottom: 8px; }
.role-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.role-chip { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; }
.role-chip small { font-weight: 400; color: var(--text-muted); font-size: 15px; }
.role-chip.on { border-color: var(--link); background: #eef3ff; color: var(--link); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }

/* branch map */
.map { position: relative; height: 260px; border-radius: var(--radius-sm); overflow: hidden; background: #e2ede6;
  background-image: linear-gradient(#cfdcd3 1px, transparent 1px), linear-gradient(90deg, #cfdcd3 1px, transparent 1px); background-size: 100px 50px; }
.map .zone { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 1.5px dashed var(--link); background: rgba(37,99,235,.08); border-radius: 50%; transition: width .2s, height .2s; }
.map .pin { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -100%); color: #dc2626; }
.map .coord { position: absolute; left: 12px; bottom: 12px; background: #fff; border-radius: 6px; padding: 4px 12px; font-size: 13px; }
.info-note { background: #f3f7ff; color: var(--link); border-radius: 6px; padding: 8px 12px; font-size: 14px; margin-top: 16px; }

/* image + document upload lists */
.thumbs { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.thumb { width: 138px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.thumb img { width: 100%; height: 100px; object-fit: cover; display: block; }
.thumb div { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; font-size: 13px; gap: 4px; }
.thumb button { border: 0; background: none; color: var(--text-muted); cursor: pointer; padding: 0; display: flex; }
.doc-row { display: flex; align-items: center; gap: 14px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.doc-row .ic { width: 36px; height: 36px; border-radius: 8px; background: #f3f4f6; display: grid; place-items: center; color: var(--text-muted); }
.doc-row b { display: block; font-weight: 600; }
.doc-row small { color: var(--text-muted); }
.doc-row button { margin-left: auto; border: 0; background: none; color: #dc2626; cursor: pointer; }
.sku-table { width: 100%; border-collapse: separate; border-spacing: 0; background: #f9fafb; border-radius: 10px; overflow: hidden; }
.sku-table th { background: #eef0f3; color: var(--text-muted); font-weight: 500; font-size: 14px; text-align: left; padding: 10px 8px; }
.sku-table td { padding: 6px 4px; }
.sku-table input { width: 100%; height: 38px; border: 1px solid var(--border); border-radius: 6px; padding: 0 10px; background: #fff; }
.sku-table .x { border: 0; background: none; color: #dc2626; cursor: pointer; font-size: 20px; }
.sku-table .add { border: 0; background: none; color: var(--link); cursor: pointer; font-size: 22px; font-weight: 700; }

/* category preview card */
.preview-wrap { border: 1.5px dashed #c9c9d2; border-radius: var(--radius-sm); padding: 24px; display: flex; justify-content: center; }
.cat-preview { width: 256px; border: 2px solid #dcdce3; border-radius: 16px; padding: 8px 8px 20px; text-align: center; background: #fff; }
.cat-preview img { width: 100%; height: 180px; object-fit: contain; }
.cat-preview b { display: block; color: var(--primary); font-size: 24px; margin: 8px 0; }
.cat-preview span { color: var(--text-muted); }

/* success popup */
.ok-icon { width: 72px; height: 72px; border-radius: 50%; background: #dcfce7; color: #16a34a; display: grid; place-items: center; margin: 0 auto 16px; }
.modal.center { text-align: center; }
.modal.center .sumbox { text-align: left; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #f8f9fb; padding: 14px 16px; margin-top: 18px; }
.modal.center .sumbox .row { display: flex; justify-content: space-between; padding: 4px 0; }
.modal.center .sumbox .row span:first-child { color: var(--text-muted); }
.modal.center .foot2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }

/* auth sub-pages */
.auth-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; margin-bottom: 14px; background: #e8edff; color: var(--primary); }
.auth-icon.red { background: #fee2e2; color: #dc2626; }
.back-link { display: inline-block; margin-top: 20px; color: var(--primary); font-weight: 500; }
.support { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 10px 12px; color: var(--text-muted); margin: 20px 0; font-size: 14px; }
.cancel-steps .step { width: 180px; }
.step.ok .circle { background: #16a34a; color: #fff; }

@media (max-width: 960px) {
  .perm-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .form-card { padding: 20px 16px; }
}
