:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5b6472;
  --border: #e5e7eb;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --warning: #b45309;
  --success: #15803d;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 10px;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #2d323c;
  --primary: #14b8a6;
  --primary-text: #0f1115;
  --accent: #38bdf8;
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #4ade80;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: var(--primary);
  color: var(--primary-text);
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
}

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

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

input, select, textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  width: 100%;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0.75rem 0 0.35rem;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 50;
}

.brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--primary);
}

.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.icon-btn {
  width: 36px; height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.sidebar {
  position: fixed;
  top: 56px; left: 0; bottom: 0;
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: none;
  flex-direction: column;
  gap: 0.25rem;
  z-index: 40;
}

.sidebar a, .mobile-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.sidebar a.active, .mobile-nav a.active {
  background: rgba(15, 118, 110, 0.1);
  color: var(--primary);
}

.mobile-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 40;
}

main {
  flex: 1;
  margin-top: 56px;
  padding: 1rem;
  min-width: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.page-header h1 { margin: 0; font-size: 1.5rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar input, .toolbar select { width: auto; min-width: 160px; }

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

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.grid > * { min-width: 0; }

.site-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.site-card h2 { margin: 0; font-size: 1.1rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge.active { background: rgba(22,163,74,0.12); color: var(--success); }
.badge.grace { background: rgba(217,119,6,0.12); color: var(--warning); }
.badge.expired { background: rgba(220,38,38,0.12); color: var(--danger); }
.badge.suspended { background: rgba(220,38,38,0.12); color: var(--danger); }
.badge.draft { background: rgba(107,114,128,0.12); color: var(--muted); }
.badge.dummy { background: rgba(14,165,233,0.12); color: var(--accent); }

.meta { font-size: 0.875rem; color: var(--muted); }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tab {
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 2px solid transparent;
}

.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th { color: var(--muted); font-weight: 600; }

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.toast-container {
  position: fixed;
  top: 68px; right: 1rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(420px, calc(100vw - 2rem));
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  animation: slide 0.2s ease;
}

.toast.success { border-left-color: var(--success); }

@keyframes slide {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; min-width: 0; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.actions > * { min-width: 0; }

.toolbar > * { min-width: 0; }
.page-header > * { min-width: 0; }
.tabs > * { min-width: 0; }

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.copy-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.success-line {
  color: var(--success);
  font-weight: 600;
  margin-top: 0.25rem;
}

.warning-line {
  color: var(--warning);
  font-weight: 600;
  margin: 0.25rem 0 0.5rem;
}

.copy-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

.copy-box code {
  flex: 1;
  min-width: 0;
}

.findings {
  list-style: none;
  margin: 0;
  padding: 0;
}

.finding {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.finding:last-child { border-bottom: none; }

.finding-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.finding.severity-ok { color: var(--success); }
.finding.severity-warning { color: var(--warning); }
.finding.severity-critical { color: var(--danger); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 420px;
  width: 100%;
  padding: 1.25rem;
}

@media (min-width: 768px) {
  .sidebar { display: flex; }
  .mobile-nav { display: none; }
  main { margin-left: 240px; padding: 1.5rem; }
}

@media (max-width: 767px) {
  main { padding-bottom: 80px; }
  .toolbar input, .toolbar select { width: 100%; }
  .mobile-nav a {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.4rem 0.2rem;
    font-size: 0.72rem;
  }
  .mobile-nav a span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
}

.usage-row { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.usage-row:last-child { border-bottom: none; }
.usage-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.25rem 0.75rem; margin-bottom: 0.3rem; }
.usage-label { font-weight: 600; font-size: 0.9rem; }
.usage-value { color: var(--muted); font-size: 0.875rem; }
.usage-bar { height: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.usage-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.usage-fill.reached { background: var(--warning); }

.payments-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.payments-method { font-weight: 600; }
.payments-toggle { display: flex; align-items: center; gap: 0.6rem; margin: 0; font-size: 1rem; cursor: pointer; }
.payments-toggle input[type="checkbox"] { width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--primary); }
.payments-note { margin-top: 0.6rem; }
.payments-source { margin-top: 0.4rem; color: var(--text); font-weight: 600; }

.ov-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.ov-cards > * { min-width: 0; }
.ov-count { margin-bottom: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.ov-count-value { font-size: 1.6rem; font-weight: 800; }
.ov-count-label { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.ov-active .ov-count-value { color: var(--success); }
.ov-grace .ov-count-value { color: var(--warning); }
.ov-expired .ov-count-value { color: var(--danger); }
.ov-none .ov-count-value { color: var(--muted); }
.ov-name { font-weight: 600; }
.ov-warnings { display: flex; flex-wrap: wrap; gap: 0.25rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: rgba(15, 118, 110, 0.06); }

.notice { border-left: 4px solid var(--accent); }
.notice-text { margin: 0; font-weight: 600; }
.site-link { color: var(--primary); text-decoration: none; font-weight: 600; }
.site-link:hover { text-decoration: underline; }
