/* ═══════════════════════════════════════════════════════════════
   theme.css — the ONE place for colors, fonts and shared components.
   Every page (shell + module iframes) links this file. Change a colour
   here and it updates everywhere.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #22263a;
  --border:   #2e3352;
  --accent:   #3b82f6;
  --accent2:  #22c55e;
  --warn:     #f59e0b;
  --danger:   #ef4444;
  --text:     #e2e8f0;
  --text2:    #94a3b8;
  --wire:     #5b6580;
  --radius:   8px;

  --sidebar:  240px;
  --projlist: 268px;
  --topbar:   52px;

  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button { font-family: inherit; cursor: pointer; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 13px; }
b { font-weight: 700; }
a { color: var(--accent); text-decoration: none; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 13px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-accent { background: var(--accent2); border-color: var(--accent2); color: #06250f; }
.btn-accent:hover { filter: brightness(1.06); }
.btn-danger { color: #fca5a5; border-color: rgba(239,68,68,.4); }
.btn-danger:hover { background: rgba(239,68,68,.12); border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-icon { padding: 6px 9px; }

/* ── Form fields ─────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 11px; color: var(--text2); font-weight: 600; }
.inp {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 8px 11px; font-size: 13px; width: 100%;
}
.inp:focus { outline: none; border-color: var(--accent); }
textarea.inp { resize: vertical; min-height: 60px; }

/* ── Cards / tables ──────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text2); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
tbody tr:hover { background: var(--surface2); }

.chip {
  font-size: 12px; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text2); user-select: none;
}
.chip.active { background: rgba(59,130,246,.16); color: #93c5fd; border-color: rgba(59,130,246,.4); }

.muted { color: var(--text2); font-size: 12.5px; }
.hr { height: 1px; background: var(--border); margin: 18px 0; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-wrap {
  position: fixed; bottom: 18px; right: 18px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 11px 15px; border-radius: 9px; font-size: 13px; min-width: 200px; max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: toastIn .2s ease;
}
.toast.ok   { border-left-color: var(--accent2); }
.toast.err  { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 500;
  display: none; align-items: center; justify-content: center; padding: 30px;
}
.modal-overlay.open { display: flex; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: min(560px, 100%); max-height: 90vh; overflow: auto;
}
.modal-head {
  display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; flex: 1; }
.modal-x { background: transparent; border: none; color: var(--text2); font-size: 18px; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ── Loading / error (module pages) ──────────────────────── */
#app-loading, #app-error {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 2000; flex-direction: column; gap: 16px;
}
#app-error { display: none; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text2); }
.error-box {
  background: var(--surface); border: 1px solid var(--danger); border-radius: var(--radius);
  padding: 24px 32px; text-align: center; max-width: 440px;
}
.error-box h3 { color: var(--danger); margin-bottom: 8px; }
.error-box p { color: var(--text2); font-size: 12px; }
