:root {
  --bg: #0b0f17;
  --surface: #131926;
  --surface-2: #1a2234;
  --border: #263147;
  --text: #e6edf7;
  --text-muted: #8b9bb4;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "PingFang SC", "Helvetica Neue", sans-serif;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  background: var(--bg);
}

/* Top Header */
.top-bar {
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 6px 12px;
}

.brand-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.status-dot.connected {
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
}
.status-dot.connecting {
  background: var(--amber);
  animation: pulse 1.2s infinite;
}
.status-dot.disconnected {
  background: var(--rose);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.brand-name {
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-muted {
  background: rgba(139, 155, 180, 0.16);
  color: var(--text-muted);
}
.pill-ok {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
}
.pill-warn {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}
.pill-err {
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.icon-btn:active {
  background: #27324b;
}
.icon-btn.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.22);
  color: #c7d2fe;
}

/* Session Tabs */
.tabs-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 7px 10px;
}

.tabs-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1 1 auto;
}
.tabs-scroll::-webkit-scrollbar {
  display: none;
}

.session-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 190px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.session-tab.active {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(129, 140, 248, 0.55);
  color: var(--text);
  font-weight: 600;
}
.session-tab .tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--emerald);
  flex: 0 0 auto;
}
.session-tab.prod .tab-dot {
  background: var(--rose);
}
.session-tab.exited .tab-dot {
  background: #64748b;
}
.session-tab .tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-add-btn {
  flex: 0 0 auto;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  width: 30px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
}
.tab-add-btn:active {
  background: var(--surface-2);
}

/* Banners */
.banner-stack {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 10px;
}
.banner-item {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.banner-warn {
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fde68a;
}
.banner-err {
  background: rgba(244, 63, 94, 0.18);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #fecdd3;
}
.banner-info {
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.45);
  color: #e0e7ff;
}
.banner-close {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
}

/* Main Terminal Viewport */
.terminal-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #0b0f17;
  padding: 6px 8px;
}

.terminal-host {
  width: 100%;
  height: 100%;
}

.terminal-wrap.desktop-size-mode .terminal-host {
  width: max-content;
  min-width: 100%;
  height: max-content;
  min-height: 100%;
}

.empty-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 23, 0.92);
  padding: 20px;
  z-index: 10;
}
.empty-card {
  max-width: 340px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 18px;
}
.empty-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}
.empty-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}
.primary-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
}
.primary-btn:active {
  background: var(--accent-hover);
}

/* Mobile Control Dock */
.control-dock {
  flex: 0 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 7px 8px calc(7px + var(--safe-bottom)) 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.cmd-bar {
  display: flex;
  align-items: center;
  gap: 5px;
}

.mini-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mini-btn:active {
  background: #27324b;
  color: var(--text);
}

.cmd-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0d121d;
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  outline: none;
}
.cmd-input:focus {
  border-color: var(--accent);
}
.cmd-input:disabled {
  opacity: 0.5;
}

.send-btn {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.send-btn:active {
  background: var(--accent-hover);
}
.send-btn:disabled {
  opacity: 0.45;
}

.key-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 1px;
}
.key-strip::-webkit-scrollbar {
  display: none;
}

.key-btn {
  flex: 0 0 auto;
  min-width: 38px;
  height: 32px;
  padding: 0 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.key-btn:active {
  background: #2b3854;
}
.key-btn.key-danger {
  border-color: rgba(244, 63, 94, 0.45);
  color: #fda4af;
}
.key-btn.key-mod.active {
  background: var(--accent);
  border-color: var(--accent-hover);
  color: #fff;
}

/* Snippets Drawer */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet-panel {
  width: 100%;
  max-width: 560px;
  max-height: 75dvh;
  background: var(--surface);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  border-top: 1px solid var(--border);
  padding: 14px 14px calc(14px + var(--safe-bottom)) 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-title {
  font-size: 15px;
  font-weight: 700;
}
.sheet-search {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0d121d;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}
.snippets-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.snippet-card {
  text-align: left;
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.snippet-card:active {
  border-color: var(--accent);
}
.snippet-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
}
.snippet-cmd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
