/* Design tokens, dark base theme, typography */

:root {
  /* Background palette */
  --bg: #0D1117;           /* --color-bg-base */
  --bg-secondary: #10131C; /* --color-bg-elevated */
  --bg-tile: #10131C;      /* --color-bg-elevated */
  --bg-header: #0D1117;    /* --color-bg-base (header matches page) */
  --bg-overlay: rgba(13, 17, 23, 0.85); /* brand base with opacity */
  --bg-tile-hover: #1A1F2B; /* --color-bg-surface */
  --bg-surface: #1A1F2B;

  /* Text palette */
  --text: #F0F6FF;         /* --color-text-primary */
  --text-dim: #4A5060;     /* --color-text-disabled */
  --text-muted: #8E95A3;   /* --color-text-secondary */

  /* Borders */
  --border: #2A3040;       /* --color-border-default */
  --border-subtle: #1E2430; /* --color-border-subtle */

  /* Accent */
  --accent: #00D9F5;        /* brand cyan */
  --accent-hover: #00b8d1;  /* slightly darker cyan for hover */
  --accent-dim: rgba(0, 217, 245, 0.15);

  /* Bell / notification */
  --bell: #F1A640;
  --bell-color: #F1A640;    /* brand amber */
  --activity-color: #F1A640;
  --bell-glow: rgba(241, 166, 64, 0.25);
  --bell-border: rgba(241, 166, 64, 0.6);

  /* Status */
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;

  /* Layout */
  --tile-height: 300px;
  --tile-min-width: 360px;
  --grid-gap: 8px;
  --grid-padding: 16px;
  --header-height: 44px;

  /* Transitions */
  --t-zoom: 250ms ease-in-out;
  --t-fast: 150ms ease;
  --t-fade: 200ms ease;

  /* Typography */
  --font-ui: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', 'Menlo', monospace;
}

/* Box-sizing reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ============================================================
   Custom scrollbar — thin, dark, matches theme
   ============================================================ */

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(48, 54, 61, 0.6) transparent;
}

/* WebKit (Chrome, Edge, Safari) */
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(48, 54, 61, 0.6);
  border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 200, 200, 0.35);  /* --accent at 35% */
}

*::-webkit-scrollbar-thumb:active {
  background: rgba(0, 200, 200, 0.55);  /* --accent at 55% */
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

/* Base */
html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

/* Utility */
.hidden {
  display: none !important;
}

/* ============================================================
   App layout
   ============================================================ */

.view {
  height: 100vh;           /* fallback for browsers without dvh support */
  height: 100dvh;          /* dynamic viewport height — adjusts for mobile browser chrome */
  overflow: hidden;
}

.view--active {
  display: flex;
  flex-direction: column;
}

.view.hidden {
  display: none;
}

/* ============================================================
   App header
   ============================================================ */

.app-header {
  height: var(--header-height);
  padding: 0 var(--grid-padding);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* ============================================================
   Session grid
   ============================================================ */

.session-grid {
  flex: 1;
  overflow-y: auto;
  padding: var(--grid-padding);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min-width), 1fr));
  gap: var(--grid-gap);
  align-content: start;
}

/* ============================================================
   Session tile
   ============================================================ */

.session-tile {
  height: var(--tile-height);
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.session-tile:hover,
.session-tile:focus-visible {
  border-color: var(--accent);
}

/* Bell / notification tile */
.session-tile--bell {
  border-color: var(--bell-border);
  box-shadow: 0 0 0 1px var(--bell-border), inset 0 0 12px var(--bell-glow);
}

/* ============================================================
   Tile header
   ============================================================ */

.tile-header {
  height: 32px;
  padding: 0 10px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
}

.tile-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.tile-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: 8px;
}

/* Bell notification badge */
.tile-bell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 8px;
  background: var(--bell);
  color: #0D1117;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  margin-right: 6px;
  animation: bell-pulse 1.4s ease-in-out infinite;
}

@keyframes bell-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

/* ============================================================
   Tile body
   ============================================================ */

.tile-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: #000000;
}

.tile-body pre {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 8px;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 11px;
  line-height: 1.0;
  color: #c9d1d9;               /* match xterm.js foreground */
  white-space: pre;
  overflow: hidden;
  margin: 0;
}

/* Loading placeholder tile — shown while a new session is being created */
.tile--loading {
  opacity: 0.6;
  pointer-events: none;
}

.tile--loading .tile-body pre {
  background: repeating-linear-gradient(
    90deg,
    var(--border) 0px,
    var(--bg-surface) 30px,
    var(--border) 60px
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  min-height: 60px;
  border-radius: 2px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.tile-pre {
  position: absolute;
  inset: 0;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: pre;
  overflow: hidden;
  margin: 0;
}



/* ============================================================
   Empty state
   ============================================================ */

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

/* ============================================================
   Responsive breakpoints
   ============================================================ */

@media (max-width:1199px) and (min-width:900px) {
  :root {
    --tile-min-width:420px;
  }
}

@media (max-width:899px) and (min-width:600px) {
  .session-grid {
    grid-template-columns:1fr;
    padding:8px;
  }
  .session-tile {
    height:200px;
  }
}

@media (max-width:599px) {
  .session-grid {
    display:flex;
    flex-direction:column;
    gap:1px;
    padding:0;
  }
  .session-tile {
    height:auto;
    border-radius:0;
    border-left:none;
    border-right:none;
  }
}

@media (max-width:599px) and (orientation:landscape) {
  .session-grid {
    padding:0;
  }
}

/* ============================================================
   Expanded view
   ============================================================ */

#view-expanded {
  position: relative;
}

.expanded-header {
  height: var(--header-height);
  padding: 0 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 18px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.expanded-session-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


.view-body {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ============================================================
   Session sidebar
   ============================================================ */

.session-sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.25s ease, min-width 0.25s ease;
}

.session-sidebar.sidebar--collapsed {
  width: 0;
  min-width: 0;
}

.sidebar-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  touch-action: pan-y;          /* tell browser vertical panning is allowed on mobile */
  overscroll-behavior: contain; /* prevent scroll chaining to non-scrollable parent */
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 4px;
}

.sidebar-collapse-btn:hover {
  color: var(--text);
}

.sidebar-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  cursor: pointer;
  color: var(--text-muted);
}

.sidebar-toggle-btn:hover {
  border-color: var(--accent);
}

/* ============================================================
   Sidebar session card styles
   ============================================================ */

.sidebar-item {
  height: 120px;
  flex-shrink: 0;          /* prevent flex from compressing cards to fit */
  background: var(--bg-secondary);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.sidebar-item:hover,
.sidebar-item:focus-visible {
  border-color: var(--accent);
}

.sidebar-item--active {
  background: var(--bg-surface);
  border-color: var(--accent);
  border-left: 3px solid var(--accent);
}

/* Bell / activity glow — matches .session-tile--bell */
.sidebar-item--bell {
  border-color: var(--bell-border);
  box-shadow: 0 0 0 1px var(--bell-border), inset 0 0 12px var(--bell-glow);
}

.sidebar-item-header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 8px 8px 4px;
  height: 32px;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.sidebar-item-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000000;
}



.sidebar-item-body pre {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 10px;
  line-height: 1.0;
  color: #c9d1d9;               /* match xterm.js foreground */
  white-space: pre;
  padding: 0 8px 6px;
  margin: 0;
}

.sidebar-empty {
  padding: 16px 12px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.terminal-container {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: #000;
  padding: 0 4px;  /* keep text off the side edges */
}

/* xterm.js injects overflow-y: scroll on .xterm-viewport — override it */
.xterm .xterm-viewport {
  overflow-y: hidden !important;
}

.reconnect-overlay {
  position: absolute;
  inset: var(--header-height) 0 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ============================================================
   Zoom-in-place expand/collapse transition
   ============================================================ */

.session-tile--expanding {
  position: fixed;
  z-index: 50;
  border-radius: 4px;
  transition:
    top var(--t-zoom),
    left var(--t-zoom),
    width var(--t-zoom),
    height var(--t-zoom),
    border-radius var(--t-zoom);
}

.session-tile--expanded {
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;    /* fallback for browsers without dvh support */
  height: 100dvh !important;   /* dynamic viewport height — adjusts for mobile browser chrome */
  border-radius: 0;
}

.session-grid--dimming .session-tile:not(.session-tile--expanding) {
  opacity: 0;
  transition: opacity var(--t-fade);
}

/* ============================================================
   Activity dot — absolute positioned in upper-right corner of tile
   ============================================================ */

.tile-bell-dot {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bell);
  animation: bell-pulse 1.4s ease-in-out infinite;
  z-index: 1;
  pointer-events: none;
}

/* Sidebar variant: inline (not absolute), fits within header row */
.sidebar-bell-dot {
  position: static;
  display: inline-block;
  flex-shrink: 0;
  width: 7px;
  height: 7px;
}

/* ============================================================
   Connection status indicator states
   ============================================================ */

.connection-status--ok {
  color: var(--ok);
}

.connection-status--warn {
  color: var(--warn);
}

.connection-status--err {
  color: var(--err);
}

/* ============================================================
   Toast notification
   ============================================================ */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-header);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-muted);
  z-index: 100;
  pointer-events: none;
  animation: toast-in var(--t-fast) ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ============================================================
   Mobile three-tier priority list (bell / active / idle)
   ============================================================ */

@media (max-width:599px) {
  /* Tier 1 — bell: expanded preview (~126px total) */
  .session-tile--tier-bell .tile-body {
    height: 90px;
  }
  .session-tile--tier-bell {
    min-height: 126px;
  }

  /* Tier 2 — active: single-line preview (~60px total) */
  .session-tile--tier-active .tile-body {
    height: 24px;
  }
  .session-tile--tier-active {
    min-height: 60px;
  }
  .session-tile--tier-active .tile-body pre {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Tier 3 — idle: compact preview (36px body) */
  .session-tile--tier-idle .tile-body {
    height: 36px;
  }
  .session-tile--tier-idle {
    min-height: 44px;
  }
  .session-tile--tier-idle .tile-header {
    height: 44px;
  }
  .session-tile--tier-idle .tile-name {
    color: var(--text-dim);
  }
}


/* ─── Mobile Bottom Sheet ─────────────────────────────────────── */

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
}

.bottom-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
}

.bottom-sheet__panel {
  position: relative;
  width: 100%;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  border-radius: 12px 12px 0 0;
  max-height: 70vh;
  overflow-y: auto;
  animation: sheet-up var(--t-zoom) ease;
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.bottom-sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 6px;
}

.bottom-sheet__list {
  list-style: none;
  padding-bottom: 8px;
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 56px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--t-fast);
}

.sheet-item:hover {
  background: var(--accent-dim);
}

.sheet-item__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-item__bell {
  color: var(--bell);
}

.sheet-item__time {
  font-size: 12px;
  color: var(--text-dim);
}

/* ─── Floating Session Pill ───────────────────────────────────── */

.session-pill {
  position: fixed;
  bottom: 24px;
  right: 16px;
  z-index: 50;
  background: var(--bg-header);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 0.75;
}

.session-pill:hover {
  opacity: 1;
  border-color: var(--accent);
  color: var(--text);
}

.session-pill__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.session-pill__bell {
  color: var(--bell);
}


/* ============================================================
   Source tile states — offline and auth-required (Phase 3)
   ============================================================ */

.source-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  height: var(--tile-height);
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.source-tile--offline {
  opacity: 0.45;
  border-style: dashed;
}

.source-tile--offline .source-tile__name {
  color: var(--text-dim);
}

.source-tile--offline .source-tile__badge {
  background: var(--err);
  color: #ffffff;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
}

.source-tile--offline .source-tile__last-seen {
  font-size: 11px;
  color: var(--text-dim);
}

.source-tile--auth {
  border-color: var(--warn);
  border-style: dashed;
}

.source-tile__name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.source-tile__login-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  opacity: 1;
  transition: opacity var(--t-fast);
}

.source-tile__login-btn:hover {
  opacity: 0.85;
}

.source-tile__login-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.source-tile__hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Reduced Motion ──────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .tile-bell {
    animation: none;
  }

  .session-tile--expanding {
    transition: none;
  }

  .session-grid--dimming .session-tile:not(.session-tile--expanding) {
    transition: none;
  }

  .bottom-sheet__panel {
    animation: none;
  }

  .toast {
    animation: none;
  }

  .session-sidebar {
    transition: none;
  }

  .new-session-fab:active {
    transform: none;
  }
}

/* ============================================================
   App wordmark
   ============================================================ */

.app-wordmark {
  margin: 0;
  line-height: 1;
  display: flex;
  align-items: center;
}
.app-wordmark img {
  height: 24px;
  width: auto;
  display: block;
}

/* ============================================================
   Hover preview popover (desktop dashboard)
   ============================================================ */

.preview-popover {
  position: fixed;
  z-index: 500;
  background: #000000;
  border: 2px solid var(--accent);
  border-radius: 8px;
  padding: 16px 20px;
  /* Cover most of the viewport — centered with margin */
  top: 5vh;
  left: 5vw;
  right: 5vw;
  bottom: 5vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  pointer-events: none;   /* mouse events pass through to tiles below */
}

.preview-popover pre {
  margin: 0;
  font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
  font-size: 14px;
  line-height: 1.0;
  color: #c9d1d9;               /* match xterm.js foreground exactly */
  white-space: pre-wrap;        /* WRAP text instead of horizontal overflow */
  word-break: break-all;        /* break long lines at viewport edge */
  overflow-x: hidden;
}



/* ============================================================
   Delete (kill) session buttons — appear on hover
   ============================================================ */

.tile-delete {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 150ms ease;
  z-index: 2;
  line-height: 1;
}

.session-tile:hover .tile-delete,
.session-tile:focus-within .tile-delete {
  opacity: 1;
}

.tile-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  opacity: 1;
}

.sidebar-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 1px 5px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 150ms ease;
  flex-shrink: 0;
  line-height: 1;
}

.sidebar-item:hover .sidebar-delete,
.sidebar-item:focus-within .sidebar-delete {
  opacity: 1;
}

.sidebar-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  opacity: 1;
}

/* ============================================================
   Header actions + settings buttons
   ============================================================ */

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  padding: 0;
  flex-shrink: 0;
}

.header-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Settings dialog
   ============================================================ */

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 299;
}

.settings-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: 480px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 300;
  padding: 0;
  overflow: hidden;
  margin: 0;
}

/* <dialog> is display:none by default (UA stylesheet). When opened via
   showModal(), the browser adds the [open] attribute. We apply flex layout
   only when open — otherwise our display:flex would override the UA
   display:none and make the dialog always visible. */
.settings-dialog[open] {
  display: flex;
  flex-direction: column;
}

.settings-dialog::backdrop {
  background: transparent;
  pointer-events: none;  /* let clicks fall through to #settings-backdrop */
}

.settings-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-dialog-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.settings-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.settings-close-btn:hover {
  color: var(--text);
  background: var(--bg-surface);
}

.settings-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.settings-tabs {
  width: 140px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding: 8px 0;
  background: var(--bg-secondary);
}

.settings-tab {
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  padding: 10px 16px;
  font-size: 13px;
}

.settings-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.settings-tab--active {
  color: var(--accent);
  border-left-color: var(--accent);
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.settings-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 16px;
}

.settings-field {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-label {
  font-size: 13px;
  color: var(--text);
}

.settings-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}

.settings-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============================================================
   Settings dialog — mobile (bottom sheet at ≤599px)
   ============================================================ */

@media (max-width: 599px) {
  .settings-dialog {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    transform: none;
    width: 100%;
    height: 85vh;
    border-radius: 12px 12px 0 0;
    margin: 0;
  }

  .settings-layout {
    flex-direction: column;
  }

  .settings-tabs {
    width: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
    height: auto;
  }

  .settings-tab {
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    padding: 10px 16px;
  }

  .settings-tab--active {
    border-bottom-color: var(--accent);
    border-left-color: transparent;
  }
}

/* ============================================================
   Sessions tab controls
   ============================================================ */

.settings-field--column {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.settings-checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.settings-checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.settings-checkbox {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ============================================================
   New Session tab controls
   ============================================================ */

.settings-textarea {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px;
  resize: vertical;
  min-height: 60px;
  outline: none;
}

.settings-textarea:focus {
  border-color: var(--accent);
}

.settings-helper {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================================
   Notifications tab controls
   ============================================================ */

.settings-notification-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.settings-status-text {
  font-size: 12px;
  color: var(--text-muted);
}

.settings-action-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}

.settings-action-btn:hover {
  border-color: var(--accent);
}

.settings-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   Header + button inline name input (new-session-btn)
   ============================================================ */

.new-session-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--font-ui);
  padding: 4px 10px;
  width: 180px;
  outline: none;
  color: var(--text);
}

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

/* ============================================================
   Sidebar sticky footer (+ New button)
   ============================================================ */

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-new-btn {
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-ui);
  padding: 8px;
  cursor: pointer;
}

.sidebar-new-btn:hover {
  color: var(--text-muted);
  border-color: var(--text-muted);
}

/* ============================================================
   Mobile FAB — new session floating action button
   ============================================================ */

.new-session-fab {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 150ms ease;
}

.new-session-fab:active {
  transform: scale(0.95);
}

.new-session-fab:focus-visible {
  outline: 2px solid var(--bg);
  outline-offset: 2px;
}

/* Fixed-position input overlay triggered by mobile FAB —
   appended to body so position:fixed escapes overflow:hidden on views */
.fab-input-overlay {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 200;
}

/* ============================================================
   Device badge, group header, filter bar, sidebar device header
   ============================================================ */

.device-badge {
  display: inline-block;
  font-size: 9px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 4px;
  line-height: 1.4;
  vertical-align: middle;
}

.device-group-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  grid-column: 1 / -1;
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0;
}

.filter-pill {
  font-size: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 3px 10px;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
  line-height: 1.4;
}

.filter-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.filter-pill--active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
}

.sidebar-device-header {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 8px 12px 4px;
}

/* ============================================================
   Dashboard view modes — Fit
   ============================================================ */

/* Fit view — tiles fill viewport, no scroll */
.session-grid--fit {
  overflow: hidden;
  align-content: stretch;   /* let 1fr rows fill container height */
}

/* In fit mode, tiles must use height:auto so the CSS grid 1fr rows control sizing.
   The base .session-tile uses var(--tile-height) which is a fixed pixel value —
   overriding with height:auto lets the grid cell (from grid-template-rows: repeat(n,1fr))
   determine the tile height instead. JS sets only grid-template-columns/rows, not inline heights. */
.session-grid--fit .session-tile {
  height: auto;
}

/* In fit mode, tile body and pre use the base CSS:
   .tile-body { position: relative; overflow: hidden; }
   .tile-body pre { position: absolute; bottom: 0; left: 0; right: 0; }
   The pre's natural height from 80 lines of content exceeds the tile height, so it
   overflows from bottom:0 upward, and tile-body clips excess at the top — showing
   the bottom-most content (the prompt area) just like a real terminal. */

/* ============================================================
   Responsive overlay sidebar at <960px
   ============================================================ */

@media (max-width: 959px) {
  .session-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 200;
    width: 240px;
    min-width: 240px;
    transition: transform 0.25s ease;
    transform: translateX(0);
    box-shadow: 2px 0 16px rgba(0,0,0,0.5);
  }

  .session-sidebar.sidebar--collapsed {
    width: 240px;
    min-width: 240px;
    transform: translateX(-100%);
  }

  .sidebar-collapse-btn {
    display: none;
  }

  /* Mobile FAB: show on mobile, hide header + button */
  .new-session-fab {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #new-session-btn {
    display: none;
  }
}

/* ============================================================
   Remote Instances UI (task-15)
   ============================================================ */

.settings-input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  outline: none;
  transition: border-color 0.15s;
}

.settings-input:focus {
  border-color: var(--accent);
}

.settings-remote-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.settings-remote-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.settings-remote-url,
.settings-remote-name {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  outline: none;
  transition: border-color 0.15s;
}

.settings-remote-url {
  flex: 2;
}

.settings-remote-name {
  flex: 1;
}

.settings-remote-url:focus,
.settings-remote-name:focus {
  border-color: var(--accent);
}

.settings-remote-remove {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  transition: color 0.15s, border-color 0.15s;
}

.settings-remote-remove:hover {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Multi-Device tab — smooth enable/disable opacity transition */
#multi-device-fields {
  transition: opacity 0.2s ease;
}

/* Constrain device name input width so it doesn't stretch the full settings panel */
#setting-device-name {
  max-width: 200px;
}
