:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: rgba(15, 23, 42, 0.12);
  --text: #0f172a;
  --muted: #64748b;
  --primary: #16a34a;
  --accent: #0ea5e9;
  --shadow: 0 14px 30px rgba(15, 23, 42, 0.08);
  --radius: 18px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: "Space Grotesk", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(800px 500px at 5% -10%, rgba(16, 185, 129, 0.16), transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(14, 165, 233, 0.18), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

.page { max-width: 1100px; margin: 0 auto; padding: 22px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-img {
  width: auto;
  height: 72px;
  max-width: 220px;
  border-radius: 0;
  object-fit: contain;
  background: transparent;
  border: none;
  padding: 0;
}
.title { font-weight: 700; font-size: 18px; }
.subtitle { font-size: 12px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.layout { display: grid; gap: 18px; margin-top: 18px; }
.card {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.auth-gate h2 { margin: 0 0 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h2 { margin: 0; font-size: 18px; }
.auth-gate { text-align: center; }
.auth-gate .row { justify-content: center; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.input {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  min-width: 220px;
  flex: 1;
}
.btn {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  position: relative;
}
.btn.primary { background: linear-gradient(135deg, #16a34a, #15803d); border-color: transparent; color: #f8fafc; }
.btn.ghost { background: transparent; }
.btn:hover { filter: brightness(1.02); }
.btn.loading { opacity: 0.7; pointer-events: none; }
.btn.loading::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.2);
  border-top-color: rgba(15, 23, 42, 0.6);
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  animation: spin 0.9s linear infinite;
}

.pill {
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
}
.mono { font-family: var(--mono); }
.muted { color: var(--muted); font-size: 12px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0;
}
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field.inline { display: flex; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 9px 6px; text-align: left; }
.table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.table tbody tr:hover { background: rgba(15, 23, 42, 0.03); cursor: pointer; }
.table tbody tr.active { background: rgba(22, 163, 74, 0.08); }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #ffffff;
}
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat-value { font-size: 16px; font-weight: 700; margin-top: 4px; }
.empty-state {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 16px;
  color: var(--muted);
  background: rgba(248, 250, 252, 0.6);
  margin-top: 12px;
}
.pre { white-space: pre-wrap; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}
.modal-content {
  width: min(820px, 100%);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
#invBilling { white-space: pre-wrap; }
.divider { height: 1px; background: var(--line); margin: 12px 0; }

@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .kv-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
}
