:root {
  --bg: #0e1014;
  --panel: #161b22;
  --panel-alt: #1d2430;
  --text: #e9edf4;
  --muted: #9ba8bf;
  --accent: #EA682E;
  --accent-2: #DC3D2A;
  --accent-soft: rgba(234, 104, 46, 0.15);
  --border: #273042;
  --border-soft: #2e394d;
  --danger: #cf3f48;
  --success: #2eae6b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(234, 104, 46, 0.16), transparent 25%),
    radial-gradient(circle at 80% 80%, rgba(220, 61, 42, 0.14), transparent 28%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px 14px;
  position: sticky;
  top: 12px;
  z-index: 40;
  backdrop-filter: blur(6px);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: #121a26;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(46, 174, 107, 0.15);
}

.brand { display: flex; gap: 12px; align-items: center; }
.logo { width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; }
h1 { margin: 0; font-size: 1.06rem; letter-spacing: 0.2px; }
h2, h3, h4 { margin: 0 0 10px; line-height: 1.2; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.05rem; }
p { margin: 4px 0 0; color: var(--muted); }

.main-content {
  display: grid;
  gap: 16px;
}

.module-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 2px;
}

.module-link {
  text-decoration: none;
  color: #ced9ea;
  border: 1px solid var(--border-soft);
  background: #101723;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  transition: border-color .18s ease, background .18s ease;
}

.module-link:hover {
  border-color: rgba(234, 104, 46, 0.5);
}

.module-link.active {
  background: linear-gradient(90deg, rgba(234, 104, 46, 0.24), rgba(220, 61, 42, 0.2));
  border-color: rgba(234, 104, 46, 0.5);
  color: #fff;
}

.footer-note {
  margin-top: 14px;
  padding: 8px 2px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: right;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-bottom: 8px;
  font-size: 0.76rem;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #ffc8ad;
  background: var(--accent-soft);
  border: 1px solid rgba(234, 104, 46, 0.32);
  border-radius: 999px;
  padding: 4px 9px;
}

.section-subtitle {
  margin: -2px 0 2px;
  font-size: 0.86rem;
  color: var(--muted);
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-alt));
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.grid2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.grid4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--muted);
}

input, select, textarea, button {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--border-soft);
  background: #111722;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
  transition: border-color .18s ease, box-shadow .18s ease, filter .18s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(234, 104, 46, 0.6);
  box-shadow: 0 0 0 3px rgba(234, 104, 46, 0.16);
}

button {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border: none;
  cursor: pointer;
  font-weight: 600;
}
button:hover { filter: brightness(1.08); }

hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.hidden { display: none !important; }
.console {
  max-height: 140px;
  overflow: auto;
  background: #0f131a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.table th, .table td {
  border-bottom: 1px solid var(--border-soft);
  padding: 7px;
  text-align: left;
}
.table th {
  color: #c4d0e4;
  font-weight: 600;
}
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-ok { background: rgba(46, 174, 107, 0.2); color: var(--success); }
.badge-warn { background: rgba(207, 63, 72, 0.2); color: var(--danger); }
#toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  min-width: 180px;
  padding: 10px 14px;
  background: #111722;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }

.auth-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: stretch;
}

.page-login .main-content {
  min-height: calc(100vh - 190px);
  align-content: center;
}

.page-login .topbar {
  position: static;
}

.auth-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-copy h2 {
  font-size: 1.42rem;
}

.auth-points {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

.auth-card {
  max-width: 470px;
  justify-self: end;
  width: 100%;
}

.auth-hero {
  position: relative;
  overflow: hidden;
}

.auth-hero::after {
  content: "";
  position: absolute;
  right: -45px;
  top: -45px;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(234, 104, 46, 0.28), transparent 65%);
  pointer-events: none;
}

.feature-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.auth-form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.auth-form button {
  margin-top: 4px;
}

.chip {
  border: 1px solid var(--border-soft);
  color: #c7d2e6;
  background: #111722;
  border-radius: 999px;
  font-size: 0.76rem;
  padding: 5px 9px;
}

.auth-note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.dashboard-wrap {
  display: grid;
  gap: 14px;
}

.compact {
  padding: 14px 15px;
}

.hero-card {
  border-left: 4px solid var(--accent);
  background: linear-gradient(180deg, #18202b, #1b2430);
}

.primary-grid {
  align-items: start;
}

.section-card {
  display: grid;
  gap: 10px;
}

.module-card {
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--border-soft);
  transition: border-color .2s ease, transform .2s ease;
}

.module-card:hover {
  border-color: rgba(234, 104, 46, 0.55);
  transform: translateY(-2px);
}

.module-link-inline {
  color: #ffd2bd;
  font-size: 0.86rem;
  font-weight: 600;
}

.stat-card {
  padding: 12px 14px;
  border-left: 3px solid rgba(234, 104, 46, 0.5);
}

.stat-card h3 {
  margin: 2px 0 0;
  font-size: 1.35rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.section-head h3 {
  margin: 0;
}

.section-head-actions {
  margin-bottom: 2px;
}

.compact-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
}

.compact-label select {
  margin-top: 0;
  min-width: 230px;
}

.btn-inline {
  width: auto;
  min-width: 120px;
  padding: 8px 12px;
  align-self: start;
}

.btn-secondary {
  background: #1f2a3a;
  border: 1px solid var(--border-soft);
}

.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.stack-list {
  display: grid;
  gap: 8px;
}

.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: #111722;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px;
}

.list-row-db {
  border-left: 3px solid rgba(234, 104, 46, 0.45);
}

.list-row-meta {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 4px;
}

.db-usage-block {
  margin-top: 8px;
}

.db-usage-text {
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 5px;
}

.db-usage-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--panel-alt);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.db-usage-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--success);
}

.db-usage-bar.is-warning span {
  background: var(--accent);
}

.db-usage-bar.is-danger span {
  background: var(--danger);
}

.db-usage-unlimited {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.list-row-actions {
  display: flex;
  gap: 8px;
}

.list-row-actions button {
  width: auto;
  min-width: 100px;
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.card-lite {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: #111824;
  padding: 12px;
}

.terminal-wrap {
  display: grid;
  gap: 10px;
}

.sql-results-card {
  margin-top: 4px;
  overflow-x: auto;
}

.sql-results-card p {
  margin-bottom: 8px;
}

.sql-results-card .table {
  background: #0f1622;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
}

.sql-results-card .table th {
  background: #172132;
  color: #d9e4f7;
}

.sql-results-card .table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.01);
}

.sql-terminal-output {
  background: #0b111a;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  min-height: 220px;
  max-height: 340px;
  overflow: auto;
  padding: 10px;
  font-family: Consolas, Menlo, Monaco, monospace;
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.sql-terminal-line {
  margin-bottom: 4px;
}

.sql-terminal-line.echo {
  color: #bcd0f8;
}

.sql-terminal-line.ok {
  color: #8ce6a3;
}

.sql-terminal-line.warn {
  color: #f8d17c;
}

.sql-terminal-line.error {
  color: #ff9d9d;
}

.sql-terminal-input-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.sql-prompt {
  color: #8fb6ff;
  font-family: Consolas, Menlo, Monaco, monospace;
  font-size: 0.88rem;
  white-space: nowrap;
}

#sqlTerminalInput {
  font-family: Consolas, Menlo, Monaco, monospace;
  font-size: 0.9rem;
}

.collapsible {
  padding: 0;
  overflow: hidden;
}

.collapsible summary {
  list-style: none;
  cursor: pointer;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid transparent;
  background: #151d29;
}

.collapsible summary::-webkit-details-marker {
  display: none;
}

.collapsible[open] summary {
  border-bottom-color: var(--border);
}

.collapsible-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.subcard {
  background: #111722;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, 0.7);
  display: grid;
  place-items: center;
  z-index: 120;
  padding: 16px;
}

.modal-card {
  width: min(900px, 100%);
  margin: 0;
}

.modal-section {
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px;
  background: #0f1622;
}

.modal-section h4 {
  margin-bottom: 8px;
}

.modal-inline {
  align-items: end;
}

.modal-inline input {
  min-width: 260px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.preview-item {
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: #101927;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.preview-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.preview-item b {
  font-size: 1rem;
  color: #e7f0ff;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 8px;
  color: #cfd9ea;
}

.check-inline input {
  width: auto;
  margin: 0;
}

.danger-zone {
  border-color: rgba(207, 63, 72, 0.5);
}

.danger-zone h4 {
  color: #ffb6b6;
}

@media (max-width: 960px) {
  .app-shell { padding: 12px; }
  .topbar { position: static; }
  .topbar-right { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-card { justify-self: stretch; max-width: none; }
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .list-row { grid-template-columns: 1fr; }
  .list-row-actions button { width: 100%; }
  .module-nav { flex-direction: column; }
  .module-link { width: 100%; }
  .footer-note { text-align: left; }
}
