:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --positive: #16a34a;
  --negative: #dc2626;
  --warn: #d97706;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex: 0 0 230px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
}
.sidebar h1 { font-size: 17px; margin: 0 0 18px; }
.sidebar nav a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.sidebar nav a:hover { background: #f1f5f9; text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .section {
  margin: 18px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.entity-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 7px;
}

.content { flex: 1; padding: 24px 28px; max-width: 1400px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-header h2 { margin: 0; font-size: 22px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 24px; font-weight: 600; margin-top: 6px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .layout { flex-direction: column; } .sidebar { width: 100%; flex: none; } }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.muted { color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: #e2e8f0; color: #334155;
}
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.ok { background: #dcfce7; color: #166534; }

.input, select, textarea {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #fff; font-family: inherit;
}
.input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px;
  background: var(--primary); color: #fff; border: none; cursor: pointer;
  font-size: 14px; font-family: inherit;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--negative); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; background: #e0e7ff; }
.messages li.warning { background: #fef3c7; }
.messages li.error { background: #fee2e2; }
.messages li.success { background: #dcfce7; }

.auth-wrapper { max-width: 380px; margin: 8vh auto; }
.auth-wrapper .card { padding: 26px; }
.auth-wrapper h2 { margin-top: 0; }
.auth-wrapper .input { width: 100%; margin-bottom: 12px; }

.chart-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.chart-box h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.form-grid { display: grid; gap: 12px; max-width: 620px; }
.form-grid label { font-size: 13px; color: var(--muted); }
.errorlist { color: var(--negative); font-size: 13px; margin: 4px 0; padding-left: 16px; }
.htmx-request { opacity: .55; }
