:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2f3f56;
  --text: #e8eef7;
  --muted: #8fa3bf;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse at top, #1e3a5f 0%, var(--bg) 55%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 0.75rem;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}

.brand-icon.sm {
  width: 32px;
  height: 32px;
  font-size: 1rem;
  margin: 0;
}

.brand h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
}

.brand p,
.subtitle,
.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  margin-top: 0.75rem;
}

input,
textarea,
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn.primary {
  background: var(--accent);
  color: white;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

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

.btn.success {
  background: #166534;
  color: #bbf7d0;
}

.btn.danger {
  background: #7f1d1d;
  color: #fecaca;
}

.error {
  color: #fca5a5;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.feedback {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--success);
}

#login-btn {
  width: 100%;
  margin-top: 1.25rem;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  padding: 0 0.5rem;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}

.nav-item:hover,
.nav-item.active {
  background: var(--surface2);
  color: var(--text);
}

.nav-item.active {
  border-left: 3px solid var(--accent);
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}

.main {
  padding: 1.5rem 2rem;
  overflow: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.topbar h2 {
  margin: 0 0 0.25rem;
}

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

.pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pill-ok {
  background: #14532d;
  color: #86efac;
}

.pill-warn {
  background: #78350f;
  color: #fde68a;
}

.pill-neutral {
  background: var(--surface2);
  color: var(--muted);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.card-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 700;
}

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

.panel h3 {
  margin: 0 0 1rem;
}

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

.panel-header h3 {
  margin: 0;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

td code {
  font-size: 0.75rem;
  word-break: break-all;
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

.tag-builtin {
  background: #1e3a5f;
  color: #93c5fd;
}

.tag-custom {
  background: #365314;
  color: #bef264;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  margin-right: 0.5rem;
}

.btn-link.danger {
  color: #f87171;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
  cursor: pointer;
}

.switch input {
  width: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.code-block {
  margin-top: 1rem;
  padding: 1rem;
  background: #0a0e14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  font-size: 0.8rem;
  line-height: 1.45;
  max-height: 360px;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  background: var(--surface);
  color: var(--text);
  max-width: 480px;
  width: 92vw;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.provider-block {
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: var(--radius);
}

.provider-block h4 {
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--accent);
}

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

  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  nav {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
  }

  .logout-btn {
    margin-left: auto;
  }
}
