:root {
  --sidebar: #1c2237;
  --sidebar-hover: #262e48;
  --sidebar-active: #2f3a5c;
  --accent: #ffb400;
  --pink: #e6007e;
  --blue: #2f7df6;
  --bg: #f3f4f8;
  --card: #ffffff;
  --text: #22263a;
  --muted: #7a8097;
  --border: #e3e6ef;
  --green1: #7bc96f; --green2: #b9dc9a;
  --red1: #e9896d;   --red2: #f2c3a9;
  --blue1: #5fa8e8;  --blue2: #8ad0dc;
  --grey1: #8f99b7;  --grey2: #c3c9dc;
  --font: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--text); background: var(--bg); font-size: 15px; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 10%, #2c3350 0%, #0d1020 60%), #0d1020; }
.login-card { background: #fff; border-radius: 6px; padding: 40px 36px; width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.5); text-align: center; }
.login-card img { height: 110px; }
.login-card h1 { font-weight: 400; font-size: 38px; margin: 24px 0 28px; }
.login-card input { width: 100%; padding: 14px 16px; border: 1px solid #cfd4e2; border-radius: 4px; margin-bottom: 14px; font-size: 18px; }
.login-card button { width: 100%; padding: 16px; background: var(--blue); color: #fff; border: 0; border-radius: 4px; font-size: 24px; cursor: pointer; }
.login-card button:hover { background: #1f6ae0; }
.login-card .version { color: #9aa0b4; margin-top: 22px; font-size: 14px; }
.login-card .error { color: #c62828; margin: -4px 0 12px; min-height: 20px; font-size: 14px; }
.login-card .lang { position: absolute; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #fff; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background-image: radial-gradient(circle at 0 100%, rgba(255,255,255,.04) 0, transparent 55%), repeating-radial-gradient(circle at 10% 95%, rgba(255,255,255,.025) 0 2px, transparent 2px 14px); }
.sidebar .brand { padding: 10px 20px; background: #fff; display: flex; align-items: center; justify-content: center; }
.sidebar .brand img { height: 64px; max-width: 200px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; padding: 12px 20px; color: #e9ebf3; border-left: 3px solid transparent; }
.sidebar nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .85; }
.sidebar nav a:hover { background: var(--sidebar-hover); }
.sidebar nav a.active { background: var(--sidebar-active); border-left-color: var(--accent); }
.sidebar nav .sub { padding-left: 50px; font-size: 14px; }
.sidebar nav .group { padding: 14px 20px 4px; font-size: 11px; letter-spacing: .08em; color: #8e95ad; text-transform: uppercase; }
.sidebar .foot { padding: 16px 20px; font-size: 12px; color: #8e95ad; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 5; }
.topbar .search { flex: 1; max-width: 420px; display: flex; gap: 8px; }
.topbar .search input { flex: 1; border: 0; border-bottom: 1px solid #cfd4e2; padding: 8px 4px; outline: none; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); padding: 6px 12px; border-radius: 4px; cursor: pointer; position: relative; }
.topbar .user .role { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.topbar .menu { position: absolute; right: 0; top: 110%; background: #fff; border: 1px solid var(--border); border-radius: 4px; min-width: 180px; box-shadow: 0 8px 24px rgba(0,0,0,.12); display: none; z-index: 10; }
.topbar .user.open .menu { display: block; }
.topbar .menu a { display: block; padding: 10px 14px; color: var(--text); }
.topbar .menu a:hover { background: var(--bg); }

.content { padding: 22px 26px; }
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.page-head .right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* ---------- controls ---------- */
.ctl { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #cfd4e2; border-radius: 4px; padding: 6px 10px; }
.ctl label { color: var(--muted); font-size: 13px; }
select, input[type=date], input[type=text], input[type=email], input[type=password], input[type=number], textarea { border: 1px solid #cfd4e2; border-radius: 4px; padding: 7px 10px; background: #fff; }
select:focus, input:focus, textarea:focus { outline: 2px solid rgba(47,125,246,.25); border-color: var(--blue); }
.btn { border: 1px solid #cfd4e2; background: #fff; border-radius: 4px; padding: 8px 14px; cursor: pointer; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: #f6f7fb; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1f6ae0; }
.btn.danger { color: #c62828; border-color: #e5b4b4; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef1f8; color: #4a5172; }
.pill.ok { background: #e3f5e1; color: #2e7d32; }
.pill.warn { background: #fff3cd; color: #8a6d00; }
.pill.bad { background: #fde3e3; color: #b71c1c; }
.pill.gov { background: #e6ecff; color: #2a47b8; }

/* ---------- cards ---------- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 4px; padding: 16px 18px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.panel h3::before { content: ''; width: 30px; height: 1px; background: #b7bccd; }
.panel h3::after { content: ''; flex: 1; height: 1px; background: #e4e7ef; }
.grid2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; }
.grid2 > *, .grid3 > *, .tile { min-width: 0; }
.tile { overflow: hidden; }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.tiles { display: grid; gap: 8px; }
.tiles.c3 { grid-template-columns: repeat(3, 1fr); }
.tiles.c4 { grid-template-columns: repeat(4, 1fr); }
.tiles.c2 { grid-template-columns: repeat(2, 1fr); }
.tile { color: #fff; border-radius: 3px; padding: 14px 14px 10px; min-height: 120px; display: flex; flex-direction: column; justify-content: space-between; }
.tile .label { font-size: 21px; font-weight: 600; text-shadow: 0 1px 1px rgba(0,0,0,.08); }
.tile .sub { font-size: 14px; text-align: right; opacity: .95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .sub small { font-size: 9px; letter-spacing: .05em; margin-left: 2px; }
.tile .value { font-size: 26px; font-weight: 800; text-align: right; line-height: 1.1; }
.tile .value small { font-size: 9px; font-weight: 600; letter-spacing: .05em; margin-left: 3px; }
.tile .delta { font-size: 11px; text-align: right; opacity: .9; margin-top: 2px; white-space: nowrap; }
.tiles.c4 .tile .label { font-size: 18px; }
.tiles.c4 .tile .value { font-size: 22px; }
.tiles.c4 .tile .value small { display: block; margin: 0; }
.tiles.c4 .tile .sub { font-size: 14px; }
.tiles.c4 .tile .value, .tiles.c3 .tile .value { white-space: nowrap; }
.tile.green { background: linear-gradient(135deg, var(--green1), var(--green2)); }
.tile.red   { background: linear-gradient(135deg, var(--red1), var(--red2)); }
.tile.blue  { background: linear-gradient(135deg, var(--blue1), var(--blue2)); }
.tile.grey  { background: linear-gradient(135deg, var(--grey1), var(--grey2)); }
.tile.pink  { background: linear-gradient(135deg, #e0609e, #f0a6c8); }
.tile.gold  { background: linear-gradient(135deg, #e9b545, #f3d79a); }

/* ---------- tables ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { background: #f7f8fb; font-weight: 700; color: #4a5172; position: sticky; top: 0; cursor: pointer; user-select: none; }
table.data th.sorted::after { content: ' ▾'; color: var(--muted); }
table.data th.sorted.asc::after { content: ' ▴'; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: #fafbfe; }
table.data tr.total td { font-weight: 800; background: #f1f3f9; }
table.data tr.clickable { cursor: pointer; }
.table-wrap { overflow: auto; max-height: 70vh; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* ---------- explorer ---------- */
.explorer { display: grid; grid-template-columns: 300px 1fr; gap: 18px; }
.tree { background: #fff; border: 1px solid var(--border); border-radius: 4px; }
.tree h4 { margin: 0; padding: 12px 14px; font-size: 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.tree ul { list-style: none; margin: 0; padding: 6px 0; max-height: 36vh; overflow: auto; border-left: 3px solid #d7dae6; margin-left: 10px; }
.tree li { padding: 7px 12px; display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.tree li:hover, .tree li.active { background: #eef1f8; }
.tree li .id { color: #9aa0b4; font-size: 12px; min-width: 44px; }
.tree li .badges { margin-left: auto; display: flex; gap: 4px; }
.tree li .badges span { background: #e9ecf4; color: #4a5172; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.detail-empty { background: #e9ebf3; color: #9aa0b4; font-size: 30px; padding: 60px; text-align: center; border-radius: 4px; }
.crumb { background: #fff; border: 1px solid var(--border); border-radius: 4px; padding: 10px 14px; display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.crumb a { color: var(--blue); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; max-width: 760px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form label input, .form label select, .form label textarea { font-size: 15px; color: var(--text); }
.form .full { grid-column: 1 / -1; }
.toast { position: fixed; bottom: 20px; right: 20px; background: #22263a; color: #fff; padding: 12px 18px; border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 100; max-width: 420px; }
.toast.err { background: #b71c1c; }
.drop { border: 2px dashed #cfd4e2; border-radius: 6px; padding: 28px; text-align: center; color: var(--muted); background: #fafbfe; cursor: pointer; }
.drop.over { border-color: var(--blue); background: #eef4ff; }
.result-box { margin-top: 14px; }
.result-box .sum { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.result-box .sum span { background: #eef1f8; border-radius: 4px; padding: 6px 10px; font-size: 14px; }
.err-list { max-height: 260px; overflow: auto; font-size: 13px; background: #fff7f7; border: 1px solid #f1c9c9; border-radius: 4px; }
.err-list div { padding: 4px 10px; border-bottom: 1px solid #f6dede; }
.warn-list { max-height: 160px; overflow: auto; font-size: 13px; background: #fffaf0; border: 1px solid #efe0b8; border-radius: 4px; }
.warn-list div { padding: 4px 10px; border-bottom: 1px solid #f5ecd4; }
.chart-box { position: relative; height: 300px; }
.muted { color: var(--muted); }
.note { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 6px; padding: 22px; width: 560px; max-width: 95vw; max-height: 90vh; overflow: auto; }
.modal h3 { margin-top: 0; }
code { background: #eef1f8; padding: 1px 5px; border-radius: 3px; font-size: 13px; }
@media (max-width: 1600px) { .tiles.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tiles.c4 .tile { min-height: 96px; } .tiles.c3 .tile .value small { display: block; margin: 0; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .explorer { grid-template-columns: 1fr; }
  .tiles.c4, .tiles.c3, .tiles.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value, .tiles.c4 .tile .value, .tiles.c3 .tile .value { white-space: normal; font-size: 20px; }
  .tile .label, .tiles.c4 .tile .label { font-size: 16px; }
  .form { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .topbar .search { max-width: 100%; flex-basis: 100%; }
  .crumb, .ctl, .page-head .right { flex-wrap: wrap; }
  .range-custom { display: inline-flex; flex-wrap: wrap; gap: 4px; }
  .content { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .panel { padding: 12px; }
}
.panel .simple { overflow-x: auto; }
