:root {
  --bg: #0a0a0f;
  --bg-surface: #12131a;
  --bg-card: #1a1b26;
  --bg-hover: #1f2133;
  --border: #2a2b3d;
  --border-focus: #7aa2f7;
  --text: #c0caf5;
  --text-dim: #565f89;
  --text-bright: #e0e4ff;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --success: #9ece6a;
  --warning: #e0af68;
  --danger: #f7768e;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Nav */
.nav {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-dim);
}

/* Auth forms */
.auth-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 60px);
  padding: 20px;
}

.auth-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.auth-box h2 {
  font-size: 22px;
  color: var(--text-bright);
  margin-bottom: 24px;
  text-align: center;
}

/* Forms */
input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

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

input::placeholder { color: var(--text-dim); }

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 500;
}

/* Buttons */
button {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}

button:hover { background: var(--bg-hover); border-color: var(--border-focus); }

button.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover { background: var(--accent-hover); }

button.danger { color: var(--danger); border-color: var(--danger); }
button.danger:hover { background: rgba(247, 118, 142, 0.1); }

button.sm { font-size: 12px; padding: 6px 12px; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-full { width: 100%; }

/* Dashboard */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 0 20px;
}

.page-header h1 {
  font-size: 24px;
  color: var(--text-bright);
  font-weight: 700;
}

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s;
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
}

.card-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  font-family: var(--font-mono);
}

.card-body { margin-bottom: 16px; }

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Status badges */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-running { background: rgba(158, 206, 106, 0.15); color: var(--success); }
.badge-stopped { background: rgba(247, 118, 142, 0.15); color: var(--danger); }
.badge-provisioning { background: rgba(224, 175, 104, 0.15); color: var(--warning); }
.badge-deleted { background: rgba(86, 95, 137, 0.15); color: var(--text-dim); }

/* Deploy modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 20px 0;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 18px;
  color: var(--text-bright);
  margin-bottom: 20px;
}

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

/* App catalog */
.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.app-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.app-card.selected {
  border-color: var(--accent);
  background: rgba(122, 162, 247, 0.05);
}

.app-card h4 {
  font-size: 15px;
  color: var(--text-bright);
  margin-bottom: 4px;
}

.app-card p {
  font-size: 13px;
  color: var(--text-dim);
}

/* Terminal */
.terminal-container {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  height: 500px;
}

/* Info rows */
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}

.info-row .label { color: var(--text-dim); }
.info-row .value { color: var(--text); font-family: var(--font-mono); font-size: 12px; }

/* Toast */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  max-width: 400px;
  font-size: 13px;
  animation: slide-in 0.2s ease;
}

.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state h3 {
  font-size: 18px;
  color: var(--text);
  margin-bottom: 8px;
}

/* Auth toggle */
.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-dim);
}

.auth-toggle a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.auth-toggle a:hover { text-decoration: underline; }

/* Utility */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 12px; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Terminal Panel */
#terminal-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  background: #0f1117; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; height: 50vh;
  transition: height 0.15s ease;
}
#terminal-panel.minimized { height: 36px; }
#terminal-panel.minimized .terminal-panel-body,
#terminal-panel.minimized .terminal-keybar,
#terminal-panel.minimized #terminal-dict-preview { display: none !important; }

.terminal-panel-header {
  display: flex; align-items: center;
  background: #12131a; border-bottom: 1px solid var(--border);
  height: 36px; flex-shrink: 0; padding: 0 4px;
}
.terminal-tabs {
  display: flex; flex: 1; overflow-x: auto; gap: 0;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.terminal-tabs::-webkit-scrollbar { display: none; }

.terminal-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px; height: 36px; font-size: 12px;
  color: var(--text-dim); background: transparent; border: none;
  border-bottom: 2px solid transparent; cursor: pointer;
  white-space: nowrap; font-family: var(--font);
}
.terminal-tab.active {
  color: var(--text-bright); border-bottom-color: var(--accent);
  background: rgba(122, 162, 247, 0.05);
}
.terminal-tab .tab-close {
  display: inline-flex; width: 16px; height: 16px;
  align-items: center; justify-content: center;
  border-radius: 3px; font-size: 11px; opacity: 0;
  transition: opacity 0.1s; border: none; background: none;
  color: inherit; cursor: pointer;
}
.terminal-tab:hover .tab-close, .terminal-tab.active .tab-close { opacity: 0.6; }
.terminal-tab .tab-close:hover { opacity: 1; background: rgba(247, 118, 142, 0.2); color: var(--danger); }

.terminal-panel-controls { display: flex; gap: 2px; padding: 0 4px; }
.terminal-panel-btn {
  background: transparent; border: none; color: var(--text-dim);
  padding: 4px 8px; font-size: 14px; cursor: pointer; border-radius: 3px;
}
.terminal-panel-btn:hover { background: var(--bg-hover); color: var(--text); }

.terminal-panel-body {
  flex: 1; overflow: hidden; position: relative;
}
.terminal-pane {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: none;
}
.terminal-pane.active { display: block; }

.term-char-menu {
  position: absolute; top: 36px; right: 40px; z-index: 160;
  background: #1a1b26; border: 1px solid #3b4261; border-radius: 6px;
  padding: 4px; display: none; gap: 4px;
}
.term-char-menu.open { display: flex; }
.term-char-menu button {
  background: #24283b; color: #a9b1d6; border: 1px solid #3b4261;
  border-radius: 4px; padding: 8px 12px; font-size: 15px;
  font-family: 'JetBrains Mono', monospace; cursor: pointer;
  touch-action: manipulation;
}
.term-char-menu button:active { background: #414868; }

.terminal-keybar {
  background: #1a1b26; border-top: 1px solid #2f3345;
  display: flex; flex-wrap: wrap; gap: 2px; padding: 4px;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.terminal-keybar button {
  background: #24283b; color: #a9b1d6; border: 1px solid #3b4261;
  border-radius: 4px; padding: 8px 10px; font-size: 13px;
  font-family: 'JetBrains Mono', monospace; cursor: pointer;
  min-width: 38px; text-align: center; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.terminal-keybar button:active { background: #414868; }
.terminal-keybar button.mod-active { background: #7aa2f7; color: #1a1b26; border-color: #7aa2f7; }
.terminal-keybar .spacer { flex-grow: 1; }

@media (min-width: 800px) and (hover: hover) {
  .terminal-keybar { display: none !important; }
}
@media (max-width: 799px), (hover: none) {
  #terminal-panel:not(.minimized) { height: calc(100% - 48px); top: 48px; }
  body.terminal-open #page-dashboard,
  body.terminal-open #page-detail,
  body.terminal-open #page-billing,
  body.terminal-open #page-admin { display: none !important; }
}
