:root {
  --bg: #f7f8f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #111111;
  --muted: #4b5563;
  --border: #d1d5db;
  --primary: #b5001a;
  --primary-2: #8a0012;
  --accent: #111111;
  --ok: #057a55;
  --warn: #b45309;
  --danger: #b91c1c;
  --shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
}

:root[data-theme='dark'] {
  --bg: #111214;
  --surface: #1b1f24;
  --surface-2: #252a30;
  --text: #f7f7f7;
  --muted: #c2c8d0;
  --border: #39414b;
  --primary: #ef233c;
  --primary-2: #b5001a;
  --accent: #f5f5f5;
  --shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 10%, rgba(181, 0, 26, 0.2), transparent 30%),
    radial-gradient(circle at 85% 0%, rgba(0, 0, 0, 0.25), transparent 40%),
    var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  min-height: 100vh;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem;
}

.topbar {
  background: linear-gradient(135deg, #111, #2d0309 45%, #b5001a);
  color: #fff;
  border-radius: 14px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.topbar h1 {
  margin: 0.2rem 0 0;
  font-size: 1.35rem;
}

.top-actions {
  display: flex;
  gap: 0.5rem;
}

.tab-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.tab-nav a {
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  padding: 0.75rem 0.5rem;
  font-weight: 700;
  min-height: 46px;
}

.tab-nav a.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

#app {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.grid-2,
.grid-3,
.grid-4 {
  display: grid;
  gap: 0.75rem;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.btn {
  border: 0;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

.btn:hover {
  background: var(--primary-2);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.warn {
  background: var(--warn);
}

.btn.danger {
  background: var(--danger);
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  min-height: 42px;
  padding: 0.5rem 0.6rem;
  font: inherit;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

table {
  width: 100%;
  min-width: 1200px;
  border-collapse: collapse;
  background: var(--surface);
}

th,
td {
  border: 1px solid var(--border);
  text-align: center;
  padding: 0.4rem;
  font-size: 0.82rem;
}

th {
  background: #121212;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}

thead th.group {
  background: var(--primary);
}

td.sticky-col,
th.sticky-col {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
}

th.sticky-col {
  background: #121212;
  color: #fff;
}

.stat-input {
  width: 72px;
  min-height: 38px;
  text-align: center;
  padding: 0.3rem;
}

.kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
}

.kpi h3,
.kpi p {
  margin: 0;
}

.kpi p {
  margin-top: 0.25rem;
  font-size: 1.3rem;
  font-weight: 800;
}

.sparkline {
  width: 100%;
  height: 70px;
  display: block;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(181, 0, 26, 0.12), transparent);
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

.recap-text {
  line-height: 1.45;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.7rem;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.4rem;
}

.score-grid .box {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 0.6rem;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 1rem;
  background: #111;
  color: #fff;
  padding: 0.65rem 0.95rem;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.toast.show {
  opacity: 1;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

.pin-form {
  min-width: 280px;
  display: grid;
  gap: 0.8rem;
}

.pin-form h2 {
  margin: 0;
}

.pin-form menu {
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.pill {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.75rem;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

@media (max-width: 760px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

  .tab-nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

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