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

:root {
  --bg-base:       #0d1117;
  --bg-surface:    #161b22;
  --bg-elevated:   #1c2230;
  --bg-hover:      #21283a;
  --border:        rgba(255,255,255,0.08);
  --border-active: rgba(99,179,237,0.4);

  --text-primary:  #e2e8f0;
  --text-muted:    #64748b;
  --text-dim:      #94a3b8;

  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --accent-glow:   rgba(59,130,246,0.15);

  --success:       #22c55e;
  --success-bg:    rgba(34,197,94,0.1);
  --error:         #ef4444;
  --error-bg:      rgba(239,68,68,0.1);
  --warning:       #f59e0b;
  --warning-bg:    rgba(245,158,11,0.1);

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   20px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 0 3px var(--accent-glow);

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(13,17,23,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0 1.5rem;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: white;
  box-shadow: 0 2px 12px rgba(99,102,241,0.35);
  flex-shrink: 0;
}
.logo-title {
  display: block; font-size: 1rem; font-weight: 700; letter-spacing: -0.01em;
}
.logo-subtitle {
  display: block; font-size: 0.7rem; color: var(--text-muted); font-weight: 400;
  letter-spacing: 0.02em; text-transform: uppercase;
}
.header-right { display: flex; align-items: center; gap: 0.75rem; }

.env-badge {
  display: flex; align-items: center; gap: 0.4rem;
  background: var(--warning-bg);
  border: 1px solid rgba(245,158,11,0.25);
  color: var(--warning);
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
}
.env-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--warning);
  animation: pulse 2s infinite;
}

/* ── Status pill ─────────────────────────────────────────────────────────── */
.status-pill {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: 99px;
  font-size: 0.75rem; font-weight: 600;
  border: 1px solid transparent;
  transition: all var(--transition);
}
.status-pill.status-connected {
  background: var(--success-bg); border-color: rgba(34,197,94,0.25); color: var(--success);
}
.status-pill.status-disconnected {
  background: rgba(255,255,255,0.04); border-color: var(--border); color: var(--text-muted);
}
.status-pill.status-expired {
  background: var(--error-bg); border-color: rgba(239,68,68,0.25); color: var(--error);
}
.pill-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.status-connected .pill-dot { animation: pulse 2s infinite; }

/* ── Setup banner ────────────────────────────────────────────────────────── */
.setup-banner {
  background: linear-gradient(90deg, rgba(245,158,11,0.08), rgba(245,158,11,0.04));
  border-bottom: 1px solid rgba(245,158,11,0.2);
}
.setup-banner-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 0.82rem;
}
.setup-icon { font-size: 1.1rem; }
.setup-banner strong { color: var(--warning); }
.setup-banner p { color: var(--text-dim); margin: 0; }
.setup-banner-inner > div { flex: 1; }

/* ── Main layout ─────────────────────────────────────────────────────────── */
.app-main {
  max-width: 1400px; margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 1024px) {
  .app-main { grid-template-columns: 1fr; }
  .card-tall { min-height: 600px; }
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: border-color var(--transition);
}
.card:hover { border-color: rgba(255,255,255,0.12); }
.card-tall {
  display: flex; flex-direction: column;
  min-height: 70vh;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}
.card-title {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.9rem; font-weight: 600; color: var(--text-primary);
  letter-spacing: -0.01em;
}
.card-title svg { color: var(--text-muted); }
.card-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.card-body.no-pad { padding: 0; }
.card-footer {
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: auto;
}

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 0.4rem; }
.field-label {
  font-size: 0.8rem; font-weight: 600; color: var(--text-dim);
  display: flex; flex-direction: column; gap: 0.15rem;
}
.field-hint { font-size: 0.72rem; font-weight: 400; color: var(--text-muted); }
.field-hint-block {
  font-size: 0.72rem; color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  margin-top: 0.25rem;
}
.field-hint-block code { font-family: var(--font-mono); color: var(--text-dim); font-size: 0.7rem; }

.input-wrapper { position: relative; }
.input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder { color: var(--text-muted); }
.input:focus { border-color: var(--accent); box-shadow: var(--shadow-glow); }
.input.input-mono { font-family: var(--font-mono); font-size: 0.8rem; }
.input-check {
  position: absolute; right: 0.65rem; top: 50%; transform: translateY(-50%);
  font-size: 0.9rem;
}

.field-error { font-size: 0.75rem; color: var(--error); }

/* ── Config details ──────────────────────────────────────────────────────── */
.config-details { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.config-summary {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  font-size: 0.82rem; font-weight: 500; color: var(--text-dim);
  background: var(--bg-elevated);
  list-style: none;
  transition: background var(--transition);
}
.config-summary::-webkit-details-marker { display: none; }
.config-summary:hover { background: var(--bg-hover); color: var(--text-primary); }
.config-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.85rem; }
.config-tag {
  margin-left: auto;
  font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem; border-radius: 99px;
}
.config-tag-missing { background: var(--error-bg); color: var(--error); border: 1px solid rgba(239,68,68,0.2); }
.config-tag-ok { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }

.info-box {
  background: rgba(59,130,246,0.06);
  border: 1px solid rgba(59,130,246,0.18);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  font-size: 0.78rem;
  display: flex; flex-direction: column; gap: 0.4rem;
}
.info-box strong { color: #93c5fd; }
.info-box p { color: var(--text-dim); }
.info-box code { font-family: var(--font-mono); color: #c4b5fd; font-size: 0.75rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap; flex-shrink: 0;
  text-decoration: none;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px rgba(59,130,246,0.4);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.14);
}
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-dim); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.77rem; }
.btn-icon { padding: 0.4rem; border-radius: var(--radius-sm); }

/* ── Auth section specifics ──────────────────────────────────────────────── */
.auth-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.connected-info {
  background: var(--success-bg);
  border: 1px solid rgba(34,197,94,0.2);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.connected-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.connected-label { font-size: 0.75rem; color: var(--text-muted); }
.connected-value { font-size: 0.8rem; color: var(--text-primary); font-weight: 500; }
.connected-value.mono { font-family: var(--font-mono); letter-spacing: 0.03em; }
.refresh-warning {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.72rem; color: var(--warning);
}

.expiry-badge {
  font-size: 0.7rem; font-weight: 600; padding: 0.2rem 0.55rem;
  border-radius: 99px;
}
.expiry-fresh { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.expiry-soon  { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,0.2); }
.expiry-gone  { background: var(--error-bg);   color: var(--error);   border: 1px solid rgba(239,68,68,0.2); }

.save-msg { font-size: 0.75rem; padding: 0.3rem 0; }
.save-msg.ok { color: var(--success); }
.save-msg.err { color: var(--error); }

/* ── Editor ──────────────────────────────────────────────────────────────── */
.editor-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.select-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.78rem; font-weight: 500;
  padding: 0.35rem 0.65rem;
  outline: none; cursor: pointer;
}
.select-input:focus { border-color: var(--accent); }

.validation-bar {
  padding: 0.5rem 1.25rem;
  font-size: 0.78rem;
  display: flex; align-items: center; gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.validation-bar.valid   { background: var(--success-bg); color: var(--success); }
.validation-bar.invalid { background: var(--error-bg);   color: var(--error); }

.editor-wrap {
  flex: 1; display: flex; min-height: 0;
  position: relative;
  border-bottom: 1px solid var(--border);
}
.line-numbers {
  padding: 1rem 0;
  min-width: 3rem; text-align: right;
  font-family: var(--font-mono);
  font-size: 0.75rem; line-height: 1.6;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  user-select: none;
  overflow: hidden;
}
.line-numbers span {
  display: block; padding: 0 0.6rem;
  height: 1.6em;
}
.xml-editor {
  flex: 1; resize: none;
  background: transparent;
  border: none; outline: none;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem; line-height: 1.6;
  color: #c9d1d9;
  tab-size: 2;
  width: 100%;
  overflow: auto;
}
.xml-editor::placeholder { color: var(--text-muted); font-family: var(--font-sans); font-size: 0.82rem; }

.editor-status {
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 0.72rem; color: var(--text-muted);
}
.xml-validity.valid   { color: var(--success); }
.xml-validity.invalid { color: var(--error); }

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

/* ── History table ───────────────────────────────────────────────────────── */
.history-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.history-table thead { background: var(--bg-elevated); }
.history-table th {
  padding: 0.65rem 1rem;
  text-align: left; font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.history-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  vertical-align: middle;
}
.history-table tbody tr { transition: background var(--transition); }
.history-table tbody tr:hover { background: var(--bg-elevated); }
.history-table tbody tr:last-child td { border-bottom: none; }

.status-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.55rem; border-radius: 99px;
  font-size: 0.7rem; font-weight: 600;
}
.status-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.status-failed  { background: var(--error-bg);   color: var(--error);   border: 1px solid rgba(239,68,68,0.2); }

.uuid-cell { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; align-items: center; gap: 0.35rem; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  padding: 3rem 1.5rem;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.6; }
.empty-state p { font-weight: 500; color: var(--text-dim); }
.empty-state span { font-size: 0.8rem; color: var(--text-muted); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.18s ease;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  width: 100%; max-width: 680px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: slideUp 0.22s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.95rem; font-weight: 600; }
.modal-body { padding: 1.25rem; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; }

.error-rule {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.3rem;
}
.error-rule.rule-error { border-left: 3px solid var(--error); }
.error-rule.rule-warning { border-left: 3px solid var(--warning); }
.rule-code { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.rule-desc { font-size: 0.82rem; color: var(--text-primary); }
.rule-severity {
  font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.12rem 0.45rem; border-radius: 99px; align-self: flex-start;
}
.sev-error   { background: var(--error-bg); color: var(--error); }
.sev-warning { background: var(--warning-bg); color: var(--warning); }

.xml-preview {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: pre-wrap; word-break: break-all;
  max-height: 240px; overflow-y: auto;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300;
  display: flex; flex-direction: column; gap: 0.5rem;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 0.65rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  font-size: 0.82rem;
  max-width: 360px;
  animation: slideInRight 0.25s cubic-bezier(0.34,1.56,0.64,1);
  transition: opacity 0.3s, transform 0.3s;
}
.toast.hiding { opacity: 0; transform: translateX(16px); }
.toast-icon { font-size: 1rem; flex-shrink: 0; margin-top: 0.05rem; }
.toast-content { display: flex; flex-direction: column; gap: 0.1rem; }
.toast-title { font-weight: 600; color: var(--text-primary); }
.toast-msg { color: var(--text-dim); font-size: 0.78rem; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--error); }
.toast-info    { border-left: 3px solid var(--accent); }
.toast-warning { border-left: 3px solid var(--warning); }

/* ── Spinners / Loading ──────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes fadeIn   { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
@keyframes slideInRight { from { opacity:0; transform:translateX(20px) } to { opacity:1; transform:translateX(0) } }
@keyframes pulse {
  0%, 100% { opacity: 1 }
  50%       { opacity: 0.4 }
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Pre-flight checklist ────────────────────────────────────────────────── */
.preflight-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.preflight-title {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 0.85rem;
  font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--border);
}
.preflight-items { display: flex; flex-direction: column; }
.preflight-item {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.preflight-item:last-child { border-bottom: none; }
.preflight-item > div { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 0; }
.preflight-item strong { color: var(--text-primary); font-size: 0.78rem; }
.check-detail { color: var(--text-muted); font-size: 0.72rem; }
.check-code {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: #93c5fd;
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  display: inline-block;
  margin-top: 0.1rem;
  word-break: break-all;
}
.check-icon {
  flex-shrink: 0; width: 18px; height: 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700;
  margin-top: 0.1rem;
}
.check-ok   { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34,197,94,0.25); }
.check-warn { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,0.25); }
.check-pending { opacity: 0.85; }

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
code { font-family: var(--font-mono); font-size: 0.85em; color: #c4b5fd; }
