/* ------------------------------------------------------------------
   Base elements and shared components: controls, cards, tables,
   pills, modals and the in-page sub-tabs.
   ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

/* Must beat the display rules below, which would otherwise override [hidden]. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--text); line-height: 1.25; }
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.5px; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.75rem; }
h3 { font-size: 1.02rem; font-weight: 700; margin: 0 0 0.75rem; }
h4 { font-size: 0.92rem; font-weight: 700; margin: 0 0 0.5rem; }

a { color: var(--brand); }
a:hover { color: var(--brand-hover); }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* ---------- Buttons ---------- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover { background: var(--brand-hover); }

button.secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

button.secondary:hover { background: var(--surface-muted); border-color: var(--border-strong); }

button.danger { background: var(--surface); border-color: var(--brand-line); color: var(--danger); }
button.danger:hover { background: var(--brand-soft); }

button:disabled { cursor: not-allowed; opacity: 0.5; }

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ---------- Form controls ---------- */
input, select, textarea {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea { padding: 10px 12px; }

input[type="checkbox"], input[type="radio"] {
  min-height: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--brand);
}

input[type="file"] { min-height: 0; padding: 6px; border-style: dashed; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

input::placeholder, textarea::placeholder { color: var(--faint); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.metric span { display: block; color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.metric strong { color: var(--text); font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom-color: var(--border);
  white-space: nowrap;
}

tbody tr:hover > td { background: var(--brand-tint); }
tbody tr:last-child > td { border-bottom: 0; }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.pill.warn { background: var(--brand-soft); color: var(--brand-ink); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

/* ---------- In-page sub-tabs (underline style, like the page menu) ---------- */
.subtabs {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.subtabs::-webkit-scrollbar { display: none; }

.subtab {
  flex-shrink: 0;
  min-height: 0;
  padding: 0 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.subtab:hover { background: transparent; color: var(--text); }

.subtab.active {
  color: var(--brand);
  font-weight: 600;
  border-bottom-color: var(--brand);
}

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(28, 27, 31, 0.45);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(720px, 90vh);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
}

.modal-card h3 { margin: 0 0 0.5rem; padding-right: 2.5rem; }

.modal-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
}

.modal-card label input {
  display: block;
  width: 100%;
  margin-top: 6px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.detail-row {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}

.detail-row:last-child { border-bottom: 0; }
.detail-row span { color: var(--muted); }
.detail-row strong { color: var(--text); }

/* ---------- Filter rows ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.filters > label:not(.checkbox-label):not(.inline-check) {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-weight: 500;
}

.filters textarea { flex: 1 1 260px; font-family: inherit; resize: vertical; }

.checkbox-label,
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  cursor: pointer;
}

.checkbox-label input { width: 16px; }
