/* ---------- Tokens ---------- */
:root {
  --bg: #0b0e12;
  --panel: #12161c;
  --panel-2: #171c24;
  --border: #232a35;
  --text: #d7dde3;
  --text-dim: #7c8794;
  --accent: #4fd1a5;      /* terminal mint — running / success */
  --accent-2: #38bdf8;    /* secondary accent for gradients/links */
  --accent-dim: #2a5c4c;
  --amber: #f0a84e;       /* installing / warning */
  --red: #e5697a;         /* stopped / error / danger */
  --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.25);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 10% -10%, rgba(79,209,165,0.06), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(56,189,248,0.05), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

button, input, select, textarea { font-family: inherit; }

/* ---------- Brand ---------- */
.brand-glyph {
  font-family: var(--mono);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
  animation: blink-cursor 1.4s steps(1) infinite;
}
.brand-glyph.big { font-size: 48px; display: block; margin-bottom: 12px; }
@keyframes blink-cursor { 50% { opacity: 0.35; } }

/* ---------- Layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }

.mobile-topbar { display: none; }
.icon-btn {
  background: none; border: none; color: var(--text); font-size: 20px;
  cursor: pointer; padding: 4px 8px; line-height: 1;
}
.sidebar-close { display: none; margin-left: auto; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(3,4,6,0.6); z-index: 39;
}

.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 17px; font-weight: 700;
  padding: 4px 4px 10px 4px;
}
.logout-btn { margin-top: auto; }
.user-badge {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 6px; border-top: 1px solid var(--border); margin-top: 6px;
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-dim);
  color: var(--accent); display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name {
  font-size: 12.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-credit {
  font-size: 11px; color: var(--text-dim); text-align: center; padding-top: 4px;
}
.sidebar-credit a { color: var(--accent); text-decoration: none; }
.sidebar-credit a:hover { text-decoration: underline; }

.project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.project-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  color: var(--text-dim); font-size: 13.5px;
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.project-item:hover { background: var(--panel-2); color: var(--text); }
.project-item.active { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.project-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.project-item .dot.running { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.project-item .dot.installing { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.project-item .dot.error { background: var(--red); }
.project-item span.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim); text-align: center; gap: 4px;
}

.hidden { display: none !important; }

/* ---------- Project view ---------- */
.project-view { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.project-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  gap: 12px; flex-wrap: wrap;
}
.project-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.project-title h1 { font-family: var(--mono); font-size: 18px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; }
.status-dot.running { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-dot.installing { background: var(--amber); box-shadow: 0 0 8px var(--amber); animation: pulse 1s infinite; }
.status-dot.error { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.4; } }

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

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: border-color .15s, background .15s, transform .12s, box-shadow .15s;
}
.btn:hover { border-color: #3a4452; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #38c99a);
  border-color: var(--accent); color: #06231a; font-weight: 600;
  box-shadow: 0 2px 10px rgba(79,209,165,0.18);
}
.btn-primary:hover { background: linear-gradient(135deg, #63dcb2, var(--accent)); box-shadow: 0 4px 16px rgba(79,209,165,0.28); }
.btn-secondary { background: var(--panel-2); }
.btn-ghost { background: transparent; }
.btn-danger-ghost { background: transparent; border-color: var(--border); color: var(--red); }
.btn-danger-ghost:hover { border-color: var(--red); background: rgba(229,105,122,0.08); }
.btn-danger { background: var(--red); border-color: var(--red); color: #2a0509; font-weight: 600; }
.btn-danger:hover { background: #ef8391; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

select#entry-file-select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 10px; border-radius: 8px; font-family: var(--mono); font-size: 12.5px;
}

.search-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 8px; font-size: 12.5px;
}
.search-input::placeholder { color: var(--text-dim); }
.files-search { width: 220px; margin-left: auto; }

/* ---------- On/Off switch ---------- */
.switch {
  display: flex; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer; padding: 4px 2px;
}
.switch-track {
  width: 42px; height: 24px; border-radius: 999px; background: #2a313c;
  border: 1px solid var(--border); position: relative; transition: background .18s;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-dim); transition: transform .18s, background .18s;
}
.switch.on .switch-track { background: rgba(79,209,165,0.25); border-color: var(--accent); }
.switch.on .switch-thumb { transform: translateX(18px); background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.switch.installing .switch-track { border-color: var(--amber); }
.switch.installing .switch-thumb { background: var(--amber); animation: pulse 0.9s infinite; }
.switch-label { font-family: var(--mono); font-size: 12.5px; color: var(--text-dim); min-width: 34px; text-align: left; }
.switch.on .switch-label { color: var(--accent); }
.switch:disabled, .switch[disabled] { opacity: 0.6; cursor: not-allowed; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; padding: 10px 24px 0; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none; border: none; color: var(--text-dim); padding: 8px 14px;
  cursor: pointer; font-size: 13.5px; border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ---------- Files ---------- */
.files-toolbar { display: flex; gap: 10px; padding: 14px 24px; border-bottom: 1px solid var(--border); }
.files-layout { flex: 1; display: flex; overflow: hidden; }
.file-list {
  width: 240px; min-width: 240px; overflow-y: auto; list-style: none; margin: 0; padding: 10px;
  border-right: 1px solid var(--border);
}
.file-list li {
  padding: 7px 10px; border-radius: 6px; cursor: pointer; color: var(--text-dim);
  font-family: var(--mono); font-size: 12.5px; display: flex; justify-content: space-between; align-items: center;
  gap: 6px;
}
.file-list li:hover { background: var(--panel-2); color: var(--text); }
.file-list li.active { background: var(--panel-2); color: var(--accent); }
.file-list li .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li .file-actions { display: flex; align-items: center; gap: 8px; opacity: 0; flex-shrink: 0; }
.file-list li:hover .file-actions { opacity: 1; }
.file-list li .del-file, .file-list li .dl-file { color: var(--text-dim); font-size: 12px; cursor: pointer; }
.file-list li .del-file:hover { color: var(--red); }
.file-list li .dl-file:hover { color: var(--accent); }
.file-list li.no-match { display: none; }

.editor-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.editor-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 12.5px; color: var(--text-dim);
}
.editor-header #editor-filename { flex-shrink: 0; }
.editor-meta { color: #4b5563; font-size: 11.5px; }
.editor-header-actions { display: flex; gap: 8px; margin-left: auto; }
#editor {
  flex: 1; resize: none; border: none; outline: none;
  background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  padding: 16px 20px; tab-size: 4;
}

/* ---------- Logs ---------- */
.logs-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 24px; border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em;
}
.logs-toolbar-actions { display: flex; align-items: center; gap: 10px; text-transform: none; }
.autoscroll-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.autoscroll-toggle input { accent-color: var(--accent); }
.log-output {
  flex: 1; margin: 0; padding: 18px 24px; overflow-y: auto;
  background: #08090c; color: #c9f7e4;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65; white-space: pre-wrap;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(5,7,10,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px; width: 380px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal-card h2 { margin: 0 0 16px; font-size: 16px; }
.modal-card label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.modal-card input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 10px; border-radius: 8px; font-family: var(--mono); font-size: 13px;
}
.hint { font-size: 11.5px; color: var(--text-dim); margin: 8px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  width: 340px; max-width: 90vw; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 30px;
  box-shadow: var(--shadow-md);
}
.login-brand { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 20px; font-weight: 700; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 6px 0 22px; }
.login-card label { display: block; font-size: 12px; color: var(--text-dim); margin: 12px 0 6px; }
.login-card input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px; border-radius: 8px; font-size: 13px;
}
.login-card button {
  width: 100%; margin-top: 20px; padding: 10px; border-radius: 8px; border: none;
  background: linear-gradient(135deg, var(--accent), #38c99a);
  color: #06231a; font-weight: 600; cursor: pointer;
  box-shadow: 0 2px 10px rgba(79,209,165,0.18);
  transition: box-shadow .15s, transform .12s;
}
.login-card button:hover { box-shadow: 0 4px 16px rgba(79,209,165,0.28); transform: translateY(-1px); }
.login-card button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.error-text { color: var(--red); font-size: 12.5px; margin-top: 10px; min-height: 14px; }

.auth-switch { text-align: center; font-size: 12.5px; color: var(--text-dim); margin: 16px 0 0; }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-switch a:hover { text-decoration: underline; }

.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; min-width: 0; }
.login-credit {
  text-align: center; margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-dim);
}
.login-credit a { color: var(--accent); text-decoration: none; }
.login-credit a:hover { text-decoration: underline; }

/* ---------- Welcome modal ---------- */
.welcome-card { text-align: center; }
.welcome-card .brand-glyph.big { margin-bottom: 8px; }
.welcome-card h2 { margin: 4px 0 10px; }
.welcome-text { margin: 0 0 14px; }
.welcome-credit {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-size: 12.5px; line-height: 1.6;
}
.welcome-credit a { color: var(--accent); text-decoration: none; font-weight: 600; }
.welcome-credit a:hover { text-decoration: underline; }
.welcome-actions { margin-top: 18px; }

.confirm-message { margin: 0 0 4px; }

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
.toast {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 11px 16px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  display: flex; align-items: center; gap: 8px;
  animation: toast-in .2s ease-out;
  max-width: 340px;
}
.toast.success { border-color: var(--accent-dim); }
.toast.success::before { content: "✓"; color: var(--accent); font-weight: 700; }
.toast.error { border-color: #6e2530; }
.toast.error::before { content: "✕"; color: var(--red); font-weight: 700; }
.toast.info::before { content: "ℹ"; color: var(--text-dim); }
.toast.fade-out { animation: toast-out .2s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* subtle fade for main content when switching projects, keeps UI feeling responsive */
.project-view { animation: view-fade .12s ease-out; }
@keyframes view-fade { from { opacity: 0.4; } to { opacity: 1; } }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2a3038; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* =========================================================
   Responsive — tablet & mobile
   ========================================================= */
@media (max-width: 860px) {
  .files-search { width: 100%; margin-left: 0; }
  .files-toolbar { flex-wrap: wrap; }
}

@media (max-width: 768px) {
  .mobile-topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
    font-family: var(--mono); font-weight: 700; font-size: 15px;
  }
  .mobile-topbar .icon-btn { font-size: 22px; padding: 2px 6px; }

  .app { flex-direction: column; height: 100dvh; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    width: 82vw; max-width: 300px; min-width: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 2px 0 24px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-block; }
  .sidebar-backdrop.visible { display: block; }

  .main { flex: 1; min-height: 0; }

  .empty-state { padding: 24px; text-align: center; }

  .project-header { padding: 12px 14px; }
  .project-title h1 { font-size: 15.5px; }
  .project-actions { width: 100%; }
  #entry-file-select { flex: 1; min-width: 0; }

  .tabs { padding: 8px 14px 0; overflow-x: auto; }
  .tab-btn { padding: 8px 12px; font-size: 13px; white-space: nowrap; }

  .files-toolbar { padding: 10px 14px; }
  .files-layout { flex-direction: column; overflow-y: auto; }
  .file-list {
    width: 100%; min-width: 0; max-height: 38vh;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .file-list li .file-actions { opacity: 1; } /* no hover on touch */
  .editor-wrap { min-height: 40vh; }
  #editor { font-size: 14px; padding: 14px; }
  .editor-header { flex-wrap: wrap; row-gap: 8px; }
  .editor-meta { order: 3; width: 100%; }

  .logs-toolbar { flex-direction: column; align-items: flex-start; gap: 8px; padding: 10px 14px; }
  .logs-toolbar-actions { flex-wrap: wrap; }
  .log-output { padding: 14px; font-size: 12px; }

  .modal-card { padding: 18px; }

  .toast-container { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }
}

@media (max-width: 420px) {
  .project-actions { gap: 6px; }
  .btn { padding: 7px 10px; font-size: 12.5px; }
  .switch-label { display: none; }
}
