:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --fg: #c9d1d9;
  --fg2: #8b949e;
  --accent: #58a6ff;
  --accent2: #1f6feb;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --border: #30363d;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

/* ---- Login ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0d1117 0%, #161b22 100%);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 { margin-bottom: 0.5rem; font-size: 1.5rem; }
.login-card .muted { color: var(--fg2); margin-bottom: 1.5rem; font-size: 0.875rem; }

.login-card label {
  display: block;
  text-align: left;
  margin-bottom: 0.25rem;
  font-weight: 600;
  font-size: 0.875rem;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: rgba(248,81,73,0.15);
  color: var(--red);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.5rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.15s;
  text-decoration: none;
  color: var(--fg);
  background: var(--bg3);
}

.btn:hover { filter: brightness(1.15); }
.btn-primary { background: var(--accent2); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.75rem; }
.btn-outline { border-color: var(--border); background: transparent; }

/* ---- Dashboard Layout ---- */
.dashboard {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 { font-size: 1rem; }

.sidebar nav { padding: 0.5rem; flex: 1; }

.nav-cat {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--fg2);
  padding: 0.75rem 0.5rem 0.25rem;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.nav-item {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--fg);
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item:hover { background: var(--bg3); }
.nav-item.active { background: var(--accent2); color: #fff; }

.nav-special {
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
}

/* ---- Main ---- */
.main {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  min-width: 0;
}

.panel { max-width: 960px; }

.welcome-panel { padding-top: 3rem; }
.welcome-panel h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.welcome-panel p { color: var(--fg2); }

/* ---- Tool Panel ---- */
.tool-header { margin-bottom: 1rem; }
.tool-header h2 { font-size: 1.25rem; }
.tool-header .muted { color: var(--fg2); font-size: 0.85rem; margin-top: 0.2rem; }

#tool-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
  color: var(--fg2);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.form-group textarea { resize: vertical; min-height: 60px; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88,166,255,0.15);
}

.tool-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* ---- Terminal ---- */
.terminal {
  background: #000;
  color: #33ff33;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.5;
  padding: 1rem;
  border-radius: var(--radius);
  min-height: 120px;
  max-height: 65vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid var(--border);
}

.terminal .cmd-line { color: var(--accent); font-weight: 700; }
.terminal .err-line { color: var(--red); }

/* ---- Web Terminal (xterm.js) ---- */
.panel-full {
  max-width: none;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 3rem);
}

.panel-full .tool-header { flex-shrink: 0; }

#xterm-container {
  flex: 1;
  min-height: 200px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
}

#xterm-container .xterm { height: 100%; }
#xterm-container .xterm-viewport { overflow-y: auto !important; }

.nav-item-term { font-weight: 700; }

/* ---- History ---- */
#history-list { margin-top: 1rem; }

.hist-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.hist-tool { font-weight: 700; min-width: 80px; }
.hist-cmd { flex: 1; color: var(--fg2); font-family: var(--mono); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-status { min-width: 50px; text-align: center; }
.hist-status.ok { color: var(--green); }
.hist-status.err { color: var(--red); }
.hist-status.run { color: var(--yellow); }
.hist-time { color: var(--fg2); font-size: 0.7rem; min-width: 110px; text-align: right; }

/* ---- Wizard ---- */
.wiz-form { max-width: 500px; }

.wiz-tor-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin: 0.75rem 0;
  flex-wrap: wrap;
}

.wiz-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.wiz-toggle input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent2);
}

.wiz-tor-interval { flex: 1; min-width: 160px; }

.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }

.wiz-stepper {
  display: flex;
  gap: 0.25rem;
  margin: 1rem 0;
}

.wiz-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.6rem 0.3rem;
  border-radius: var(--radius);
  background: var(--bg2);
  border: 1px solid var(--border);
  transition: all 0.3s;
}

.wiz-step .step-num {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
  transition: all 0.3s;
}

.wiz-step .step-label {
  font-size: 0.7rem;
  color: var(--fg2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.wiz-step.active {
  border-color: var(--accent);
  background: rgba(88,166,255,0.08);
}

.wiz-step.active .step-num {
  background: var(--accent2);
  color: #fff;
}

.wiz-step.done {
  border-color: var(--green);
  background: rgba(63,185,80,0.08);
}

.wiz-step.done .step-num {
  background: var(--green);
  color: #fff;
}

.wiz-step.done .step-num::after { content: "\2713"; }
.wiz-step.done .step-num { font-size: 0; }
.wiz-step.done .step-num::after { font-size: 1rem; }

.wiz-tool-status {
  font-size: 0.85rem;
  color: var(--accent);
  padding: 0.4rem 0;
  min-height: 1.5rem;
  font-family: var(--mono);
}

#wiz-terminal {
  max-height: 55vh;
}

.wiz-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.wiz-stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.wiz-stat .stat-num {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.wiz-stat .stat-label {
  font-size: 0.75rem;
  color: var(--fg2);
  text-transform: uppercase;
  margin-top: 0.2rem;
}

.wiz-downloads {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.btn-download {
  background: var(--accent2);
  color: #fff;
  padding: 0.7rem 1.5rem;
  text-decoration: none;
}

.btn-download:hover { filter: brightness(1.15); }

.nav-item-wizard {
  font-weight: 700;
  color: var(--green) !important;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .dashboard { flex-direction: column; }
  .sidebar { width: 100%; min-width: 100%; max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
  .main { padding: 1rem; }
}
