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

:root {
  --bg: #050507;
  --bg2: #0a0a10;
  --surface: #0f0f18;
  --surface2: #151520;
  --border: #1a1a2a;
  --border2: #252535;
  --text: #eaeaf0;
  --muted: #6b7084;
  --accent: #7c5cfc;
  --accent2: #a78bfa;
  --green: #34d399;
  --red: #ef4444;
  --orange: #fb923c;
  --blue: #38bdf8;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  --sidebar-w: 240px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent2); text-decoration: none; }

code { font-family: var(--mono); font-size: .84rem; }
.mono { font-family: var(--mono); font-size: .8rem; color: var(--muted); word-break: break-all; }

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ── Auth ─────────────────────────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-container {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.auth-logo {
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#auth-screen h1 {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.auth-sub {
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
  margin-bottom: 28px;
}

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: .85rem;
  color: var(--muted);
}

.auth-toggle a { color: var(--accent2); margin-left: 4px; }

.error-msg {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: .84rem;
  text-align: center;
}

/* ── Form Elements ────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: var(--font);
  transition: border-color .2s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

textarea {
  font-family: var(--mono);
  font-size: .82rem;
  resize: vertical;
  min-height: 100px;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6341e0);
  color: #fff;
}

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

.btn-full { width: 100%; justify-content: center; padding: 12px; }

.btn-sm { padding: 6px 14px; font-size: .8rem; }

.btn-danger { background: rgba(239, 68, 68, .15); color: var(--red); border: 1px solid rgba(239, 68, 68, .3); }

/* ── Console Layout ───────────────────────────────────────────────────── */
#console-screen {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
}

.sidebar-logo {
  padding: 20px 20px;
  font-weight: 800;
  font-size: 1rem;
  color: var(--accent2);
  border-bottom: 1px solid var(--border);
}

.sidebar-logo span { color: var(--text); }

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  color: var(--muted);
  transition: all .15s;
  margin-bottom: 2px;
}

.nav-item:hover { color: var(--text); background: var(--surface2); text-decoration: none; }
.nav-item.active { color: var(--text); background: rgba(124, 92, 252, .1); }

.nav-icon { font-size: 1rem; }

.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid var(--border);
}

.user-info {
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  width: 100%;
  padding: 8px;
  background: rgba(239, 68, 68, .08);
  border: 1px solid rgba(239, 68, 68, .2);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s;
}

.btn-logout:hover { background: rgba(239, 68, 68, .15); }

/* ── Main Content ─────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 32px 40px;
  min-height: 100vh;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-header h1 { font-size: 1.5rem; font-weight: 700; }
.view-header p { color: var(--muted); font-size: .9rem; width: 100%; }

/* ── Stats Grid ───────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

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

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label { font-size: .82rem; color: var(--muted); }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 { font-size: .95rem; font-weight: 600; }

.card-body { padding: 20px; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color .2s;
}

.project-card:hover { border-color: var(--accent); }

.project-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.project-card p { font-size: .84rem; color: var(--muted); margin-bottom: 12px; }

.project-meta {
  display: flex;
  gap: 12px;
  font-size: .78rem;
  color: var(--muted);
}

.project-meta span {
  padding: 2px 8px;
  background: var(--bg2);
  border-radius: 4px;
}

/* ── Data Table ───────────────────────────────────────────────────────── */
.contracts-table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
}

.data-table th, .data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface);
  color: var(--muted);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.data-table tbody tr:hover td { background: rgba(124, 92, 252, .03); }
.data-table code { color: var(--accent2); font-weight: 500; }

/* ── Modal ────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 460px;
}

.modal-content h2 { font-size: 1.2rem; margin-bottom: 20px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.chain-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  color: var(--text);
  cursor: pointer;
}

.check-item input { accent-color: var(--accent); }

/* ── Empty State ──────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: .9rem;
}

/* ── Toast ────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: .86rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .4);
  transform: translateY(20px);
  opacity: 0;
  transition: all .3s;
  pointer-events: none;
  z-index: 999;
}

#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-left: 3px solid var(--green); }
#toast.error { border-left: 3px solid var(--red); }

/* ── API Key Display ──────────────────────────────────────────────────── */
.api-key-display {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--green);
  word-break: break-all;
  margin-top: 8px;
}

/* ── Explorer Function List ───────────────────────────────────────────── */
.fn-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}

.fn-item:hover { background: var(--surface2); }
.fn-item:last-child { border-bottom: none; }

.fn-name {
  font-family: var(--mono);
  font-size: .85rem;
  font-weight: 600;
  color: var(--accent2);
}

.fn-type {
  font-size: .72rem;
  color: var(--muted);
  margin-left: 8px;
}

.fn-call-form {
  padding: 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
}

.fn-call-form .field { margin-bottom: 10px; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .cards-grid { grid-template-columns: 1fr; }
}


/* ── Compile Grid ─────────────────────────────────────────────────────── */
.compile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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