:root {
  --bg: #12151b;
  --panel: #191d25;
  --panel-alt: #1f2430;
  --border: #2a3040;
  --text: #e7eaf0;
  --text-dim: #8891a3;
  --accent: #e8a33d;
  --accent-dim: #a97a34;
  --ok: #4fd1c5;
  --err: #e5484d;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

.screen { min-height: 100vh; }
.screen[hidden] { display: none !important; }

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.brand-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

/* ---------- login ---------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(232,163,61,0.06), transparent 40%),
    var(--bg);
}
.login-card {
  width: 340px;
  padding: 32px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.login-card .brand { margin-bottom: 16px; }
.login-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0 0 20px;
}
#login-form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
input, select {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 10px;
  font-family: var(--sans);
  font-size: 14px;
}
input:focus, select:focus {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}
button {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--accent);
  color: #1a1200;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.secondary { background: var(--panel-alt); color: var(--text); border: 1px solid var(--border); }
button.small { padding: 6px 10px; font-size: 12px; }
button.ghost-btn { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }

.error-text { color: var(--err); font-size: 13px; }

/* ---------- main console ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.session-info { display: flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 13px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr 300px;
  gap: 1px;
  background: var(--border);
  min-height: calc(100vh - 53px);
}

.sidebar, .content, .wire { background: var(--bg); padding: 18px; overflow-y: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.panel h2 {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.field { margin-bottom: 10px; }
.btn-row { display: flex; gap: 8px; margin-top: 4px; }
.btn-row button { flex: 1; }
.meta-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-top: 10px; font-family: var(--mono); }

.new-col-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
}
.new-col-row input.ncr-name { flex: 1; min-width: 0; }
.new-col-row select.ncr-type { width: 100px; }
.ncr-pk { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.new-col-row .ncr-remove { padding: 4px 8px; }

#new-table-panel > button#create-table-btn { width: 100%; margin-top: 8px; }
#add-col-def-btn { width: 100%; margin-top: 4px; }

.content-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.content-header h1 { font-size: 18px; font-family: var(--mono); font-weight: 500; margin: 0; }

.table-wrap { position: relative; }
table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13px; }
thead th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  cursor: text;
}
tbody td.cell-value:hover { background: var(--panel-alt); }
tbody td.row-actions { cursor: default; width: 40px; text-align: center; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

.empty-state { color: var(--text-dim); font-size: 14px; margin-top: 40px; text-align: center; }

/* ---------- wire log: elemento distintivo della UI ---------- */
.wire { border-left: 1px solid var(--border); background: #0d0f14; }
.wire h2 {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 12px;
}
.wire-sub { color: #4a5163; text-transform: none; letter-spacing: 0; font-size: 11px; }
.wire-log {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.wire-line { white-space: pre-wrap; word-break: break-all; padding: 3px 6px; border-radius: 4px; }
.wire-line.out { color: var(--accent); }
.wire-line.out::before { content: "→ "; color: #6b5730; }
.wire-line.in-ok { color: var(--ok); }
.wire-line.in-ok::before { content: "← "; color: #2f6f68; }
.wire-line.in-err { color: var(--err); background: rgba(229,72,77,0.08); }
.wire-line.in-err::before { content: "← "; color: #8a3033; }

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