/* Nerd Font symbols (powerline separators, devicons, etc.) as a fallback so
   prompt glyphs render; normal monospace still handles text. */
@font-face {
  font-family: 'Symbols Nerd Font Mono';
  src: url('./fonts/SymbolsNerdFontMono.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg: #0d1117;
  --bg-2: #11161d;
  --panel: #161b22;
  --border: #21262d;
  --text: #c9d1d9;
  --muted: #8b949e;
  --accent: #d97757;       /* Claude clay/orange */
  --accent-dim: #b45f44;
  --green: #3fb950;
  --red: #f85149;
  --sel: #1f6feb33;
  font-size: 14px;
}

* { box-sizing: border-box; }

/* ---------- Scrollbars ---------- */
* {
  scrollbar-width: thin;                       /* Firefox */
  scrollbar-color: #30363d var(--bg-2);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 6px;
  border: 2px solid var(--bg-2);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }
::-webkit-scrollbar-corner { background: var(--bg-2); }
/* terminal panes sit on the darker --bg */
.term-pane ::-webkit-scrollbar-track,
.term-pane ::-webkit-scrollbar-corner { background: var(--bg); }
.term-pane ::-webkit-scrollbar-thumb { border-color: var(--bg); }
.term-pane { scrollbar-color: #30363d var(--bg); }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  height: 100dvh; /* track mobile browser chrome */
}

/* ---------- Window Controls Overlay (PWA) ---------- */
/* When installed with WCO, the app's own top row IS the title bar: the sidebar
   header and the tab strip live in the draggable overlay band, and the OS
   window controls sit at the far right. No separate title bar, no offset. */
@media all and (display-mode: window-controls-overlay) {
  .side-head,
  #tabs {
    -webkit-app-region: drag;
    app-region: drag;
  }
  .side-head {
    min-height: env(titlebar-area-height, 33px);
    /* line the brand up with the window-controls band on the right */
    padding-left: calc(14px + env(titlebar-area-x, 0px));
  }
  .side-head .brand,
  .side-head .icon-btn {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }
  #tabs {
    /* reserve space at the top-right for the OS window controls */
    padding-right: calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw) + 8px);
  }
  #tabs .tab {
    -webkit-app-region: no-drag;
    app-region: no-drag;
  }
}

/* ---------- Sidebar ---------- */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

/* connection swapper */
#conn-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 12px;
  flex: none;
}
#conn-bar > i { font-size: 11px; }
#conn-select {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 12px;
  outline: none;
}
#conn-select:focus { border-color: var(--accent-dim); }
#conn-bar .icon-btn { font-size: 12px; padding: 2px 6px; }

.conn-list { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.conn-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; }
.conn-row-label { font-weight: 600; }
.conn-row code { color: var(--muted); font-size: 11px; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.conn-del { border: none; background: none; color: var(--muted); cursor: pointer; }
.conn-del:hover { color: var(--red); }
.conn-add { display: flex; gap: 6px; margin-top: 12px; align-items: center; }
.conn-add .modal-input { margin-top: 0; }
.conn-sub { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-top: 16px; margin-bottom: 4px; }
.conn-coord { border-top: 1px solid var(--border); margin-top: 14px; }
.conn-coord .modal-input { margin-top: 8px; }
.conn-coord .m-btn.ok { margin-top: 10px; }
.conn-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 11px; text-transform: none; letter-spacing: 0; }
.conn-seen { font-size: 10.5px; color: var(--muted); }

/* swappable sidebar views + bottom tab switcher */
#sidebar-body { flex: 1 1 auto; min-height: 0; display: flex; }
.sb-view { display: none; flex-direction: column; flex: 1; min-width: 0; min-height: 0; padding-top: 6px; }
.sb-view.active { display: flex; }

.list { list-style: none; margin: 0; padding: 4px 8px 10px; overflow-y: auto; }
#terminal-list { flex: 1 1 auto; min-height: 0; }
.folders { flex: 1 1 auto; min-height: 0; }

#sidebar-tabs { display: flex; border-top: 1px solid var(--border); background: var(--bg-2); flex: none; }
.sb-tab {
  flex: 1;
  padding: 9px 6px;
  background: none;
  border: none;
  border-top: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.sb-tab:hover { color: var(--text); background: #1c2230; }
.sb-tab.active { color: var(--text); border-top-color: var(--accent); background: var(--bg); }
.sb-badge { font-size: 10px; background: var(--panel); padding: 0 6px; border-radius: 9px; color: var(--muted); min-width: 16px; text-align: center; }
.sb-badge:empty { display: none; }

.filter {
  margin: 0 12px 8px;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.filter:focus { border-color: var(--accent-dim); }

/* terminal rows */
.term-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 2px;
}
.term-row:hover { background: #1c2230; }
.term-row.active { background: var(--sel); }
.term-row .tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }
.term-row.dead .tdot { background: var(--red); }
.term-row .tinfo { min-width: 0; flex: 1; }
.term-row .ttitle { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-row .tcwd { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-row .tkill { opacity: 0; color: var(--muted); border: none; background: none; cursor: pointer; font-size: 14px; }
.term-row:hover .tkill { opacity: 1; }
.term-row .tkill:hover { color: var(--red); }

/* folders */
.folder { margin-bottom: 2px; }
.folder-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.folder-head:hover { background: #1c2230; }
.folder-head .chev { color: var(--muted); font-size: 9px; width: 12px; text-align: center; transition: transform .12s; }
.folder.open .chev { transform: rotate(90deg); }
.folder-head .fname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.folder-head .fcount { font-size: 11px; color: var(--muted); background: var(--bg); padding: 1px 7px; border-radius: 10px; }
.folder-head .fopen { opacity: 0; border: none; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.folder-head:hover .fopen { opacity: 1; }
.folder-head .fopen:hover { color: var(--accent); }
.fpath { font-size: 10px; color: var(--muted); padding: 0 8px 4px 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sessions { display: none; padding-left: 14px; }
.folder.open .sessions { display: block; }

.session {
  padding: 6px 9px;
  border-left: 2px solid var(--border);
  margin-left: 6px;
  cursor: pointer;
  border-radius: 0 6px 6px 0;
}
.session:hover { background: #1c2230; border-left-color: var(--accent); }
.session .ssum { font-size: 12.5px; line-height: 1.35; }
.session .smeta { font-size: 10.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; }

/* footer */
/* usage bars */
#usage {
  padding: 8px 14px 9px;
  border-top: 1px solid var(--border);
  flex: none;
}
.usage-head { display: flex; align-items: center; justify-content: space-between; font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 6px; }
.usage-est.live { color: var(--green); border-color: var(--green); }
.usage-est.paused { color: #d6a429; border-color: #d6a429; }
.usage-live {
  text-transform: none;
  letter-spacing: 0;
  font-size: 10px;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  padding: 1px 7px;
  cursor: pointer;
}
.usage-live:hover { color: var(--text); border-color: var(--accent-dim); }
.usage-est {
  text-transform: none;
  letter-spacing: 0;
  font-size: 9px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 4px;
}
.usage-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.usage-row:hover .ubar { box-shadow: 0 0 0 1px var(--accent-dim); }
.usage-row .ul { font-size: 11px; color: var(--muted); width: 16px; flex: none; }
.ubar { flex: 1 1 auto; height: 7px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.ufill { height: 100%; width: 0; background: var(--green); border-radius: 4px; transition: width 0.4s; }
.ufill.warm { background: #d6a429; }
.ufill.hot { background: var(--red); }
.usage-row .upct { font-size: 10.5px; color: var(--muted); width: 34px; text-align: right; flex: none; font-variant-numeric: tabular-nums; }

.side-foot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  flex: none;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }

/* buttons */
.icon-btn, .ghost-btn {
  background: none; border: 1px solid transparent; color: var(--muted);
  cursor: pointer; border-radius: 6px;
}
.icon-btn { font-size: 16px; padding: 2px 7px; }
.icon-btn:hover { color: var(--text); background: #1c2230; }
.ghost-btn { font-size: 12px; padding: 3px 9px; border-color: var(--border); }
.ghost-btn:hover { color: var(--text); border-color: var(--accent-dim); }

/* ---------- Main / terminal ---------- */
#main { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

#tabs {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
  overflow-x: auto;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  min-height: 38px;
}
.tab {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--muted);
  max-width: 230px;
}
.tab.active { background: var(--bg); color: var(--text); }
.tab .tabname { overflow: hidden; text-overflow: ellipsis; }
.tab .x { border: none; background: none; color: inherit; cursor: pointer; opacity: .6; font-size: 14px; }
.tab .x:hover { opacity: 1; color: var(--red); }

#term-host { position: relative; flex: 1 1 auto; min-height: 0; }
.term-pane { position: absolute; inset: 0; padding: 6px 4px 4px 8px; display: none; }
.term-pane.active { display: block; }
.term-pane .xterm { height: 100%; }

.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.empty-inner { text-align: center; max-width: 420px; color: var(--muted); }
.empty-inner h1 { color: var(--text); font-size: 20px; margin-bottom: 8px; font-weight: 600; }
.empty-inner p { line-height: 1.6; }
kbd { background: var(--panel); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: var(--text); font-size: 12px; }

/* ---------- File explorer pane ---------- */
.fs-pane {
  padding: 0;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
}
/* Beat the generic `.term-pane.active { display: block }` so the flex
   column (and therefore the scrollable list) survives when active. */
.term-pane.fs-pane.active { display: flex; }
.fs-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex: none;
}
.fs-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 13px;
  cursor: pointer;
  flex: none;
}
.fs-btn:hover:not(:disabled) { border-color: var(--accent-dim); }
.fs-btn:disabled { opacity: 0.35; cursor: default; }
.fs-shell { margin-left: auto; }

.fs-crumbs {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: nowrap;
  overflow-x: auto;
  font-size: 12.5px;
  min-width: 0;
  padding: 0 4px;
}
.crumb { padding: 2px 6px; border-radius: 6px; cursor: pointer; white-space: nowrap; color: var(--muted); }
.crumb:hover { background: #1c2230; color: var(--text); }
.crumb.cur { color: var(--text); font-weight: 600; cursor: default; }
.crumb.cur:hover { background: none; }
.crumb-sep { color: var(--border); }

.fs-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 0; }
.fs-row {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 5px 14px;
  cursor: default;
  font-size: 13px;
  user-select: none;
}
.fs-row:hover { background: #1c2230; }
.fs-row.err { opacity: 0.5; }
.fs-row .fi { text-align: center; color: var(--muted); }
.fs-row .fi .fa-folder, .fs-row .fi .fa-hard-drive { color: var(--accent); }
.fs-row .fn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fs-row .fsz { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.fs-row .fmt { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.fs-empty, .fs-error { padding: 24px; color: var(--muted); text-align: center; }
.fs-error b { color: var(--text); }

/* ---------- Monaco editor pane ---------- */
.ed-pane { padding: 0; background: var(--bg); }
.ed-pane .monaco-editor,
.ed-pane .monaco-editor .overflow-guard { width: 100% !important; height: 100% !important; }

/* ---------- Remote desktop pane ---------- */
.desk-pane { padding: 0; background: #000; overflow: auto; outline: none; }
/* beat `.term-pane.active { display:block }` so the flex centering applies */
.term-pane.desk-pane.active { display: flex; }
.desk-img { max-width: 100%; max-height: 100%; display: block; margin: auto; } /* fit (contain) + center; img box == image so coords stay exact */
.desk-status { position: absolute; top: 50%; left: 0; right: 0; transform: translateY(-50%); text-align: center; color: var(--muted); font-size: 13px; }
/* software cursor (GDI capture excludes the OS cursor) */
.desk-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #38e06a;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
  z-index: 5;
}
/* touch device in landscape: desktop fills the screen (regardless of width) */
@media (orientation: landscape) and (pointer: coarse) {
  #app.desk-active .desk-pane.active { position: fixed; inset: 0; z-index: 1000; }
}

/* tab kinds */
.tab .ticon { font-size: 11px; opacity: 0.8; }
.tab-fs.active,
.tab-editor.active { box-shadow: inset 0 2px 0 var(--accent); }
.tab.dirty .tabname::before { content: '● '; color: var(--accent); font-size: 10px; }
.head-actions { display: flex; gap: 2px; }

/* ---------- Confirm modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: #000a;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  width: min(440px, 90vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px #000b;
  padding: 18px 18px 14px;
}
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.modal-msg { font-size: 13px; line-height: 1.55; color: var(--muted); }
.modal-msg br { content: ''; }
.modal-input {
  width: 100%;
  margin-top: 14px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.modal-input:focus { border-color: var(--accent); }
.modal-field { display: block; margin-top: 12px; }
.modal-field span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.modal-field .modal-input { margin-top: 0; }
.modal-err { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 14px; }
.icon-btn.enrolled { color: var(--green); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.m-btn {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.m-btn:hover { border-color: var(--accent-dim); }
.m-btn.ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.m-btn.ok:hover { background: var(--accent-dim); }
.m-btn.ok.danger { background: var(--red); border-color: var(--red); }
.m-btn.ok.danger:hover { background: #c93c34; }

/* ---------- Context menu ---------- */
.ctx-menu {
  position: fixed;
  z-index: 2000;
  min-width: 210px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 10px 30px #000a;
  font-size: 13px;
  user-select: none;
}
.ctx-item {
  display: flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text);
}
.ctx-ic { width: 16px; text-align: center; margin-right: 10px; color: var(--muted); font-size: 13px; }
.ctx-item:hover { background: var(--sel); }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger .ctx-ic { color: var(--red); }
.ctx-item.danger:hover { background: #f8514922; }
.ctx-sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--border);
}

/* mobile terminal key bar (above the soft keyboard) */
#keybar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0; /* transform lifts it above the keyboard on iOS */
  z-index: 60;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
#keybar.show { display: flex; }
.kb-row { display: grid; gap: 4px; }
.kb-key {
  min-width: 0;
  padding: 10px 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 12px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.kb-key:active { background: var(--sel); }
.kb-key.kb-mod { color: var(--muted); }
.kb-key.armed { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (min-width: 761px) { #keybar { display: none !important; } }

/* mobile menu button (in the tab bar) + backdrop — hidden on desktop */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  font-size: 16px;
  padding: 0 14px;
  cursor: pointer;
  flex: none;
}
#nav-backdrop { display: none; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }

  /* sidebar becomes a slide-in drawer */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: 86%;
    max-width: 340px;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  #app.nav-open #sidebar { transform: none; box-shadow: 2px 0 24px #000a; }
  #nav-backdrop { position: fixed; inset: 0; z-index: 40; background: #0007; }
  #app:not(.nav-open) #nav-backdrop { display: none; }
  #app.nav-open #nav-backdrop { display: block; }

  .nav-toggle { display: flex; }
  #tabs { min-height: 42px; }
  .tab { max-width: 52vw; padding: 9px 12px; }

  /* bigger touch targets */
  .icon-btn { padding: 6px 9px; font-size: 17px; }
  .sb-tab { padding: 12px 6px; }
  .term-row, .session, .folder-head, .ctx-item, .fs-row { padding-top: 9px; padding-bottom: 9px; }

  /* 16px inputs so iOS doesn't zoom on focus */
  .filter, #conn-select, .modal-input { font-size: 16px; }
  .modal { width: 94vw; }
}
