:root {
  --bg: #e8f4fc;
  --surface: #ffffff;
  --surface-2: #dbeaf8;
  --border: rgba(14, 165, 233, 0.12);
  --text: #0c4a6e;
  --text-2: #64748b;
  --accent: #0ea5e9;
  --accent-soft: #38bdf8;
  --accent-dark: #0284c7;
  --green: #10b981;
  --red: #f43f5e;
  --orange: #f59e0b;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 2px 14px rgba(14, 165, 233, 0.08);
  --shadow-md: 0 8px 28px rgba(14, 165, 233, 0.12);
  --glass: rgba(255, 255, 255, 0.78);
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-num: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', Consolas, monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, #bae6fd 0%, transparent 55%),
    radial-gradient(ellipse 80% 50% at 100% 100%, #e0f2fe 0%, transparent 45%);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100%;
  min-height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 34px;
  height: 34px;
  background: linear-gradient(145deg, #38bdf8, #0ea5e9);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35);
  flex-shrink: 0;
}

.brand h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #0369a1;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--surface);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.icon-btn:active { opacity: 0.75; }

/* Main */
.main { padding: 16px 14px 110px; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 0 2px;
}

.section-title h2 {
  font-size: 12px;
  font-weight: 600;
  color: #0369a1;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.count {
  background: rgba(14, 165, 233, 0.15);
  color: #0369a1;
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 20px;
}

.projects-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.project-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer;
}
.project-card:active { opacity: 0.9; }

.project-card .card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}

.project-card .name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: #0c4a6e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-card .status {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.status.running {
  background: rgba(16, 185, 129, 0.14);
  color: #047857;
}

.status.stopped {
  background: rgba(100, 116, 139, 0.12);
  color: #64748b;
}

.card-stats { display: flex; gap: 16px; }
.card-stat { display: flex; flex-direction: column; gap: 2px; }
.card-stat span:first-child { font-size: 11px; color: var(--text-2); }
.card-stat span:last-child { font-size: 14px; color: #0c4a6e; }

.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  text-align: center;
}
.empty-state.show { display: flex; }
.empty-icon { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 16px; margin-bottom: 4px; color: #0c4a6e; }
.empty-state span { font-size: 13px; color: var(--text-2); }

/* FAB */
.fab {
  position: fixed;
  bottom: 24px;
  right: max(16px, calc(50% - 204px));
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: linear-gradient(145deg, #38bdf8, #0ea5e9);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 22px rgba(14, 165, 233, 0.4);
  cursor: pointer;
  z-index: 40;
}
.fab:active { opacity: 0.85; }
.fab.open { transform: rotate(45deg); }

/* Modal — simple, no lag */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 74, 110, 0.25);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
}
.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 440px;
  border-radius: 20px 20px 0 0;
  padding: 10px 20px 32px;
  transform: translateY(100%);
  transition: transform 0.25s ease-out;
}
.modal-overlay.show .modal { transform: translateY(0); }

.modal-handle {
  width: 32px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 4px;
  margin: 0 auto 16px;
}

.modal h3 { font-size: 18px; margin-bottom: 3px; color: #0c4a6e; }
.modal-sub { font-size: 13px; color: var(--text-2); margin-bottom: 16px; }

.modal input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #bae6fd;
  border-radius: 12px;
  font-size: 15px;
  font-family: var(--font);
  background: #f0f9ff;
  outline: none;
  margin-bottom: 16px;
  color: var(--text);
}
.modal input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.modal-actions { display: flex; gap: 10px; }

.btn-primary, .btn-secondary {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(145deg, #38bdf8, #0ea5e9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.3);
}
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-primary:active, .btn-secondary:active { opacity: 0.85; }

/* Sheet — NO heavy animation (fixes hang) */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 74, 110, 0.18);
  z-index: 90;
  display: none;
}
.sheet-overlay.show { display: block; }

.sheet {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 440px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 120% 80% at 50% -20%, #bae6fd 0%, transparent 55%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--text-2);
  flex-shrink: 0;
}

.sheet-header h2 {
  flex: 1;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #0c4a6e;
  min-width: 0;
}

.status-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.status-pill.running { background: rgba(16, 185, 129, 0.14); color: #047857; }
.status-pill.stopped { background: rgba(100, 116, 139, 0.12); color: #64748b; }

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 14px 0;
  flex-shrink: 0;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-value { font-size: 18px; color: #0c4a6e; }

.control-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 14px;
  flex-shrink: 0;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 2px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  color: var(--text);
}
.ctrl-btn:active { opacity: 0.8; }
.ctrl-btn.start { color: #047857; }
.ctrl-btn.stop { color: #e11d48; }
.ctrl-btn.restart { color: #0284c7; }
.ctrl-btn.delete { color: #d97706; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 14px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-2);
  border-radius: 10px;
  cursor: pointer;
}
.tab.active {
  background: var(--surface);
  color: #0369a1;
  box-shadow: var(--shadow);
  border: 1px solid rgba(14, 165, 233, 0.15);
}

.tab-panel {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  height: 0; /* critical: forces flex child to shrink and scroll */
  overflow: hidden;
  flex-direction: column;
  padding: 0 14px 16px;
}
.tab-panel.active { display: flex; }

/* Logs */
.logs-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.mini-btn {
  padding: 7px 12px;
  border: none;
  background: var(--surface);
  border-radius: 9px;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.mini-btn:active { opacity: 0.8; }

.logs-box {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  background: #0c4a6e;
  color: #bae6fd;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid rgba(14, 165, 233, 0.2);
  margin: 0;
}

/* Files */
.files-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
  flex-shrink: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  color: var(--text-2);
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
}
.breadcrumb span {
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
}
.breadcrumb span:active { background: var(--surface-2); color: var(--text); }

.files-actions { display: flex; gap: 5px; flex-shrink: 0; }

.file-list {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
}
.file-item:active { background: #f0f9ff; }

.file-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.file-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}
.file-icon.folder { background: linear-gradient(145deg, #38bdf8, #0ea5e9); color: #fff; }
.file-icon.py { background: linear-gradient(145deg, #60a5fa, #2563eb); }
.file-icon.js { background: linear-gradient(145deg, #fbbf24, #f59e0b); }
.file-icon.html { background: linear-gradient(145deg, #fb923c, #ea580c); }
.file-icon.css { background: linear-gradient(145deg, #22d3ee, #0891b2); }
.file-icon.json { background: linear-gradient(145deg, #a3e635, #65a30d); }
.file-icon.txt,
.file-icon.md,
.file-icon.file { background: linear-gradient(145deg, #94a3b8, #64748b); }
.file-icon.zip { background: linear-gradient(145deg, #c084fc, #9333ea); }
.file-icon.img { background: linear-gradient(145deg, #f472b6, #db2777); }
.file-icon.env { background: linear-gradient(145deg, #34d399, #059669); }
.file-icon.sh,
.file-icon.cfg { background: linear-gradient(145deg, #818cf8, #4f46e5); }
.file-icon.pdf { background: linear-gradient(145deg, #f87171, #dc2626); }
.file-icon.media { background: linear-gradient(145deg, #2dd4bf, #0d9488); }

.file-info { flex: 1; min-width: 0; }
.file-info .fname {
  font-size: 14px;
  color: #0c4a6e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-info .fmeta { font-size: 11px; color: var(--text-2); margin-top: 1px; }

.file-delete {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: #fb7185;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.6;
  flex-shrink: 0;
}
.file-delete:active { opacity: 1; background: rgba(244, 63, 94, 0.1); }

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #0c4a6e;
  color: #e0f2fe;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  max-width: 85%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(12, 74, 110, 0.25);
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }


.logs-box {
  font-family: var(--font-mono) !important;
  font-weight: 400;
  letter-spacing: 0;
}

.count,
.card-stat span:last-child,
.stat-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}


/* Startup file box */
.startup-box {
  margin: 0 14px 12px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.startup-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #0369a1;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}
.startup-label svg { color: #0ea5e9; flex-shrink: 0; }
.startup-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.startup-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1.5px solid #bae6fd;
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font-mono);
  font-weight: 500;
  background: #f0f9ff;
  color: #0c4a6e;
  outline: none;
}
.startup-row input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.12);
}
.startup-save {
  flex-shrink: 0;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(145deg, #38bdf8, #0ea5e9);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(14, 165, 233, 0.28);
}
.startup-save:active { opacity: 0.85; }
