:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6b7a90;
  --border: #e3e9f1;
  --primary: #205f9c;
  --primary-soft: #eef4fc;
  --danger: #d8202f;
  --danger-soft: #fde7e9;
  --normal: #205f9c;
  --low: #6b7a90;
  --urgent: #d8202f;
  --shadow: 0 1px 2px rgba(20, 36, 64, .04), 0 4px 12px rgba(20, 36, 64, .04);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

button {
  font: inherit;
  cursor: pointer;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 0; }

/* Login */

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
}

.login-card p {
  margin: 0 0 20px;
}

.field {
  display: block;
  margin: 12px 0;
}

.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
}

button.primary {
  display: block;
  width: 100%;
  padding: 11px 16px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
  margin-top: 16px;
}

button.primary:hover { filter: brightness(1.05); }

button.ghost {
  padding: 7px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--ink);
}

button.ghost:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* Dashboard */

.dashboard-view { min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
}

.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.role-badge {
  padding: 4px 10px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 28px 40px;
  display: grid;
  gap: 16px;
}

/* KPIs */

.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.kpi-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.kpi-danger .kpi-num { color: var(--danger); }

/* Panels */

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

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-2 {
  grid-template-columns: 1.2fr 1fr;
}

@media (max-width: 1024px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

/* Bars */

.bars {
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 96px 1fr 48px;
  gap: 10px;
  align-items: center;
}

.bar-label {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bar-track {
  background: #f0f3f8;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}

.bar-fill.urgent { background: var(--danger); }
.bar-fill.normal { background: var(--normal); }
.bar-fill.low    { background: var(--low); }

.bar-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 18px 0;
  text-align: center;
}

/* Pie / donut */

.pie-wrap {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  align-items: center;
}

.pie {
  position: relative;
  width: 200px;
  height: 200px;
}

.pie svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pie-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  pointer-events: none;
}

.pie-center-num {
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.pie-center-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.pie-legend {
  display: grid;
  gap: 10px;
  max-height: 200px;
  overflow-y: auto;
  align-content: start;
}

.pie-legend-item {
  display: grid;
  grid-template-columns: 14px 1fr auto auto;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.pie-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
}

.pie-name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-count {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

.pie-pct {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

@media (max-width: 720px) {
  .pie-wrap {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .pie-legend {
    width: 100%;
    max-height: none;
  }
}

/* Type archive */

.archive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.archive-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfe;
  padding: 14px 16px;
}

.archive-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.archive-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--ink);
  font-size: 14px;
}

.archive-group-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.archive-group-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--primary);
  font-size: 16px;
}

.archive-leaf {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
  align-items: baseline;
}

.archive-leaf-name {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive-leaf-slug {
  color: var(--muted);
  font-size: 11px;
  margin-left: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.archive-leaf-count {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

.archive-leaf-count.zero {
  color: var(--muted);
  font-weight: 400;
}

/* Legend */

.legend {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.dot-created { background: var(--primary); }
.dot-resolved { background: #5cba88; }

/* Trend chart */

.trend-chart {
  width: 100%;
  height: 220px;
  position: relative;
}

.trend-chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.trend-grid {
  stroke: #eef2f8;
  stroke-width: 1;
}

.trend-axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.trend-line-created {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
}

.trend-line-resolved {
  fill: none;
  stroke: #5cba88;
  stroke-width: 2;
}

.trend-area-created {
  fill: rgba(32, 95, 156, .08);
  stroke: none;
}

.trend-dot-created { fill: var(--primary); }
.trend-dot-resolved { fill: #5cba88; }

/* Recent table */

.table-wrap {
  overflow-x: auto;
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.recent-table thead th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  background: #f7f9fc;
  border-bottom: 1px solid var(--border);
}

.recent-table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.recent-table tbody tr:last-child td { border-bottom: 0; }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.pill-urgent { background: var(--danger-soft); color: var(--danger); }
.pill-normal { background: var(--primary-soft); color: var(--primary); }
.pill-low    { background: #eef1f5;             color: var(--muted); }

.status-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  background: #eef1f5;
  color: var(--ink);
  font-size: 12px;
}

.status-closed { background: #ebf3ef; color: #2f7d52; }
.status-submitted { background: #fff4e1; color: #ad6b00; }
