:root {
  /* Light theme (default) — industry standard, matches the design guide */
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #f1f3f7;
  --text: #111827;
  --muted: #6b7280;
  --primary: #3b62f6;
  --primary-2: #2f4fd0;
  --success: #15a34a;
  --danger: #dc2626;
  --warn: #b45309;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
}
:root[data-theme="dark"] {
  --bg: #0f1220;
  --panel: #191d31;
  --panel-2: #212642;
  --text: #e8eaf2;
  --muted: #9aa1bd;
  --primary: #5b7cfa;
  --primary-2: #4864e0;
  --success: #2fbf71;
  --danger: #ef4d63;
  --warn: #f2a33c;
  --border: #2a3050;
  --shadow: none;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
}
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar { background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 0; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); white-space: nowrap; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-logo { flex-shrink: 0; }
.brand-name { font-weight: 700; font-size: 1.2rem; letter-spacing: -0.02em; }
.brand-accent { color: var(--primary); }
.nav { display: flex; align-items: center; gap: 12px; margin-left: auto; flex-wrap: wrap; row-gap: 6px; }
.nav a { color: var(--muted); font-weight: 500; font-size: 0.9rem; white-space: nowrap; }
.nav a:hover { color: var(--text); text-decoration: none; }
.balance { background: var(--panel-2); padding: 6px 12px; border-radius: 999px; font-weight: 600; color: var(--text); }
.btn-ghost { border: 1px solid var(--border); padding: 6px 12px; border-radius: 8px; }
.lang { font-size: 0.8rem; color: var(--muted); }
.lang a { color: var(--muted); padding: 0 3px; }
.lang a.on { color: var(--text); font-weight: 600; }
.lang .sep { opacity: .5; }
.theme-toggle { font-size: 1rem; text-decoration: none; line-height: 1; }
.theme-toggle:hover { text-decoration: none; }
.menu-toggle { display: none; background: none; border: 1px solid var(--border); color: var(--text); font-size: 1.2rem; border-radius: 8px; padding: 4px 10px; margin-left: auto; cursor: pointer; }

/* Layout blocks */
main.wrap { padding-top: 24px; padding-bottom: 40px; min-height: 70vh; }
h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 600; margin: 32px 0 12px; }
h3 { font-size: 1rem; font-weight: 600; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.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); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
/* Dominant KPI (typographic ratio ~2.5 over the 16px base) */
.stat .n { font-size: 2.25rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.stat .l { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }

/* Auth */
.auth { max-width: 420px; margin: 6vh auto; }

/* Forms */
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 0.95rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
textarea { min-height: 90px; font-family: ui-monospace, monospace; }
.btn {
  display: inline-block; background: var(--primary); color: #fff; border: none;
  padding: 10px 16px; border-radius: 8px; font-weight: 600; font-size: 0.95rem; cursor: pointer;
}
.btn:hover { background: var(--primary-2); text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
/* Color discipline: accent stays for the primary action only. Secondary is
   neutral; positive/destructive use soft tints instead of loud solid fills. */
.btn-muted { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-muted:hover { background: var(--panel-2); }
.btn-success { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 40%, transparent); }
.btn-success:hover { background: color-mix(in srgb, var(--success) 20%, transparent); }
.btn-danger { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.inline { display: inline; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 9px; margin-bottom: 14px; border: 1px solid var(--border); }
.flash-success { background: rgba(47,191,113,.15); border-color: var(--success); }
.flash-error { background: rgba(239,77,99,.15); border-color: var(--danger); }
.flash-info { background: rgba(91,124,250,.12); border-color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 560px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; background: var(--panel); }
tr:last-child td { border-bottom: none; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-pending, .badge-processing { background: rgba(242,163,60,.18); color: var(--warn); }
.badge-completed { background: rgba(47,191,113,.18); color: var(--success); }
.badge-rejected { background: rgba(239,77,99,.18); color: var(--danger); }
.badge-manual { background: rgba(91,124,250,.18); color: var(--primary); }

.result-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 14px; white-space: pre-wrap; word-break: break-word; overflow-x: auto; font-family: ui-monospace, monospace; font-size: 0.85rem; }
.result-box img { max-width: 220px; height: auto; border-radius: 8px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.check-form select, .check-form input { width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg-btn { background: transparent; color: var(--muted); border: none; padding: 8px 16px; font-weight: 600; cursor: pointer; font-size: 0.9rem; }
.seg-btn.on { background: var(--primary); color: #fff; }
.bulk-total { font-weight: 600; }
.tab-nav { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn { background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--muted); padding: 8px 14px; font-weight: 600; cursor: pointer; font-size: 0.9rem; }
.tab-btn.on { color: var(--text); border-bottom-color: var(--primary); }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal-box { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 640px; }
.modal-close { position: absolute; top: 12px; right: 12px; background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; font-size: 1rem; }
.hidden-tpl { display: none; }
.footer { padding: 24px 16px; color: var(--muted); border-top: 1px solid var(--border); }
details { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; padding: 10px 14px; margin-top: 10px; }
summary { cursor: pointer; font-weight: 600; }

@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: flex-start; margin-left: 0; padding-bottom: 12px; }
  .nav.open { display: flex; }
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
