*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --text: #e2e8f0;
  --text-muted: #8892b0;
  --primary: #6366f1;
  --primary-hover: #4f52d8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* Sidebar */
.sidebar {
  width: 200px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  padding: 0 16px 16px;
  letter-spacing: 0.5px;
}
.sidebar ul { list-style: none; }
.sidebar li a {
  display: block;
  padding: 8px 16px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar li a:hover { background: var(--surface2); color: var(--text); }
.sidebar li a.active { background: var(--surface2); color: var(--primary); font-weight: 600; }
.nav-section {
  padding: 12px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.sidebar-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}
.session-role {
  font-size: 12px;
  color: var(--text-muted);
}
.btn-logout {
  font-size: 12px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
}
.btn-logout:hover {
  background: var(--surface2);
  color: var(--text);
}

/* Content */
.content {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  overflow-x: auto;
}
h1 { font-size: 22px; margin-bottom: 20px; }
h2 { font-size: 16px; margin: 24px 0 12px; }
h3 { font-size: 14px; margin-bottom: 12px; color: var(--text-muted); }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); word-break: break-all; }
.stat-value.small { font-size: 14px; }

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
th {
  background: var(--surface2);
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: var(--surface2); }
tr.clickable { cursor: pointer; }
.truncate { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: 'Courier New', monospace; font-size: 12px; }
.number { text-align: right; font-family: monospace; }
.small { font-size: 12px; }
.empty { text-align: center; color: var(--text-muted); padding: 24px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Forms */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 24px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; color: var(--text-muted); }
input[type="text"], input[type="number"], select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* Search form */
.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.search-form input, .search-form select { max-width: 300px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); border-color: var(--success); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--danger); border-color: var(--danger); }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert-success { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid var(--success); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Detail tables */
.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  overflow-x: auto;
}
.detail-table { width: 100%; border-collapse: collapse; }
.detail-table th {
  width: 200px;
  background: none;
  text-align: left;
  padding: 6px 12px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}
.detail-table td {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  word-break: break-all;
}


/* Chart */
.chart-wrap {
  margin-top: 16px;
  background: var(--bg);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  justify-content: center;
}
.chart-wrap canvas {
  max-height: 300px;
  max-width: 700px;
  width: 100% !important;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.status-dot.pending { background: #6b7280; }
.status-dot.true    { background: #22c55e; }
.status-dot.false   { background: #ef4444; }

.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 240px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-select {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
}

/* Dashboard section header with controls */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 12px;
}
.section-header h2 { margin: 0; }
.chart-controls { display: flex; gap: 6px; }
.chart-gran-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Dashboard 2-column layout */
.dashboard-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 8px;
}
.dashboard-two-col h2 { margin: 24px 0 12px; }
@media (max-width: 900px) {
  .dashboard-two-col { grid-template-columns: 1fr; }
}

/* Builder donut chart */
.builder-chart-card {
  display: flex;
  align-items: center;
  gap: 24px;
}
.builder-chart-wrap {
  position: relative;
  width: 200px;
  height: 200px;
  flex-shrink: 0;
}
.builder-chart-wrap canvas {
  width: 200px !important;
  height: 200px !important;
}
.builder-center-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  line-height: 1.4;
}
.builder-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.builder-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.builder-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.builder-legend-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.builder-legend-val {
  font-family: monospace;
  font-size: 12px;
  white-space: nowrap;
}

/* Chart wrap override for dashboard (full width) */
.detail-card .chart-wrap {
  height: 260px;
  max-width: 100%;
  padding: 0;
}
.detail-card .chart-wrap canvas {
  max-height: 260px;
  max-width: 100%;
}
