/* ── Variables ────────────────────────────────────────────────── */
:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --surface-alt:  #f8fafc;
  --line:         #e2e8f0;
  --text:         #0f172a;
  --text-2:       #475569;
  --muted:        #94a3b8;
  --accent:       #2563eb;
  --accent-h:     #1d4ed8;
  --accent-light: #eff6ff;
  --success:      #16a34a;
  --success-light:#dcfce7;
  --danger:       #dc2626;
  --danger-light: #fee2e2;
  --warn:         #d97706;
  --warn-light:   #fef3c7;
  --sidebar:      #0d1526;
  --sidebar-2:    #162035;
  --shadow-s:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:       0 4px 16px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
  --shadow-l:     0 20px 60px rgba(0,0,0,.14);
  --r:            10px;
  --r-l:          18px;
  --ease:         0.18s ease;
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); }

/* ── Auth Gate ────────────────────────────────────────────────── */
.auth-gate {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-brand {
  background: linear-gradient(160deg, #0d1526 0%, #0a1020 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  position: relative;
  overflow: hidden;
}

.auth-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(37,99,235,.22) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(37,99,235,.12) 0%, transparent 50%);
  pointer-events: none;
}

.auth-brand-inner {
  position: relative;
  max-width: 360px;
  color: #fff;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}

.auth-logo-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: #e2e8f0;
}

.auth-tagline {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
  color: #f8fafc;
  margin-bottom: 32px;
}

.auth-features {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 14px;
}

.auth-features li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.auth-features li svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #60a5fa;
}

.auth-form-panel {
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
}

.auth-form-inner {
  width: 100%;
  max-width: 380px;
}

/* Auth tabs */
.auth-tabs {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 28px;
  background: var(--surface-alt);
}

.auth-tab {
  flex: 1;
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
  transition: background var(--ease), color var(--ease);
  border-radius: 0;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-s);
}

/* Auth forms */
.auth-form { display: none; }
.auth-form.active { display: grid; gap: 18px; }

/* ── Form Fields ──────────────────────────────────────────────── */
.field { display: grid; gap: 6px; }

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field input,
.field select,
textarea,
.search-input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--ease), box-shadow var(--ease);
  outline: none;
}

.field input:focus,
.field select:focus,
textarea:focus,
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.field-row {
  display: flex;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.field-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.field-row input {
  flex: 1;
  border: none;
  border-radius: 0;
  padding: 10px 14px;
  outline: none;
  font-size: 0.875rem;
}

.btn-show-pw {
  padding: 0 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border-left: 1.5px solid var(--line);
  white-space: nowrap;
  transition: background var(--ease);
}

.btn-show-pw:hover { background: #dbeafe; }

.form-error {
  color: var(--danger);
  font-size: 0.8rem;
  padding: 8px 12px;
  background: var(--danger-light);
  border-radius: var(--r);
}

/* ── Buttons ──────────────────────────────────────────────────── */
.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--r);
  background: var(--accent);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
  box-shadow: 0 1px 3px rgba(37,99,235,.35);
}

.primary-button:hover {
  background: var(--accent-h);
  box-shadow: 0 4px 12px rgba(37,99,235,.35);
}

.primary-button:active { transform: translateY(1px); }

.primary-button svg { width: 14px; height: 14px; }

.primary-button.full-width { width: 100%; justify-content: center; padding: 12px; }

.secondary-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--r);
  background: var(--surface-alt);
  color: var(--text-2);
  border: 1.5px solid var(--line);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--ease), border-color var(--ease);
}

.secondary-button:hover {
  background: var(--line);
  border-color: #c8d5e4;
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: .55;
  pointer-events: none;
}

.danger-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}

.danger-button:hover { filter: brightness(1.12); }
.danger-button:active { transform: translateY(1px); }
.danger-button:disabled { opacity: .55; pointer-events: none; }

/* ── App Shell ────────────────────────────────────────────────── */
.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 240px 1fr;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 8px;
  height: 100dvh;
  overflow-y: auto;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  margin-bottom: 8px;
}

.brand h1 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f1f5f9;
}

.brand p {
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 1px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.nav {
  flex: 1;
  display: grid;
  gap: 2px;
  align-content: start;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--ease), color var(--ease);
}

.nav-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.nav-link:hover {
  background: rgba(255,255,255,.06);
  color: #cbd5e1;
}

.nav-link.active {
  background: rgba(37,99,235,.25);
  color: #93c5fd;
}

/* Sidebar footer */
.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.07);
  padding-top: 16px;
  display: grid;
  gap: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.user-meta { min-width: 0; }

.user-name {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  display: block;
  font-size: 0.7rem;
  color: #475569;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  color: #64748b;
  font-size: 0.8rem;
  font-weight: 500;
  transition: background var(--ease), color var(--ease);
  width: 100%;
}

.btn-logout svg { width: 14px; height: 14px; }

.btn-logout:hover {
  background: rgba(220,38,38,.15);
  color: #fca5a5;
}

/* ── Main Content ─────────────────────────────────────────────── */
.main { padding: 24px 28px; overflow-y: auto; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar-left h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.eyebrow {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 2px;
}

.org-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid rgba(37,99,235,.15);
}

/* ── Metrics Bar ──────────────────────────────────────────────── */
.metrics-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 18px 20px;
  box-shadow: var(--shadow-s);
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

/* ── Panels ───────────────────────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header.with-actions { align-items: center; }

.panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.panel-header p {
  font-size: 0.8rem;
  color: var(--text-2);
  margin-top: 3px;
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 20px;
  box-shadow: var(--shadow-s);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-header.split { align-items: flex-start; flex-wrap: wrap; }

.card-header h4 {
  font-size: 0.875rem;
  font-weight: 700;
}

.card-header p {
  font-size: 0.75rem;
  color: var(--text-2);
  margin-top: 2px;
}

/* ── Status Grid ──────────────────────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.status-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 20px;
  box-shadow: var(--shadow-s);
  position: relative;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  margin-bottom: 12px;
}

.status-dot.ok    { background: var(--success); box-shadow: 0 0 0 3px var(--success-light); }
.status-dot.warn  { background: var(--warn);    box-shadow: 0 0 0 3px var(--warn-light); }
.status-dot.error { background: var(--danger);  box-shadow: 0 0 0 3px var(--danger-light); }

.status-card h4 {
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.status-card p {
  font-size: 0.8rem;
  color: var(--text-2);
}

/* ── Browser Layout ───────────────────────────────────────────── */
.browser-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

/* ── Bucket List ──────────────────────────────────────────────── */
.bucket-list {
  display: grid;
  gap: 8px;
}

.bucket-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--surface-alt);
  transition: border-color var(--ease), background var(--ease);
}

.bucket-item:hover {
  border-color: #c7d9f0;
  background: #f0f7ff;
}

.bucket-item.active {
  border-color: var(--accent);
  background: var(--accent-light);
}

.bucket-item strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.bucket-item div {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Object Table ─────────────────────────────────────────────── */
.object-table, .upload-feed, .table-grid {
  display: grid;
  gap: 8px;
}

.upload-item--failed { border-color: var(--danger); color: var(--danger); }

.table-row, .upload-item, .audit-row {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  font-size: 0.8rem;
}

.table-row strong, .audit-row strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.table-row div, .audit-row div {
  color: var(--text-2);
  font-size: 0.75rem;
}

.audit-filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}


.audit-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
}

.audit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.audit-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.audit-subject {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}

.audit-row-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.75rem;
  color: var(--text-2);
  white-space: nowrap;
  flex-shrink: 0;
}

.audit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.audit-badge--info    { background: var(--accent-light, #e8f0fe); color: var(--accent); }
.audit-badge--success { background: var(--success-light);          color: var(--success); }
.audit-badge--warn    { background: var(--warn-light);             color: var(--warn); }
.audit-badge--danger  { background: var(--danger-light);           color: var(--danger); }

.table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.object-row-main { flex: 1; min-width: 0; }
.object-row-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.object-meta { font-size: 0.75rem; color: var(--text-2); }

.id-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.7rem;
  color: var(--text-2);
  word-break: break-all;
}

.btn-copy-id {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--ease);
}

.btn-copy-id:hover { background: #dbeafe; }

.role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-badge--owner  { background: #fef9c3; color: #854d0e; }
.role-badge--admin  { background: #ede9fe; color: #6d28d9; }
.role-badge--member { background: var(--surface-alt); color: var(--text-2); border: 1px solid var(--line); }

.member-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.role-select {
  padding: 5px 8px;
  border-radius: var(--r);
  border: 1.5px solid var(--line);
  font-size: 0.8rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn-remove-member {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  color: var(--muted);
  transition: background var(--ease), color var(--ease);
}
.btn-remove-member svg { width: 14px; height: 14px; }
.btn-remove-member:hover { background: var(--danger-light); color: var(--danger); }

.btn-copy-url {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid rgba(37,99,235,.15);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--ease);
}

.btn-copy-url:hover { background: #dbeafe; }
.btn-copy-url svg { width: 13px; height: 13px; }

/* ── Dropzone ─────────────────────────────────────────────────── */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 16px;
  min-height: 110px;
  border: 2px dashed #c0d4eb;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(37,99,235,.04) 0%, rgba(255,255,255,.8) 100%);
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}

.dropzone:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.dropzone svg { width: 28px; height: 28px; opacity: .6; }

/* ── Key Reveal ───────────────────────────────────────────────── */
.key-reveal {
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 0.8rem;
  line-height: 1.7;
}

.key-reveal strong { display: block; font-weight: 700; margin-bottom: 4px; color: #92400e; }
.key-reveal code {
  display: block;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--text);
}

/* ── Policy Editor ────────────────────────────────────────────── */
textarea {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.8rem;
  resize: vertical;
  margin-bottom: 14px;
}

/* ── Search ───────────────────────────────────────────────────── */
.search-input {
  width: 200px;
  padding: 7px 12px;
  font-size: 0.8rem;
}

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 32, .5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 20px;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal-box {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-l);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  animation: slideUp .18s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px) }
  to   { opacity: 1; transform: translateY(0) }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 20px;
}

.modal-header h3 { font-size: 1rem; font-weight: 700; }

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transition: background var(--ease), color var(--ease);
}

.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: var(--surface-alt); color: var(--text); }

.modal-form {
  padding: 0 24px 24px;
  display: grid;
  gap: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.field-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Toast Stack ──────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: grid;
  gap: 10px;
  width: 320px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-l);
  animation: toastIn .2s ease;
  border-left: 4px solid transparent;
}

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

.toast.fadeout {
  animation: toastOut .2s ease forwards;
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px) }
}

.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger);  }
.toast--warn    { border-left-color: var(--warn);     }
.toast--info    { border-left-color: var(--accent);   }

.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast-msg  { flex: 1; }

/* ── Loading spinner ──────────────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg) } }

/* ── Settings panel ──────────────────────────────────────────── */
.settings-card {
  padding: 28px 32px;
  margin-bottom: 20px;
}

.settings-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}

.settings-card-desc {
  font-size: 0.875rem;
  color: var(--text-2);
  margin: 0 0 20px;
  line-height: 1.5;
}

.settings-form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  max-width: 420px;
}

.settings-form .field {
  width: 100%;
}

.totp-status-row {
  margin-bottom: 16px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-badge--loading  { background: var(--surface-alt); color: var(--muted); }
.status-badge--enabled  { background: var(--success-light); color: var(--success); }
.status-badge--disabled { background: var(--surface-alt); color: var(--text-2); }

.totp-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  max-width: 420px;
}

.totp-qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--surface-alt);
  border: 1.5px solid var(--line);
  border-radius: var(--r);
}

.totp-qr-wrap img {
  width: 180px;
  height: 180px;
  border-radius: 6px;
}

.totp-secret-text {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--text-2);
  text-align: center;
  word-break: break-all;
}

.totp-verify-row {
  display: flex;
  gap: 8px;
}

.totp-verify-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  letter-spacing: .15em;
  text-align: center;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.totp-verify-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.totp-verify-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell        { grid-template-columns: 1fr; }
  .sidebar          { display: none; }
  .metrics-bar      { grid-template-columns: repeat(3, 1fr); }
  .status-grid      { grid-template-columns: 1fr 1fr; }
  .browser-layout   { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .auth-gate  { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .main { padding: 16px 18px; }
  .metrics-bar { grid-template-columns: 1fr 1fr; }
  .status-grid { grid-template-columns: 1fr; }
  .panel-header { flex-direction: column; gap: 10px; }
  .card-header.split { flex-direction: column; gap: 8px; }
  .search-input { width: 100%; }
}

/* ── Billing panel ────────────────────────────────────────────── */
.billing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.billing-tier-card {
  padding: 24px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1.5px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.billing-tier-card h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  margin: 0;
}

.billing-tier-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.billing-tier-price {
  font-size: 0.85rem;
  color: var(--text-2);
}

.usage-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.usage-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-2);
}

.usage-bar {
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width .4s ease;
}

.usage-bar-fill.warn  { background: var(--warn); }
.usage-bar-fill.danger { background: var(--danger); }

.billing-tier-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.billing-status-banner {
  padding: 14px 20px;
  border-radius: var(--r);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.billing-status-banner.active   { background: var(--success-light); color: var(--success); }
.billing-status-banner.past_due { background: var(--danger-light);  color: var(--danger);  }
.billing-status-banner.canceling { background: var(--warn-light);   color: var(--warn);    }
.billing-status-banner.none     { background: var(--surface-alt);   color: var(--text-2);  }

/* Subscribe / choose-plan card */
.plan-chooser {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 560px;
}

.plan-chooser h4 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-2);
  margin: 0 0 8px;
}

.tier-radio-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tier-radio {
  display: none;
}

.tier-radio-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}

.tier-radio-label:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.tier-radio:checked + .tier-radio-label {
  border-color: var(--accent);
  background: var(--accent-light);
}

.term-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--success-light);
  color: var(--success);
}

.tier-radio-label strong {
  font-size: 0.875rem;
  color: var(--text);
}

.tier-radio-label span {
  font-size: 0.78rem;
  color: var(--text-2);
}

.plan-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-top: 1.5px solid var(--line);
}

.plan-total-row strong {
  font-size: 1.2rem;
  color: var(--text);
}

/* Stripe Payment Element wrapper */
#payment-element-wrap {
  padding: 20px;
  border: 1.5px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}

.billing-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.billing-section-header .settings-card-title { margin: 0; }

/* Plan summary */
.billing-plan-summary { display: flex; flex-direction: column; gap: 0; }

.billing-plan-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}

.billing-plan-row:last-child { border-bottom: none; }

.billing-plan-label { color: var(--text-2); }
.billing-plan-value { color: var(--text); font-weight: 500; }
.billing-plan-price { color: var(--text); font-weight: 600; text-align: right; }

.billing-plan-total .billing-plan-label,
.billing-plan-total .billing-plan-price { font-weight: 700; color: var(--text); }

/* Invoice table */
.invoice-row {
  display: grid;
  grid-template-columns: 110px 1fr 88px 90px auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.875rem;
}

.invoice-row:last-child { border-bottom: none; }

.invoice-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}

.invoice-date  { color: var(--text-2); white-space: nowrap; }
.invoice-desc  { color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invoice-number { color: var(--text-2); font-family: monospace; font-size: 0.8rem; }
.invoice-amount { font-weight: 600; color: var(--text); text-align: right; }

.invoice-status {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.invoice-status.paid    { background: var(--success-light); color: var(--success); }
.invoice-status.open    { background: var(--warn-light);    color: var(--warn);    }
.invoice-status.void    { background: var(--surface-alt);   color: var(--muted);   }

.invoice-links { display: flex; gap: 8px; }
.invoice-links a {
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
}
.invoice-links a:hover { text-decoration: underline; }

@media (max-width: 860px) {
  .billing-grid { grid-template-columns: 1fr; }
  .tier-radio-group { grid-template-columns: 1fr 1fr; }
  .invoice-row { grid-template-columns: 1fr 88px auto; }
  .invoice-date, .invoice-number, .invoice-status { display: none; }
}
