* { box-sizing: border-box; }

:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #d8dbe4;
  --text: #1f2330;
  --muted: #6b7280;
  --accent: #1f4f8b;
  --accent-hover: #163a66;
  --danger: #b3261e;
  --success: #1f7a4d;
  --warn: #b6791b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

header.app-header {
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

header.app-header h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

header.app-header .user-info {
  font-size: 0.85rem;
  opacity: 0.9;
}

header.app-header .user-info button {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 0.5rem;
  font-size: 0.8rem;
}

main {
  max-width: 1100px;
  margin: 1.25rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > .col { flex: 1; min-width: 180px; }

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  color: var(--text);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: 0.75rem; }

.checkbox-group, .radio-group {
  display: flex; gap: 1rem; flex-wrap: wrap; padding: 0.4rem 0;
}
.checkbox-group label, .radio-group label {
  display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 400; margin: 0;
}

button.primary {
  background: var(--accent); color: #fff; border: none;
  padding: 0.55rem 1rem; border-radius: 4px; font: inherit; font-weight: 500;
  cursor: pointer;
}
button.primary:hover { background: var(--accent-hover); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: #fff; color: var(--text); border: 1px solid var(--border);
  padding: 0.5rem 0.9rem; border-radius: 4px; cursor: pointer; font: inherit;
}
button.danger {
  background: var(--danger); color: #fff; border: none;
  padding: 0.5rem 0.9rem; border-radius: 4px; cursor: pointer; font: inherit;
}

.alert {
  padding: 0.6rem 0.85rem; border-radius: 4px; margin-bottom: 0.75rem; font-size: 0.85rem;
  border: 1px solid;
}
.alert.error { background: #fdecea; border-color: #f5c2bf; color: var(--danger); }
.alert.success { background: #e8f5ee; border-color: #b9dcc7; color: var(--success); }
.alert.warn { background: #fff5e1; border-color: #f0d49b; color: var(--warn); }
.alert.info { background: #e8eef9; border-color: #b9c8e3; color: var(--accent); }

table.cases {
  width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
table.cases th {
  text-align: left; background: #eef0f6; padding: 0.5rem; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
table.cases td {
  padding: 0.5rem; border-bottom: 1px solid var(--border);
}
table.cases tr:hover td { background: #f8f9fc; cursor: pointer; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: 0.65rem 0.75rem; border-left: 3px solid var(--accent);
  background: #f8f9fc; margin-bottom: 0.5rem; border-radius: 0 4px 4px 0;
}
.timeline li .meta {
  font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem;
}

.auth-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); padding: 2rem;
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.auth-card .subtitle { color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }

.recovery-code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  background: #fff8e1; border: 1px solid #ecc97c; padding: 0.75rem;
  font-size: 1rem; letter-spacing: 0.5px; word-break: break-all; border-radius: 4px;
  text-align: center;
}

.muted { color: var(--muted); font-size: 0.85rem; }

.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; gap: 0.5rem; flex-wrap: wrap;
}

.hidden { display: none !important; }

/* ==================== Dashboard ==================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.kpi {
  background: linear-gradient(180deg, #fff 0%, #f7f8fc 100%);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.85rem 1rem;
}
.kpi .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
.kpi .value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  margin-top: 0.2rem;
}
.kpi.accent { border-left-color: var(--success); }
.kpi.warn { border-left-color: var(--warn); }

.dash-section { margin-top: 1.25rem; }
.dash-section h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.bar-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.85rem;
}
.bar-row .label { font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .bar {
  background: #eef0f6;
  border-radius: 3px;
  height: 14px;
  position: relative;
  overflow: hidden;
}
.bar-row .bar > .fill {
  background: var(--accent);
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.bar-row .count {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
  text-align: right;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}
.dash-grid .panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  background: #fff;
}
.agency-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.agency-table th, .agency-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.agency-table th:first-child, .agency-table td:first-child {
  text-align: left;
}
.agency-table thead th {
  background: #eef0f6;
  font-weight: 600;
  position: sticky;
  top: 0;
}
