:root {
  --bg: #0c0c0c;
  --surface: #181818;
  --surface-raised: #242424;
  --surface-hover: #2d2d2d;
  --border: #343434;
  --text: #f2f2f2;
  --muted: #a5a5a5;
  --subtle: #737373;
  --accent: #4cc2ff;
  --alert: #f5b942;
  --danger: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button { font: inherit; }

.app-shell {
  display: grid;
  grid-template-rows: calc(44px + var(--safe-top)) minmax(0, 1fr);
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 15% -20%, rgba(76, 194, 255, .1), transparent 34%),
    var(--bg);
}

.titlebar {
  z-index: 20;
  display: flex;
  align-items: end;
  min-width: 0;
  height: calc(44px + var(--safe-top));
  padding-top: var(--safe-top);
  background: #202020;
  border-bottom: 1px solid #050505;
  user-select: none;
}

.brand {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 9px;
  flex: 0 0 auto;
  padding: 0 15px;
  color: #dcdcdc;
}

.brand-mark {
  color: var(--accent);
  font: 700 14px/1 "Cascadia Code", "JetBrains Mono", monospace;
}

.brand-name { font-size: 13px; font-weight: 600; letter-spacing: .02em; }

.tab-strip {
  display: flex;
  align-items: stretch;
  align-self: stretch;
  min-width: 0;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.tab-strip::-webkit-scrollbar { display: none; }

.terminal-tab {
  --tab-color: #3a3a3a;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 154px;
  max-width: 240px;
  padding: 0 9px 0 12px;
  border: 0;
  border-right: 1px solid #111;
  border-top: 2px solid transparent;
  background: #272727;
  color: #cfcfcf;
  cursor: default;
}

.terminal-tab::before {
  content: "";
  position: absolute;
  inset: auto 8px 0;
  height: 2px;
  background: var(--tab-color);
  opacity: .8;
}

.terminal-tab:hover { background: #303030; }

.terminal-tab.active {
  background: var(--bg);
  color: #fff;
  border-top-color: var(--tab-color);
}

.terminal-tab.active::before { display: none; }

.tab-status {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #686868;
}

.tab-status.running { background: #6ccb5f; box-shadow: 0 0 0 3px rgba(108, 203, 95, .12); }
.tab-status.alert { background: var(--alert); animation: alert-pulse 1.5s infinite; }
.tab-status.connected { background: var(--accent); }
.tab-status.offline { background: var(--danger); }

@keyframes alert-pulse {
  50% { box-shadow: 0 0 0 5px rgba(245, 185, 66, 0); }
}

.tab-copy {
  min-width: 0;
  flex: 1;
  text-align: left;
}

.tab-title, .tab-subtitle {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tab-title { font-size: 12px; font-weight: 600; }
.tab-subtitle { margin-top: 1px; color: var(--muted); font-size: 10px; }

.tab-close {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: #aaa;
  line-height: 20px;
}

.tab-close:hover { background: #4a4a4a; color: #fff; }

.titlebar-actions {
  display: flex;
  align-items: center;
  align-self: stretch;
  flex: 0 0 auto;
}

.icon-button, .add-button {
  display: grid;
  place-items: center;
  align-self: stretch;
  min-width: 42px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #d8d8d8;
  cursor: pointer;
}

.icon-button:hover, .add-button:hover { background: #373737; color: white; }
.add-button { font-size: 22px; font-weight: 300; }

.terminal-stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }

.terminal-panel {
  position: absolute;
  inset: 0;
  display: none;
  padding: 8px 6px 5px 10px;
  background: rgba(12, 12, 12, .98);
}

.terminal-panel.active { display: block; }
.terminal-host { width: 100%; height: 100%; }
.xterm { height: 100%; }
.xterm .xterm-viewport { scrollbar-color: #454545 transparent; scrollbar-width: thin; }

.empty-state, .access-state {
  display: grid;
  place-content: center;
  justify-items: center;
  width: 100%;
  height: 100%;
  padding: 28px;
  text-align: center;
}

.empty-state[hidden] { display: none; }
.empty-mark { color: var(--accent); font: 700 32px/1 "Cascadia Code", monospace; }
.empty-state h1, .access-card h1 { margin: 18px 0 8px; font-size: 20px; }
.empty-state p, .access-card p { max-width: 390px; margin: 0 0 22px; color: var(--muted); font-size: 14px; line-height: 1.5; }

.primary-button {
  min-height: 38px;
  padding: 0 18px;
  border: 1px solid #62caff;
  border-radius: 4px;
  background: #1784b8;
  color: white;
  font-weight: 600;
}

.session-drawer {
  position: fixed;
  z-index: 60;
  inset: 0 0 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(390px, 92vw);
  padding-top: var(--safe-top);
  border-left: 1px solid var(--border);
  background: #181818;
  box-shadow: -18px 0 48px rgba(0, 0, 0, .5);
  transform: translateX(104%);
  transition: transform 170ms ease-out;
}

.session-drawer.open { transform: translateX(0); }
.drawer-backdrop { position: fixed; z-index: 50; inset: 0; background: rgba(0, 0, 0, .58); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px 10px 12px 18px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 { margin: 3px 0 0; font-size: 17px; }
.eyebrow { color: var(--accent); font: 700 10px/1 monospace; letter-spacing: .14em; }
.session-list { overflow: auto; padding: 10px; }

.session-card { margin-bottom: 7px; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; background: #202020; }

.session-heading {
  --session-color: #3a3a3a;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 7px 10px;
  border-left: 4px solid var(--session-color);
}

.session-label {
  display: grid;
  place-items: center;
  min-width: 45px;
  height: 20px;
  padding: 0 6px;
  border-radius: 2px;
  font: 700 10px/1 monospace;
}

.session-name { min-width: 0; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }
.session-meta { color: var(--subtle); font-size: 11px; }

.pane-button {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 42px;
  padding: 6px 10px 6px 14px;
  border: 0;
  border-top: 1px solid #2e2e2e;
  background: #1c1c1c;
  color: var(--text);
  text-align: left;
}

.pane-button:hover, .pane-button.open { background: #292929; }
.pane-copy { min-width: 0; }
.pane-title, .pane-path { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pane-title { font-size: 12px; }
.pane-path { margin-top: 2px; color: var(--subtle); font: 10px/1.2 "Cascadia Code", monospace; }
.pane-agent { color: var(--muted); font-size: 10px; }

.drawer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(48px + var(--safe-bottom));
  padding: 0 15px var(--safe-bottom);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
}

.drawer-footer button { border: 0; background: transparent; color: var(--accent); }

.connection-banner {
  position: fixed;
  z-index: 35;
  top: calc(52px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 24px);
  padding: 7px 12px;
  border: 1px solid #704d10;
  border-radius: 4px;
  background: #3c2c11;
  color: #ffe0a0;
  font-size: 12px;
}

.toast-region { position: fixed; z-index: 80; right: 14px; bottom: 16px; display: grid; gap: 8px; width: min(350px, calc(100vw - 28px)); }

.toast {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 13px;
  border: 1px solid #745618;
  border-left: 4px solid var(--alert);
  border-radius: 5px;
  background: #242017;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .42);
}

.toast-title { font-size: 12px; font-weight: 700; }
.toast-subtitle { margin-top: 3px; color: var(--muted); font-size: 11px; }
.toast button { border: 0; background: transparent; color: #ffd271; font-size: 11px; font-weight: 600; }

.mobile-keybar { display: none; }
.mobile-only { display: none; }

.access-state { position: fixed; z-index: 100; inset: 0; background: var(--bg); }
.access-card { display: grid; justify-items: center; max-width: 420px; }
.access-state[hidden], .drawer-backdrop[hidden], .connection-banner[hidden] { display: none; }

@media (max-width: 720px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: grid; }
  .brand { padding: 0 7px 0 0; }
  .brand-name { display: none; }
  .mobile-active-tab {
    --tab-color: #3a3a3a;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    align-self: stretch;
    padding: 0 8px;
    border: 0;
    border-bottom: 2px solid var(--tab-color);
    background: transparent;
    color: white;
    text-align: left;
  }
  .mobile-active-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; font-weight: 600; }
  .app-shell { grid-template-rows: calc(44px + var(--safe-top)) minmax(0, 1fr) calc(42px + var(--safe-bottom)); }
  .terminal-stage { grid-row: 2; }
  .terminal-panel { padding: 6px 2px 3px 6px; }
  .mobile-keybar {
    z-index: 20;
    display: flex;
    grid-row: 3;
    gap: 4px;
    overflow-x: auto;
    padding: 5px 6px calc(5px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: #1d1d1d;
    scrollbar-width: none;
  }
  .mobile-keybar::-webkit-scrollbar { display: none; }
  .mobile-keybar button {
    min-width: 48px;
    height: 31px;
    padding: 0 8px;
    border: 1px solid #404040;
    border-radius: 4px;
    background: #2b2b2b;
    color: #ededed;
    font: 11px/1 "Cascadia Code", monospace;
  }
  .mobile-keybar button:active { background: #444; }
  .toast-region { bottom: calc(54px + var(--safe-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
