:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #16213a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-2: #38bdf8;
  --danger: #ef4444;
  --warn: #f59e0b;
  --border: #2b3a55;

  --brand-blue: #2f8ff4;
  --brand-blue-light: #5db2ff;
  --brand-dark: #0b0f16;
  --brand-dark-2: #131924;
}

* { box-sizing: border-box; }

.htmx-indicator { opacity: 0; transition: opacity 150ms ease; position: fixed; top: 12px; right: 16px; padding: 6px 12px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }

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

a { color: var(--accent-2); text-decoration: none; }

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

.sidebar {
  width: 220px;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 30px; height: auto; filter: drop-shadow(0 0 10px rgba(47, 143, 244, .5)); }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; color: #fff; }
.brand-accent { color: var(--brand-blue-light); }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--muted); font-size: .92rem; font-weight: 500; transition: background 120ms ease, color 120ms ease; }
.sidebar nav a svg { flex-shrink: 0; opacity: .85; }
.sidebar nav a:hover { background: var(--panel); color: #fff; }
.sidebar nav a.active { background: rgba(47, 143, 244, .15); color: var(--brand-blue-light); }
.sidebar nav a.active svg { opacity: 1; }

.user-box { margin-top: auto; font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

.content { flex: 1; padding: 28px 36px; max-width: 1200px; }

h1, h2, h3 { color: #fff; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

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

.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .value { font-size: 1.8rem; font-weight: 700; color: #fff; }
.kpi .label { color: var(--muted); font-size: .85rem; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-subtitle { color: var(--muted); margin: 4px 0 0; font-size: .92rem; }

.kpi-card {
  position: relative;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  overflow: hidden;
}
.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--kpi-color, var(--brand-blue));
}
.kpi-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--kpi-color, var(--brand-blue));
  background: rgba(47, 143, 244, .15);
  background: color-mix(in srgb, var(--kpi-color, var(--brand-blue)) 15%, transparent);
}
.kpi-body { display: flex; flex-direction: column; gap: 2px; }
.kpi-value { font-size: 1.7rem; font-weight: 700; color: #fff; line-height: 1.1; }
.kpi-label { color: var(--muted); font-size: .83rem; }

.card-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.card-header h3 { margin: 0; }
.card-header-hint { color: var(--muted); font-size: .8rem; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: .9rem; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr { transition: background 100ms ease; }
tbody tr:hover { background: rgba(255, 255, 255, .025); }
tbody tr:last-child td { border-bottom: none; }

.avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-light));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
}
.avatar-lg { width: 56px; height: 56px; font-size: 1.15rem; }

.cell-main { display: flex; align-items: center; gap: 12px; }
.cell-title { color: var(--text); font-weight: 600; }
.cell-sub { color: var(--muted); font-size: .8rem; }

.search-box { position: relative; }
.search-box svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-box input { width: 100%; padding-left: 36px; }

.info-list { display: flex; flex-direction: column; gap: 16px; }
.info-row { display: flex; gap: 12px; align-items: flex-start; }
.info-row svg { color: var(--brand-blue-light); flex-shrink: 0; margin-top: 3px; }
.info-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 2px; }
.info-value { color: var(--text); font-size: .92rem; }

.form-section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--brand-blue-light); font-weight: 700; margin: 26px 0 14px; }
.form-section-title:first-of-type { margin-top: 0; }

.tabs { display: inline-flex; gap: 2px; background: var(--panel-2); padding: 4px; border-radius: 10px; }
.tabs a { padding: 6px 14px; border-radius: 7px; font-size: .85rem; font-weight: 500; color: var(--muted); }
.tabs a:hover { color: #fff; }
.tabs a.active { background: var(--brand-blue); color: #fff; }
.tabs-secondary a.active { background: var(--panel); color: var(--brand-blue-light); }

.group-heading-cell { background: var(--panel-2) !important; font-weight: 600; color: #fff; font-size: .85rem; padding: 10px 18px !important; }
.group-heading-cell .card-header-hint { font-weight: 500; margin-left: 6px; }

.grid-3 { grid-template-columns: repeat(3, 1fr); }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #04150a;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 4px 10px; font-size: .8rem; }
.btn-primary { background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-light)); color: #fff; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary:hover { filter: brightness(1.05); }

.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: .85rem; color: var(--muted); }
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: .9rem;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge-green { background: rgba(34,197,94,.15); color: var(--accent); }
.badge-red { background: rgba(239,68,68,.15); color: var(--danger); }
.badge-warn { background: rgba(245,158,11,.15); color: var(--warn); }
.badge-muted { background: rgba(148,163,184,.15); color: var(--muted); }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--bg);
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
  padding: 56px;
  background:
    radial-gradient(circle at 15% 15%, rgba(47, 143, 244, .35), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(93, 178, 255, .18), transparent 50%),
    linear-gradient(160deg, var(--brand-dark) 0%, var(--brand-dark-2) 100%);
  color: #fff;
  overflow: hidden;
}

.auth-logo {
  width: 400px;
  height: auto;
  filter: drop-shadow(0 0 24px rgba(47, 143, 244, .45));
}

.auth-brand-title { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
.auth-brand-title span { color: var(--brand-blue-light); }
.auth-brand-subtitle { color: rgba(226, 232, 240, .75); max-width: 380px; line-height: 1.5; }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, .5);
}

.auth-card h2 { margin: 0 0 6px; font-size: 1.4rem; }
.auth-card .auth-subtitle { color: var(--muted); margin: 0 0 26px; font-size: .9rem; }

.auth-card input {
  width: 100%;
  padding: 10px 12px;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(47, 143, 244, .25);
}

.auth-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -4px 0 20px;
  font-size: .85rem;
}
.checkbox-row { display: flex; align-items: center; gap: 8px; color: var(--muted); cursor: pointer; }
.checkbox-row input { width: auto; padding: 0; accent-color: var(--brand-blue); cursor: pointer; }
.auth-options a { color: var(--brand-blue-light); }
.auth-options a:hover { text-decoration: underline; }

.btn-brand {
  width: 100%;
  background: linear-gradient(135deg, var(--brand-blue), var(--brand-blue-light));
  color: #fff;
  border: none;
  padding: 11px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: .95rem;
}
.btn-brand:hover { filter: brightness(1.05); }

.auth-back { display: block; text-align: center; margin-top: 18px; font-size: .85rem; color: var(--muted); }
.auth-success { color: var(--brand-blue-light); font-size: .9rem; line-height: 1.5; }

.error-msg { color: var(--danger); font-size: .85rem; margin-top: 8px; }

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { padding: 32px; min-height: 220px; }
}
