/* ==========================================================
   VoucherKu: neumorphism, mobile-first
   ========================================================== */
:root {
  --bg: #e4e9ee;
  --sh-d: #c3cad3;
  --sh-l: #ffffff;
  --text: #2b3440;
  --muted: #6b7684;
  --accent: #0f8b80;
  --accent-ink: #ffffff;
  --money: #c27c12;
  --tx: #d98e1f;
  --danger: #cc4558;
  --ok: #2e9e5b;

  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;

  --raise: 7px 7px 15px var(--sh-d), -7px -7px 15px var(--sh-l);
  --raise-sm: 4px 4px 9px var(--sh-d), -4px -4px 9px var(--sh-l);
  --press: inset 4px 4px 9px var(--sh-d), inset -4px -4px 9px var(--sh-l);
  --press-sm: inset 2px 2px 5px var(--sh-d), inset -2px -2px 5px var(--sh-l);

  --nav-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262b32;
    --sh-d: #1b1f24;
    --sh-l: #313740;
    --text: #e2e7ed;
    --muted: #96a0ad;
    --accent: #36c2b3;
    --accent-ink: #0d2522;
    --money: #f0b04a;
    --tx: #f0b04a;
    --danger: #ef6b7d;
    --ok: #58c987;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
code { font-family: var(--mono); font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.raised { box-shadow: var(--raise); }
.inset { box-shadow: var(--press); }

/* ---------- App shell & activities ---------- */
#app { max-width: 560px; margin: 0 auto; min-height: 100%; position: relative; }
#stage { position: relative; min-height: 100vh; }

.activity {
  position: relative;
  min-height: 100vh;
  background: var(--bg);
  padding-top: var(--safe-t);
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 28px);
}
.activity.no-nav { padding-bottom: calc(var(--safe-b) + 32px); }
.activity[hidden] { display: none; }
.activity.enter { animation: act-in .24s cubic-bezier(.2,.8,.2,1); }
.activity.leave { position: absolute; top: 0; left: 0; width: 100%; z-index: 2; animation: act-out .2s ease forwards; pointer-events: none; }
@keyframes act-in { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes act-out { to { transform: translateX(28px); opacity: 0; } }
.activity.fade { animation: act-fade .2s ease; }
@keyframes act-fade { from { opacity: 0; } to { opacity: 1; } }

.pad { padding: 4px 18px 0; }

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px 12px;
  background: var(--bg);
}
.appbar-title { flex: 1; min-width: 0; }
.appbar-title h2 { font-size: 21px; font-weight: 800; }
.appbar-title small { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 42px; height: 42px; border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--bg); box-shadow: var(--raise-sm);
}
.icon-btn:active { box-shadow: var(--press-sm); }

.router-switch {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 0 14px; height: 46px; border-radius: 999px; min-width: 0;
}
.router-switch svg { color: var(--accent); }
.router-switch select {
  flex: 1; min-width: 0; border: 0; background: transparent; font-weight: 700;
  appearance: none; -webkit-appearance: none; outline: none; padding-right: 18px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 7px) 50%, calc(100% - 2px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* ---------- Cards ---------- */
.card { background: var(--bg); border-radius: var(--r-lg); padding: 18px; margin-bottom: 18px; }
.stack > * + * { margin-top: 14px; }
.section-title { font-size: 16px; font-weight: 700; margin: 26px 2px 14px; }

.stat-hero { display: flex; flex-direction: column; gap: 2px; padding: 20px 20px 18px; }
.stat-big { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; color: var(--money); line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stat-row .card { margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 16px; border-radius: var(--r-md); }
.stat strong { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- Traffic chart ---------- */
.traffic-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.traffic-head small { display: block; font-size: 12px; }
.legend { display: flex; gap: 12px; font-size: 12px; text-align: right; }
.legend b { font-variant-numeric: tabular-nums; }
.lg-rx { color: var(--accent); }
.lg-tx { color: var(--tx); }
.chart-wrap { border-radius: var(--r-md); height: 150px; padding: 8px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }

/* ---------- Tabs & chips ---------- */
.tabs { display: flex; border-radius: 999px; padding: 5px; gap: 4px; margin-bottom: 16px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 999px;
  font-weight: 600; font-size: 13px; color: var(--muted); white-space: nowrap;
}
.tabs button.on { background: var(--bg); box-shadow: var(--raise-sm); color: var(--text); }
.tabs i { font-style: normal; font-size: 11px; color: var(--accent); }

.chips { display: flex; gap: 10px; margin: 16px 0 18px; overflow-x: auto; padding: 4px 2px 8px; }
.chip { border: 0; background: var(--bg); border-radius: 999px; padding: 8px 16px; font-size: 13px; font-weight: 600; box-shadow: var(--raise-sm); white-space: nowrap; color: var(--muted); }
.chip.on { box-shadow: var(--press-sm); color: var(--accent); }

.search { display: flex; align-items: center; gap: 10px; padding: 0 16px; height: 48px; border-radius: 999px; }
.search svg { color: var(--muted); width: 19px; }
.search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; }

/* ---------- List items ---------- */
.item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg); border-radius: var(--r-md); padding: 14px 14px 14px 16px;
  box-shadow: var(--raise-sm); width: 100%; border: 0; text-align: left;
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-title.mono { font-size: 15.5px; letter-spacing: .02em; }
.item-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-end { text-align: right; font-size: 12.5px; flex: none; }
.item-end b { display: block; font-size: 14px; color: var(--money); }
.item .icon-btn { width: 38px; height: 38px; }
.item .icon-btn svg { width: 18px; height: 18px; }
.item.selected { box-shadow: var(--press-sm); }
.item .tick {
  width: 24px; height: 24px; border-radius: 8px; flex: none; display: grid; place-items: center;
  box-shadow: var(--press-sm); color: transparent;
}
.item.selected .tick { color: var(--accent); }
.item .tick svg { width: 16px; height: 16px; stroke-width: 3; }

.badge { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; box-shadow: var(--press-sm); color: var(--muted); font-family: var(--font); letter-spacing: 0; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--tx); }
.badge.off { color: var(--danger); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.off { background: var(--danger); }

.router-card { display: block; }
.router-card .rc-top { display: flex; align-items: center; gap: 12px; }
.router-card .rc-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: var(--accent); box-shadow: var(--press-sm); flex: none; }
.router-card .rc-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.router-card .rc-meta span { font-size: 11.5px; color: var(--muted); }
.router-card .rc-meta b { display: block; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }
.skeleton { height: 64px; border-radius: var(--r-md); box-shadow: var(--press-sm); opacity: .7; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); padding-left: 4px; }
.field input, .field select, .field textarea, .inset-select {
  width: 100%; border: 0; border-radius: var(--r-sm); background: var(--bg);
  padding: 13px 15px; box-shadow: var(--press); outline: none;
}
.field textarea { resize: vertical; font-size: 12.5px; line-height: 1.5; }
.field select, .inset-select { appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 15px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
.field input:focus, .field select:focus, .field textarea:focus { box-shadow: var(--press), 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 .field:first-child { grid-column: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: var(--r-sm); padding: 12px 18px; font-weight: 700;
  background: var(--bg); box-shadow: var(--raise-sm); white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { box-shadow: var(--press-sm); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--raise-sm); }
.btn-primary:active { filter: brightness(.94); box-shadow: inset 3px 3px 7px rgba(0,0,0,.22); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; padding: 15px; border-radius: var(--r-md); font-size: 15.5px; }
.btn[disabled] { opacity: .55; pointer-events: none; }

.switch { display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { width: 50px; height: 28px; border-radius: 999px; box-shadow: var(--press); position: relative; flex: none; transition: background .2s; }
.switch-ui::after { content: ""; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--bg); box-shadow: var(--raise-sm); transition: transform .2s; }
.switch input:checked + .switch-ui { background: color-mix(in srgb, var(--accent) 30%, var(--bg)); }
.switch input:checked + .switch-ui::after { transform: translateX(22px); background: var(--accent); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 3px; }

/* segmented & formats */
.seg { display: flex; border-radius: var(--r-sm); padding: 5px; gap: 5px; }
.seg label, .formats label { flex: 1; cursor: pointer; }
.seg input, .formats input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px 6px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--bg); box-shadow: var(--raise-sm); color: var(--text); }
.formats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.formats span { display: block; text-align: center; padding: 12px 0; border-radius: var(--r-sm); box-shadow: var(--raise-sm); font-size: 13px; font-weight: 700; color: var(--muted); }
.formats input:checked + span { box-shadow: var(--press-sm); color: var(--accent); }
.seg input:focus-visible + span, .formats input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.qty { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.qty > span { font-weight: 700; }
.stepper { display: flex; align-items: center; border-radius: 999px; padding: 5px; }
.stepper button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--bg); box-shadow: var(--raise-sm); font-size: 20px; font-weight: 700; }
.stepper button:active { box-shadow: var(--press-sm); }
.stepper input { width: 70px; border: 0; background: transparent; text-align: center; font-weight: 800; font-size: 20px; outline: none; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

.range { -webkit-appearance: none; appearance: none; height: 12px; border-radius: 999px; background: var(--bg); box-shadow: var(--press-sm); padding: 0 !important; }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); box-shadow: 3px 3px 7px var(--sh-d), -3px -3px 7px var(--sh-l); cursor: pointer; }
.range::-moz-range-thumb { width: 26px; height: 26px; border: 0; border-radius: 50%; background: var(--accent); box-shadow: 3px 3px 7px var(--sh-d), -3px -3px 7px var(--sh-l); }

.preview { display: flex; align-items: center; justify-content: space-between; border-radius: var(--r-md); padding: 16px 18px; }
.preview b { font-size: 24px; letter-spacing: .08em; color: var(--accent); }

/* ---------- Generate result ---------- */
.row-actions { display: flex; gap: 10px; margin-bottom: 18px; }
.row-actions .inset-select { flex: 1; min-width: 0; box-shadow: var(--press); }
.code-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.code { border-radius: var(--r-sm); padding: 12px; box-shadow: var(--raise-sm); text-align: center; }
.code b { display: block; font-family: var(--mono); font-size: 17px; letter-spacing: .05em; }
.code small { font-family: var(--mono); color: var(--muted); }

/* ---------- Report bars ---------- */
.bars { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.bar-row { font-size: 12.5px; }
.bar-row .bar-lbl { display: flex; justify-content: space-between; margin-bottom: 4px; }
.bar-track { height: 10px; border-radius: 999px; box-shadow: var(--press-sm); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.month { border-radius: 999px; padding: 0 12px; height: 42px; display: flex; align-items: center; }
.month input { border: 0; background: transparent; outline: none; font-weight: 600; font-size: 13px; width: 132px; }

/* ---------- Settings menu ---------- */
.menu { padding: 8px; }
.menu button { width: 100%; display: flex; align-items: center; gap: 14px; border: 0; background: transparent; padding: 12px 10px; border-radius: var(--r-md); text-align: left; }
.menu button:active { box-shadow: var(--press-sm); }
.menu button > span:nth-child(2) { flex: 1; }
.menu b { display: block; font-size: 14.5px; }
.menu small { display: block; font-size: 12.5px; }
.menu-ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; color: var(--accent); flex: none; box-shadow: var(--press-sm); }
.menu .danger, .menu .danger .menu-ic { color: var(--danger); }
.chev { color: var(--muted); width: 18px; }

.price-card .pc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.price-card .pc-head b { flex: 1; }
.price-card .grid2 { margin-bottom: 12px; }
.price-card .pc-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.note { margin-top: 4px; }
.note code { display: block; word-break: break-all; margin-top: 8px; padding: 10px; border-radius: 10px; box-shadow: var(--press-sm); }
.tpl-preview { padding: 10px; }
.tpl-preview iframe { width: 100%; height: 190px; border: 0; border-radius: 14px; background: #fff; }

/* ---------- Login ---------- */
.login { padding-top: 12vh; }
.login-mark { width: 84px; height: 84px; border-radius: 28px; margin: 0 auto 18px; display: grid; place-items: center; color: var(--accent); }
.login-mark svg { width: 40px; height: 40px; }
.login-title { text-align: center; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.login .muted { margin: 6px 0 30px; }

/* ---------- FAB & selection bar ---------- */
.fab {
  position: fixed; z-index: 6;
  right: max(20px, calc(50% - 280px + 20px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 22px);
  width: 56px; height: 56px; border: 0; border-radius: 18px;
  background: var(--bg); color: var(--accent); display: grid; place-items: center;
}
.fab:active { box-shadow: var(--press); }
.activity.no-nav .fab { bottom: calc(var(--safe-b) + 24px); }

.selbar {
  position: fixed; z-index: 7; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 18px);
  width: min(524px, calc(100% - 36px));
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-radius: var(--r-md); padding: 10px 10px 10px 16px;
}
.selbar > span { flex: 1; font-weight: 700; font-size: 14px; }
.selbar .btn { padding: 10px 14px; }

/* ---------- Bottom navigation ---------- */
.bottomnav {
  position: fixed; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: 0; width: 100%; max-width: 560px;
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 0 10px var(--safe-b);
  display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr; align-items: center;
  background: var(--bg);
  box-shadow: 0 -6px 16px var(--sh-d);
  border-radius: 26px 26px 0 0;
}
.bottomnav[hidden] { display: none; }
.nav-btn {
  border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--muted); padding: 8px 0; border-radius: 16px; margin: 0 4px;
}
.nav-btn.on { color: var(--accent); box-shadow: var(--press-sm); }
.nav-gen {
  justify-self: center; width: 70px; height: 70px; margin-top: -38px;
  border-radius: 50%; border: 6px solid var(--bg);
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  box-shadow: 8px 8px 18px var(--sh-d), -8px -8px 18px var(--sh-l), inset 2px 2px 4px rgba(255,255,255,.28), inset -3px -3px 6px rgba(0,0,0,.16);
  transition: transform .15s ease;
}
.nav-gen svg { width: 28px; height: 28px; fill: currentColor; stroke-width: 1.2; }
.nav-gen:active { transform: scale(.94); }
.nav-gen.on { box-shadow: 8px 8px 18px var(--sh-d), -8px -8px 18px var(--sh-l), inset 4px 4px 9px rgba(0,0,0,.25); }

/* ---------- Toast & dialog ---------- */
.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 14px);
  max-width: min(480px, calc(100% - 32px));
  padding: 12px 18px; border-radius: 14px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: 0 10px 24px rgba(0,0,0,.18);
  animation: toast-in .22s ease;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

.dialog { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(3px); }
.dialog[hidden] { display: none; }
.dialog-card { background: var(--bg); border-radius: var(--r-lg); padding: 22px; width: min(380px, 100%); }
.dialog-title { font-size: 17px; margin-bottom: 6px; }
.dialog-text { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.dialog-actions { display: flex; gap: 12px; justify-content: flex-end; }

@media (min-width: 560px) {
  .code-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 360px) {
  .stat-big { font-size: 28px; }
  .formats { grid-template-columns: repeat(2, 1fr); }
  .stat-row { gap: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
