/* Upgrade Portal SPA — dark card theme. */

:root {
  --bg:        #0b0d12;
  --panel:     #14171f;
  --panel-2:   #1a1e28;
  --border:    #262b38;
  --fg:        #e6e8ee;
  --fg-muted:  #8a92a6;
  --accent:    #4f9dff;
  --accent-2:  #1f6feb;
  --success:   #2ea043;
  --warn:      #d29922;
  --danger:    #f0584c;
  --code-bg:   #0a0c11;

  --radius:    8px;
  --gap:       24px;
  --gap-sm:    12px;
  --transition: 120ms ease;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
}

#header-slot:empty { display: none; }

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

nav {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
}

nav a {
  text-decoration: none;
  color: var(--fg-muted);
  font-size: 0.95rem;
  padding: 0.25rem 0;
  transition: color var(--transition);
}

nav a:hover { color: var(--fg); }
nav a.active { color: var(--accent); font-weight: 600; }

#user-chip {
  margin-left: auto;
  color: var(--fg-muted);
  font-size: 0.9rem;
}

#logout-btn { margin-left: 0.5rem; }

main {
  padding: var(--gap);
  max-width: 1280px;
  margin: 0 auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 0.75rem;
}

th, td {
  padding: 0.6rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

th { background: var(--panel-2); font-weight: 600; color: var(--fg-muted); }

tr:hover td { background: rgba(255, 255, 255, 0.03); }
tr:last-child td { border-bottom: none; }

button {
  cursor: pointer;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font-size: 0.9rem;
  transition: background var(--transition), border-color var(--transition);
}

button:hover { background: var(--panel-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary, button[type="submit"] {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
button.primary:hover, button[type="submit"]:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
}

button.danger {
  border-color: var(--danger);
  color: var(--danger);
  background: transparent;
}
button.danger:hover {
  background: var(--danger);
  color: white;
}

input, select, textarea {
  font: inherit;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 157, 255, 0.25);
}

textarea {
  width: 100%;
  min-height: 28rem;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  resize: vertical;
}

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

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.editor-toolbar #ws-sha {
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--fg-muted);
  font-size: 0.8rem;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  padding: 2px;
}
.mode-toggle button {
  border: none;
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  background: transparent;
  color: var(--fg-muted);
  font-size: 0.85rem;
}
.mode-toggle button.active {
  background: var(--panel-2);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.left-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 16rem;
  flex-shrink: 0;
}
.left-nav li {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.left-nav li:hover { background: var(--panel-2); }
.left-nav li.active {
  background: var(--panel-2);
}
.left-nav li.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent);
  border-radius: var(--radius) 0 0 var(--radius);
}
.left-nav .num {
  display: inline-block;
  width: 1.6rem;
  height: 1.6rem;
  line-height: 1.6rem;
  text-align: center;
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg-muted);
  font-size: 0.75rem;
  margin-right: 0.5rem;
}
.left-nav li.active .num { background: var(--accent); color: white; }

.editor-layout {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
}

.section { display: flex; flex-direction: column; gap: var(--gap-sm); flex: 1 1 auto; }

.list-card {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.item-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color var(--transition);
}
.item-card:hover { border-color: var(--accent); }
.item-card .meta { color: var(--fg-muted); font-size: 0.85rem; margin-top: 0.2rem; }
.item-card .actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.item-card .actions button {
  padding: 0.3rem 0.55rem;
  font-size: 0.95rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-right: 0.4rem;
}
.badge.canary { color: var(--warn); border-color: var(--warn); }
.badge.production { color: var(--success); border-color: var(--success); }
.badge.custom { color: var(--fg-muted); }
.badge.danger { color: var(--danger); border-color: var(--danger); }

.result-panel {
  background: var(--code-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre-wrap;
  margin-top: 0.75rem;
  max-height: 22rem;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.85rem;
}

.error    { color: var(--danger); }
.warn     { color: var(--warn); }
.success  { color: var(--success); }
.healthy  { color: var(--success); font-weight: 600; }
.unhealthy { color: var(--danger); font-weight: 600; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  width: 100%;
  max-width: 36rem;
}
.modal h3 { margin-top: 0; }
.modal label { display: block; margin: 0.65rem 0; }
.modal label > span { color: var(--fg-muted); font-size: 0.85rem; display: block; margin-bottom: 0.2rem; }
.modal label input, .modal label select, .modal label textarea {
  display: block; width: 100%;
}
.modal fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
}
.modal fieldset legend {
  color: var(--fg-muted);
  font-size: 0.8rem;
  padding: 0 0.4rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.login-section {
  max-width: 22rem;
  margin: 6rem auto;
  background: var(--panel);
  padding: 2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.login-section h2 { margin-top: 0; }
.login-section label { display: block; margin: 0.75rem 0; }
.login-section input { width: 100%; }
.login-section button { width: 100%; margin-top: 0.5rem; }

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  min-width: 16rem;
  max-width: 28rem;
  font-size: 0.9rem;
  animation: toast-in 200ms ease;
}
.toast.success { border-left-color: var(--success); }
.toast.warn    { border-left-color: var(--warn); }
.toast.error   { border-left-color: var(--danger); }
@keyframes toast-in {
  from { transform: translateY(-8px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

#audit-filter { display: flex; gap: 0.75rem; align-items: end; margin-top: 0.75rem; }
#audit-filter label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--fg-muted); }

@media (max-width: 768px) {
  main { padding: 1rem; }
  .editor-layout { flex-direction: column; }
  .left-nav { width: 100%; flex-direction: row; overflow-x: auto; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    padding: 0.5rem 0.75rem;
  }
  td {
    border: none;
    padding: 0.25rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
  }
  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--fg-muted);
  }
  textarea { min-height: 16rem; }
  .modal { max-width: none; }
}
