/* =========================================================================
   Nulli Pro — design system
   Modern, minimal. Theme is server-stored (dark/light) and applied via
   data-theme on <html>. No browser storage is used.
   ========================================================================= */

:root {
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.05);
  --radius: 14px;
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-soft: rgba(96, 165, 250, 0.16);
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;

  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #16213a;
  --text: #e6edf7;
  --muted: #8ea3c0;
  --border: #1f2c47;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 0.4em; letter-spacing: -0.02em; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.brand-name { font-weight: 800; letter-spacing: -0.02em; font-size: 15px; }
.brand-sub { font-size: 10px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.side-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px; color: var(--muted);
  font-weight: 600; font-size: 13.5px; margin-bottom: 2px; cursor: pointer;
  background: none; border: none; width: 100%; text-align: left; font-family: inherit;
}
.nav-link svg { width: 19px; height: 19px; fill: currentColor; flex-shrink: 0; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

.side-foot { padding: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }

/* ---------- Main column ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; display: grid; place-items: center;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 12px 5px 6px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.user-chip .u-name { font-size: 12.5px; font-weight: 700; }
.user-chip .u-role { font-size: 10px; color: var(--muted); }

.content { padding: 24px 22px 90px; max-width: 1100px; width: 100%; margin: 0 auto; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 8px var(--safe-bottom);
}
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10px; font-weight: 700; color: var(--muted); padding: 6px 0; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 12px; }

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

.kpi { padding: 16px 18px; }
.kpi .kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kpi .kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; }
.kpi .kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.kpi.tone-green .kpi-value { color: var(--success); }
.kpi.tone-red .kpi-value { color: var(--danger); }
.kpi.tone-blue .kpi-value { color: var(--primary); }
.kpi.tone-amber { background: linear-gradient(160deg, var(--surface), rgba(217, 119, 6, 0.14)); }

/* ---------- Forms ---------- */
label { display: block; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit; margin-bottom: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.form-row { margin-bottom: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: filter 0.15s, transform 0.05s; background: var(--surface-2); color: var(--text);
}
.btn:hover { filter: brightness(0.96); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row form { display: inline; }

/* ---------- Lists ---------- */
.list-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; box-shadow: var(--shadow); }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .li-main { font-weight: 600; }
.list-item .li-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-item .li-right { text-align: right; flex-shrink: 0; }
.link-item { cursor: pointer; }
.link-item:hover { background: var(--surface-2); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid-table th { text-align: left; padding: 9px 10px; color: var(--muted); border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.grid-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid-table tr:last-child td { border-bottom: none; }
.grid-table .num, .text-right { text-align: right; font-variant-numeric: tabular-nums; }
.grid-table .pos { color: var(--success); font-weight: 700; }
.grid-table .neg { color: var(--danger); font-weight: 700; }
.grid-table tfoot td { font-weight: 800; border-top: 2px solid var(--border); }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.03em; }
.badge-ok { background: rgba(22, 163, 74, 0.14); color: var(--success); }
.badge-warn { background: rgba(217, 119, 6, 0.16); color: var(--warning); }
.badge-err { background: rgba(220, 38, 38, 0.14); color: var(--danger); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-muted { background: var(--surface-2); color: var(--muted); }

/* ---------- Searchable dropdown (np-select) ---------- */
.np-select {
  position: relative;
  width: 100%;
}
.np-select-trigger {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font-size: 14px; font-family: inherit;
  cursor: pointer; text-align: left;
}
.np-select-trigger:hover { border-color: var(--primary); }
.np-select-trigger:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.np-select-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-select-chevron { width: 18px; height: 18px; fill: currentColor; color: var(--muted); flex-shrink: 0; transition: transform 0.15s; }
.np-select.open .np-select-chevron { transform: rotate(180deg); }
.np-select-panel {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); overflow: hidden; max-height: 320px; display: flex; flex-direction: column;
}
.np-select-search {
  width: 100%; padding: 10px 12px; border: none; border-bottom: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px; font-family: inherit;
}
.np-select-search:focus { outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.np-select-list { overflow-y: auto; padding: 6px 0; }
.np-select-item {
  padding: 9px 12px; cursor: pointer; font-size: 13.5px;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.np-select-item:hover, .np-select-item.selected { background: var(--primary-soft); color: var(--primary); }
.np-select-item.selected { font-weight: 600; }
.np-select-empty { padding: 12px; color: var(--muted); text-align: center; font-size: 12.5px; }

/* ---------- Table toolbar & pager (np-table) ---------- */
.np-table-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; margin-bottom: 8px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.np-table-search input {
  width: 280px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font-size: 13px; font-family: inherit;
}
.np-table-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.np-table-perpage label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.np-table-perpage select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 12.5px; }
.np-table-pager {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; margin-top: 8px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.np-table-page-info { font-size: 12.5px; color: var(--muted); }
.np-table-pager .btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- Flash & notices ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; font-size: 13.5px; }
.flash-success { background: rgba(22, 163, 74, 0.12); color: var(--success); border: 1px solid rgba(22, 163, 74, 0.3); }
.flash-error { background: rgba(220, 38, 38, 0.12); color: var(--danger); border: 1px solid rgba(220, 38, 38, 0.3); }
.flash-warn { background: rgba(217, 119, 6, 0.14); color: var(--warning); border: 1px solid rgba(217, 119, 6, 0.3); }

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; font-weight: 500; }
.notice .dot { margin-top: 4px; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.notice-warn { background: rgba(217, 119, 6, 0.12); border: 1px solid rgba(217, 119, 6, 0.35); color: var(--warning); }
.notice-warn .dot { background: var(--warning); }
.notice-error { background: rgba(220, 38, 38, 0.12); border: 1px solid rgba(220, 38, 38, 0.35); color: var(--danger); }
.notice-error .dot { background: var(--danger); }
.notice-info { background: var(--primary-soft); border: 1px solid rgba(37, 99, 235, 0.3); color: var(--primary); }
.notice-info .dot { background: var(--primary); }

/* ---------- Charts ---------- */
.chart-box { height: 240px; position: relative; }

/* ---------- Report paper ---------- */
.report-paper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; max-width: 860px; margin: 0 auto; }
.rpt-header { text-align: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 2px solid var(--text); }
.rpt-org { font-size: 20px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.rpt-title { font-size: 15px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-top: 4px; }
.rpt-meta { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.rpt-actions { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 14px; }

table.rpt { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.rpt th { background: var(--surface-2); border-bottom: 2px solid var(--text); border-top: 1px solid var(--border); padding: 8px; text-align: left; text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.05em; }
table.rpt th.num { text-align: right; }
table.rpt td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
table.rpt td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
table.rpt tr.section-head td { font-weight: 800; color: var(--primary); text-transform: uppercase; border-top: 2px solid var(--border); background: var(--surface-2); font-size: 11px; }
table.rpt tr.total-row td { border-top: 1px solid var(--text); font-weight: 800; }
table.rpt tr.grand-total td { border-top: 2px solid var(--text); border-bottom: 3px double var(--text); font-weight: 900; font-size: 13px; }
.indent { padding-left: 22px !important; color: var(--muted); }

/* ---------- Minimal (auth/license) pages ---------- */
.min-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.min-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.min-brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 22px; text-align: center; }
.min-brand .mark { width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; margin-bottom: 12px; }
.min-brand h1 { font-size: 20px; }
.min-brand p { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- License status ---------- */
.status-hero { border-radius: 16px; padding: 24px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.status-hero .big { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; word-break: break-all; }
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.kv:last-child { border-bottom: none; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }

/* ---------- Wallet ---------- */
.wallet-hero { background: linear-gradient(135deg, #1e293b, #334155); color: #fff; border-radius: 18px; padding: 26px; margin-bottom: 18px; }
.wallet-hero .w-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.7; }
.wallet-hero .w-balance { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; margin: 6px 0 2px; }
.wallet-hero .w-plan { opacity: 0.85; font-size: 13px; }

.plan-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 2px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; background: var(--surface); }
.plan-card.active { border-color: var(--success); }
.plan-card.best { border-color: var(--warning); }
.plan-card .p-price { font-size: 18px; font-weight: 800; }
.plan-card .p-term { font-size: 12px; color: var(--muted); }

/* ---------- Modal system ---------- */
.np-modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(2, 6, 23, 0.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: np-fade 0.15s ease;
}
.np-modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 24px 64px rgba(2, 6, 23, 0.4); width: 100%; max-width: 430px;
  padding: 22px; animation: np-pop 0.16s ease;
}
.np-modal-icon {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 22px; margin-bottom: 14px;
}
.np-modal-icon.np-i-destructive, .np-modal-icon.np-i-error { background: rgba(220, 38, 38, 0.14); }
.np-modal-icon.np-i-warn { background: rgba(217, 119, 6, 0.16); }
.np-modal-icon.np-i-info { background: var(--primary-soft); }
.np-modal-icon.np-i-success { background: rgba(22, 163, 74, 0.14); }
.np-modal-title { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 8px; }
.np-modal-body { font-size: 13.5px; color: var(--muted); line-height: 1.55; word-break: break-word; }
.np-modal-body b, .np-modal-body strong { color: var(--text); }
.np-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
@keyframes np-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes np-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Utility ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-right { text-align: right; }
.role-pill { text-transform: capitalize; }

/* ---------- Print (PDF export) ---------- */
@media print {
  .sidebar, .topbar, .bottom-nav, .rpt-actions, .btn-row, .flash, .notice, .toast, .no-print { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .report-paper { border: none; box-shadow: none; padding: 0; }
  table.rpt th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .content { padding: 18px 14px 110px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0 14px; }
  .user-chip .u-name { display: none; }
}

@media (max-width: 520px) {
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 20px; }
}
