/* ═══════════════════════════════════════════════════
   VELO DESIGN SYSTEM — mature palette, dark & light
   ═══════════════════════════════════════════════════ */
:root {
  --font: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 258px;

  --accent: #4553d6;
  --accent-hover: #3642b8;
  --accent-soft: rgba(69, 83, 214, .10);
  --accent-text: #4553d6;

  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e4e7ed;
  --text: #181c26;
  --muted: #5d6679;
  --faint: #8b93a7;

  --success: #0e9f6e;
  --success-soft: rgba(14, 159, 110, .12);
  --danger: #d8443c;
  --danger-soft: rgba(216, 68, 60, .12);
  --warning: #b7791f;
  --warning-soft: rgba(183, 121, 31, .14);

  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);
  color-scheme: light;
}

[data-theme="dark"] {
  --accent: #7c8cf8;
  --accent-hover: #93a1fa;
  --accent-soft: rgba(124, 140, 248, .14);
  --accent-text: #9aa8fa;

  --bg: #0c1120;
  --surface: #131a2c;
  --surface-2: #182136;
  --border: #242f4a;
  --text: #e6e9f3;
  --muted: #99a3bf;
  --faint: #6b7592;

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, .14);
  --danger: #f26d64;
  --danger-soft: rgba(242, 109, 100, .14);
  --warning: #e5b567;
  --warning-soft: rgba(229, 181, 103, .14);

  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* ── Icon system (SVG, currentColor) ───────────── */
.vico { flex-shrink: 0; vertical-align: middle; }
.nav-item .ico { display: flex; align-items: center; justify-content: center; }
.btn .vico { margin: -1px 0; }
.badge .vico { width: 13px; height: 13px; }
.card-title .vico { color: var(--accent-text); }
.stat-icon .vico { width: 22px; height: 22px; color: var(--accent-text); }
.brand-mark .vico { width: 18px; height: 18px; }
.icon-btn .vico { width: 17px; height: 17px; }
.flash .vico { width: 16px; height: 16px; flex-shrink: 0; }
.empty-ico .vico { width: 40px; height: 40px; color: var(--faint); stroke-width: 1.5; }
.hero-feat .fi .vico { width: 16px; height: 16px; }
.expiry-pill .vico { width: 13px; height: 13px; }

/* Theme toggle: swap sun/moon by theme */
.theme-toggle .i-sun { display: none; }
[data-theme="dark"] .theme-toggle .i-sun { display: block; }
[data-theme="dark"] .theme-toggle .i-moon { display: none; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  transition: background .25s ease, color .25s ease;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.01em; }
::selection { background: var(--accent-soft); }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform .28s ease, background .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 22px 16px;
  font-weight: 800; font-size: 20px; letter-spacing: -.02em;
  color: var(--text);
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: grid; place-items: center; color: #fff; font-size: 17px;
  box-shadow: 0 4px 12px rgba(69, 83, 214, .35);
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 14px 14px; }
.nav-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--faint);
  padding: 16px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; font-size: 15px; }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 700; font-size: 16.5px; }
.topbar-spacer { flex: 1; }

.content { padding: 26px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ── User chip / expiry pill ────────────────────── */
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 12px 6px 7px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; font-size: 13.5px; font-weight: 600;
}
.user-chip .avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.expiry-pill {
  font-size: 12px; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  background: var(--warning-soft); color: var(--warning);
}
.expiry-pill.ok { background: var(--success-soft); color: var(--success); }
.expiry-pill.bad { background: var(--danger-soft); color: var(--danger); }

/* ── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font: 600 14px var(--font); cursor: pointer;
  border: 1px solid transparent;
  background: var(--accent); color: #fff;
  transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn-success { background: var(--success); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 16px;
  transition: all .15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* ── Cards ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: background .25s, border-color .25s;
}
.card + .card { margin-top: 18px; }
.card-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 9px; }
.card-sub { color: var(--muted); font-size: 13.5px; margin-top: -4px; }

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

/* ── Stat cards ─────────────────────────────────── */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 15px;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 20px;
  background: var(--accent-soft);
}
.stat-num { font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ── Tables ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
th {
  text-align: left; padding: 12px 16px; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 700;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 13px; }

/* ── Badges ─────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.badge.green { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.amber { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.gray { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

/* ── Forms ──────────────────────────────────────── */
.field { margin-bottom: 16px; }
.label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--faint); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: 500 14px var(--font);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--faint); }
.input-group { display: flex; gap: 9px; }
.input-group .input { flex: 1; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: none; }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--border); transition: background .2s; cursor: pointer;
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }

/* ── Type segmented control ─────────────────────── */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg-2 { grid-template-columns: repeat(2, 1fr); }
.seg-2 label { padding: 9px 10px; }
.seg-2 .seg-name { margin-top: 0; display: inline-flex; align-items: center; gap: 6px; }
.seg input { display: none; }
.seg label {
  padding: 13px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface);
  cursor: pointer; text-align: center; transition: all .15s;
}
.seg label:hover { border-color: var(--faint); }
.seg input:checked + label { border-color: var(--accent); background: var(--accent-soft); }
.seg .seg-ico { font-size: 20px; }
.seg .seg-name { font-weight: 700; font-size: 13.5px; margin-top: 4px; }
.seg .seg-desc { font-size: 11.5px; color: var(--muted); }

/* ── Flash messages ─────────────────────────────── */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; margin-bottom: 18px;
}
.flash.ok { background: var(--success-soft); color: var(--success); }
.flash.err { background: var(--danger-soft); color: var(--danger); }

/* ── Template gallery ───────────────────────────── */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 15px; }
.tpl-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
  display: flex; flex-direction: column;
}
.tpl-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.tpl-thumb {
  height: 108px; display: grid; place-items: center; font-size: 40px;
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border-bottom: 1px solid var(--border);
}
.tpl-body { padding: 13px 15px; flex: 1; }
.tpl-name { font-weight: 700; font-size: 14px; }
.tpl-cat { font-size: 12px; color: var(--faint); }
.tpl-actions { display: flex; gap: 7px; padding: 0 15px 14px; }

/* ── Tabs ───────────────────────────────────────── */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab {
  padding: 7px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  color: var(--muted); cursor: pointer; border: 1px solid transparent;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { background: var(--accent-soft); color: var(--accent-text); }

/* ── Copy box ───────────────────────────────────── */
.copy-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 8px 8px 13px;
  font-size: 13px; min-width: 0;
}
.copy-box .mono { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Progress bars (analytics) ──────────────────── */
.bar-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; font-size: 13.5px; }
.bar-row .bar-label { width: 110px; flex-shrink: 0; font-weight: 600; display: flex; gap: 7px; align-items: center; }
.bar-row .bar-track { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #8b5cf6); }
.bar-row .bar-num { width: 42px; text-align: right; color: var(--muted); font-weight: 600; }

/* ── Chart ──────────────────────────────────────── */
.chart-wrap { position: relative; height: 220px; }

/* ── Empty state ────────────────────────────────── */
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .empty-ico { font-size: 42px; margin-bottom: 10px; }

/* ── Token template selector ────────────────────── */
.token-tpl-dropdown { position: relative; }
.token-tpl-dropdown select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 14px; font-weight: 600; color: var(--text);
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.token-tpl-dropdown select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.token-tpl-preview {
  display: flex; gap: 14px; padding: 16px; margin-top: 12px;
  border-radius: var(--radius); border: 1.5px solid var(--border);
  background: var(--surface-2); align-items: flex-start;
}
.token-tpl-preview-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center; flex-shrink: 0; color: var(--accent-text);
}
.token-tpl-preview-info { flex: 1; min-width: 0; }
.token-tpl-preview-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.token-tpl-preview-name { font-weight: 700; font-size: 14.5px; color: var(--text); }
.token-tpl-preview-desc { font-size: 12.5px; color: var(--muted); line-height: 1.45; margin: 0 0 10px; }
.token-tpl-preview .btn { align-self: flex-start; }

/* ── Login page ─────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-wrap--simple {
  display: flex; align-items: center; justify-content: center;
  padding: 40px 28px; background: var(--bg);
}
.login-wrap--simple .login-box { width: 100%; max-width: 380px; }
.login-box-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 28px;
}
.login-hero {
  background: linear-gradient(150deg, #171d33 0%, #232a4d 55%, #3b3486 100%);
  color: #eef0fa; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.login-hero::after {
  content: ''; position: absolute; width: 480px; height: 480px; border-radius: 50%;
  background: radial-gradient(circle, rgba(124,140,248,.28), transparent 65%);
  bottom: -160px; right: -120px;
}
.login-hero h1 { font-size: 34px; letter-spacing: -.03em; line-height: 1.15; }
.login-hero p { color: #b6bde0; font-size: 15.5px; max-width: 420px; }
.hero-feats { display: grid; gap: 13px; margin-top: 30px; position: relative; z-index: 1; }
.hero-feat { display: flex; gap: 12px; align-items: center; font-size: 14.5px; color: #cdd3ef; }
.hero-feat .fi {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: rgba(255,255,255,.09); display: grid; place-items: center; font-size: 15px;
}
.login-panel { display: flex; align-items: center; justify-content: center; padding: 40px 28px; background: var(--bg); }
.login-box { width: 100%; max-width: 380px; }
.login-box h2 { font-size: 24px; letter-spacing: -.02em; }

/* ── Hamburger ──────────────────────────────────── */
.hamburger { display: none; }
.sidebar-overlay { display: none; }

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.show {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(8, 10, 18, .5); backdrop-filter: blur(2px);
  }
  .main { margin-left: 0; }
  .hamburger { display: grid; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .content { padding: 18px 14px; }
  .topbar { padding: 10px 14px; }
}
@media (max-width: 560px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .seg { grid-template-columns: 1fr; }
  .topbar-title { display: none; }
  .stat { padding: 15px; }
  .stat-num { font-size: 20px; }
}

/* ── Utilities ──────────────────────────────────── */
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }
