:root {
  color-scheme: light;
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --border: #e3e6ee;
  --text: #15182a;
  --text-soft: #5a6077;
  --muted: #8a91a8;
  --primary: #4a3aff;
  --primary-soft: #ece9ff;
  --primary-hover: #3729d8;
  --success: #16a55a;
  --warning: #d68a00;
  --danger: #d6443a;
  --shadow: 0 8px 24px rgba(20, 24, 60, 0.06);
  --shadow-lg: 0 12px 40px rgba(20, 24, 60, 0.10);
  --radius: 14px;
  --radius-sm: 10px;
  --chart-h: 260px;
  --chart-h-wide: 300px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4a3aff, #7d6cff);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 18px rgba(74, 58, 255, 0.35);
}
.brand-text h1 { font-size: 17px; }
.brand-text p { margin: 0; color: var(--text-soft); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.status-pill {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}
.status-pill-muted { background: #eef0f5; color: var(--text-soft); }
.status-pill-ok { background: #def7ea; color: var(--success); }
.status-pill-warn { background: #fff1d6; color: var(--warning); }
.status-pill-error { background: #ffe1de; color: var(--danger); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 73px);
}
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 22px 22px 32px;
  overflow-y: auto;
  position: sticky;
  top: 73px;
  align-self: start;
  height: calc(100vh - 73px);
}
.dashboard {
  padding: 26px 32px 60px;
  min-width: 0;
}

@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
}

/* Sidebar panels */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px 0 18px;
}
.panel + .panel { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-soft); margin-bottom: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.field input,
.field select,
.field textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--primary); background: var(--surface); }
.field textarea { resize: vertical; min-height: 56px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.field-check {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 0; font-size: 13px;
}
.field-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

.advanced { margin: 4px 0 14px; }
.advanced summary {
  cursor: pointer; padding: 8px 0;
  font-size: 12px; font-weight: 600; color: var(--primary);
  list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: "+ "; }
.advanced[open] summary::before { content: "− "; }

.sidebar-actions { display: grid; gap: 8px; margin-top: 10px; }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, transform 0.05s, border-color 0.15s, color 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-soft); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.hint { font-size: 12px; color: var(--text-soft); margin: 8px 0 0; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-soft);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.empty-state h2 { font-size: 18px; color: var(--text); margin-bottom: 8px; }

/* Dashboard sections */
.report-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.report-meta h2 { font-size: 22px; }
.report-meta p { margin: 4px 0 0; color: var(--text-soft); font-size: 13px; }
.jql-pill {
  background: var(--surface);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-soft);
  max-width: 70%;
  word-break: break-word;
}

/* KPIs */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi span { font-size: 12px; color: var(--text-soft); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi strong { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.kpi em { font-style: normal; font-size: 12px; color: var(--text-soft); }

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.chart-card-wide { grid-column: span 2; }
@media (max-width: 760px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-card-wide { grid-column: auto; }
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
  box-shadow: var(--shadow);
}
.chart-card header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 10px;
}
.chart-card h3 { font-size: 14px; }
.chart-card canvas { width: 100% !important; height: var(--chart-h) !important; max-height: var(--chart-h); }
.chart-card-wide canvas { height: var(--chart-h-wide) !important; max-height: var(--chart-h-wide); }
.muted { color: var(--text-soft); font-size: 12px; }

/* Missing card */
.missing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 22px;
}
.missing-card header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.missing-card table { width: 100%; border-collapse: collapse; }
.missing-card th, .missing-card td { padding: 8px 6px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
.missing-card th { font-size: 12px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.missing-card td:nth-child(2), .missing-card td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }

/* Detail */
.detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.detail-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.detail-head h3 { font-size: 14px; flex: 0 0 auto; }
.detail-head input {
  flex: 1 1 220px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.detail-table-wrap { overflow-x: auto; max-height: 500px; }
#detailTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
#detailTable th {
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
  text-align: left;
  font-weight: 600;
  color: var(--text-soft);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 9px 8px;
  border-bottom: 2px solid var(--border);
}
#detailTable td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
#detailTable tr:hover td { background: var(--surface-2); }
#detailTable a { color: var(--primary); text-decoration: none; }
#detailTable a:hover { text-decoration: underline; }
.cell-summary { max-width: 320px; }

/* Status bar */
.status-bar {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-width: calc(100vw - 40px);
}
.status-bar.error { background: var(--danger); }
.status-bar.ok { background: var(--success); }
