@font-face {
  font-family: 'JetBrains Mono';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('/fonts/jbm-400.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url('/fonts/jbm-500.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url('/fonts/jbm-600.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src: url('/fonts/jbm-700.ttf') format('truetype');
}

:root {
  /* terminal/tiling-wm inspired palette - deep charcoal-navy, not pure black */
  --bg: #0c0d13;
  --bg-panel: #121420;
  --bg-elevated: #1a1c2a;
  --bg-input: #171927;
  --border: #262a3d;
  --border-soft: #1d2032;
  --text: #cdd0e3;
  --text-dim: #7d81a0;
  --text-faint: #4c5069;
  --accent: #8b7cf6;
  --accent-dim: #362f5e;
  --accent-soft: #2a2547;
  --cyan: #63d2ce;
  --green: #7fd88f;
  --amber: #e3b341;
  --red: #ef6b7a;
  --radius: 6px;
  --radius-sm: 4px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

button { font-family: inherit; font-size: 0.9rem; cursor: pointer; color: var(--text); }

input, textarea {
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, textarea:focus { outline: 1px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  min-height: 40px;
  font-size: 0.85rem;
}
.btn:hover { border-color: var(--text-faint); }
.btn-primary { background: var(--accent-dim); border-color: var(--accent); color: #e4defe; }
.btn-primary:hover { background: var(--accent-soft); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-small { padding: 0.4rem 0.7rem; min-height: 34px; font-size: 0.8rem; }
.btn-block { width: 100%; margin-top: 0.85rem; }
.btn-icon {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 1.2rem; min-width: 36px; min-height: 36px; border-radius: var(--radius-sm);
}
.btn-icon:hover { color: var(--text); background: var(--bg-elevated); }

.icon-btn {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  font-size: 1rem; min-width: 34px; min-height: 34px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--border); }

.muted { color: var(--text-dim); }
.error { color: var(--red); font-size: 0.85rem; }

/* --- Login --- */
#login-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; }
.login-box { width: 100%; max-width: 320px; text-align: center; }
.login-ascii { color: var(--accent); font-size: 0.7rem; line-height: 1.2; margin: 0 0 0.5rem; }
.login-box > .muted { font-size: 0.8rem; margin: 0; }
.login-box form { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 1.5rem; }
.login-box button[type="submit"] { background: var(--accent-dim); border: 1px solid var(--accent); color: #e4defe; border-radius: var(--radius-sm); padding: 0.65rem; min-height: 42px; }

/* --- App shell: sidebar + main --- */
#app-view { height: 100vh; display: flex; overflow: hidden; }

.sidebar {
  width: 260px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-panel); border-right: 1px solid var(--border-soft);
  position: fixed; inset: 0 auto 0 0; z-index: 30;
  transform: translateX(-100%); transition: transform 0.18s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 25; }

.sidebar-brand { padding: 0.9rem 0.9rem 0.7rem; border-bottom: 1px solid var(--border-soft); }
.brand-mark { font-weight: 600; font-size: 0.95rem; letter-spacing: -0.01em; }
.brand-mark .accent { color: var(--accent); }
.status-row { display: flex; gap: 0.6rem; margin-top: 0.5rem; font-size: 0.72rem; color: var(--text-dim); }
.status-pill { display: flex; align-items: center; gap: 0.3rem; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); flex: none; }
.dot.online { background: var(--green); }
.dot.offline { background: var(--red); }

.project-switcher {
  margin: 0.75rem 0.75rem 0; text-align: left;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem; min-height: 44px;
}
.ps-label { display: block; font-size: 0.65rem; color: var(--text-faint); text-transform: lowercase; }
.ps-row { display: flex; justify-content: space-between; align-items: center; margin-top: 0.15rem; font-size: 0.85rem; }
.ps-row .chevron { color: var(--text-dim); }

.btn-new-session {
  margin: 0.6rem 0.75rem 0.5rem; text-align: left;
  background: transparent; border: 1px dashed var(--border); color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 0.5rem 0.65rem; min-height: 40px; font-size: 0.82rem;
}
.btn-new-session:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-new-session:disabled { opacity: 0.4; cursor: default; }

.session-list { flex: 1; overflow-y: auto; padding: 0.25rem 0.5rem 0.5rem; }
.session-group-label { font-size: 0.68rem; color: var(--text-faint); padding: 0.6rem 0.4rem 0.3rem; }
.session-item {
  display: block; width: 100%; text-align: left; background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); padding: 0.45rem 0.5rem; margin-bottom: 0.15rem; min-height: 40px;
  color: var(--text-dim); font-size: 0.8rem; overflow: hidden;
}
.session-item:hover { background: var(--bg-elevated); color: var(--text); }
.session-item.active { background: var(--accent-soft); border-color: var(--accent-dim); color: var(--text); }
.session-item .si-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .si-mode { font-size: 0.68rem; color: var(--text-faint); }

.sidebar-footer { display: flex; gap: 0.25rem; padding: 0.5rem; border-top: 1px solid var(--border-soft); }

/* --- Main pane --- */
.main-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.main-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border-soft); position: relative; }
.sidebar-toggle { display: inline-flex; }
.main-header-info { flex: 1; min-width: 0; }
.mh-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mh-meta { font-size: 0.75rem; color: var(--text-dim); display: flex; gap: 0.6rem; margin-top: 0.1rem; }
.mh-meta a { color: var(--cyan); text-decoration: none; }

.mh-menu {
  position: absolute; top: 3.2rem; right: 0.75rem; z-index: 12;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  display: flex; flex-direction: column; min-width: 160px; overflow: hidden;
}
.mh-menu button { text-align: left; background: transparent; border: none; padding: 0.6rem 0.8rem; font-size: 0.82rem; color: var(--text); }
.mh-menu button:hover { background: var(--bg-input); }
.mh-menu button.danger { color: var(--red); }

.mode-tabs { display: flex; gap: 0.3rem; padding: 0.6rem 0.9rem 0; }
.mode-tab {
  background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 0.4rem 0.9rem; font-size: 0.8rem; min-height: 36px;
}
.mode-tab::before { content: ''; }
.mode-tab.active { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-soft); }
.mode-tab.active::before { content: '● '; }

.confirm-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  background: rgba(227,179,65,0.08); border: 1px solid var(--amber); border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem; margin: 0.6rem 0.9rem 0; font-size: 0.82rem;
}
.warn-glyph { color: var(--amber); font-weight: 700; margin-right: 0.3rem; }

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.75rem; padding: 1rem; }
.ascii-prompt { color: var(--text-faint); font-size: 0.6rem; line-height: 1.15; }

.chat-log { flex: 1; display: flex; flex-direction: column; gap: 0.55rem; padding: 0.85rem 0.9rem; overflow-y: auto; }
.msg { max-width: 78ch; border-radius: var(--radius-sm); padding: 0.55rem 0.75rem; font-size: 0.85rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg-user { align-self: flex-end; background: var(--accent-soft); border: 1px solid var(--accent-dim); }
.msg-assistant { align-self: flex-start; background: var(--bg-panel); border: 1px solid var(--border-soft); }
.msg-tool { align-self: flex-start; background: transparent; border: 1px dashed var(--border); color: var(--text-dim); font-size: 0.76rem; padding: 0.35rem 0.65rem; }
.msg-tool::before { content: '$ '; color: var(--text-faint); }
.msg-status { align-self: center; color: var(--text-faint); font-size: 0.76rem; }
.msg-error { align-self: flex-start; background: rgba(239,107,122,0.08); border: 1px solid var(--red); color: var(--red); }

.chat-input-row { display: flex; align-items: flex-end; gap: 0.5rem; padding: 0.7rem 0.9rem; border-top: 1px solid var(--border-soft); }
.prompt-caret { color: var(--accent); font-size: 1rem; padding-bottom: 0.55rem; }
.chat-input-row textarea { flex: 1; resize: none; max-height: 8rem; background: var(--bg-input); }
.chat-input-row button { background: var(--accent-dim); border: 1px solid var(--accent); color: #e4defe; border-radius: var(--radius-sm); padding: 0 1rem; min-height: 40px; font-weight: 600; font-size: 0.82rem; }
.chat-input-row button:disabled { opacity: 0.5; }

.diff-panel { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm); margin: 0 0.9rem 0.7rem; overflow: hidden; }
.diff-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border-soft); font-size: 0.78rem; color: var(--text-dim); }
.diff-content { margin: 0; padding: 0.75rem; font-size: 0.76rem; line-height: 1.5; overflow-x: auto; max-height: 300px; }
.diff-actions { display: flex; gap: 0.5rem; padding: 0.65rem 0.75rem; flex-wrap: wrap; }

/* --- Modals / overlays --- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 40; }
.modal-box { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px 10px 0 0; width: 100%; max-width: 460px; padding: 1.1rem; max-height: 88vh; overflow-y: auto; }
.modal-box-wide { max-width: 560px; }
.modal-box h2 { font-size: 0.95rem; margin: 0 0 0.75rem; font-weight: 600; }
.modal-box-header { display: flex; justify-content: space-between; align-items: center; }
.modal-box form { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 0.5rem; }
.modal-box label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.78rem; color: var(--text-dim); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; }

.project-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.project-card {
  display: flex; flex-direction: column; gap: 0.2rem;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem; text-align: left; min-height: 44px; width: 100%;
}
.project-card:hover { border-color: var(--text-faint); }
.project-card-pinned { border-style: dashed; border-color: var(--accent-dim); }
.project-card .pc-name { font-weight: 600; font-size: 0.85rem; }
.project-card .pc-meta { font-size: 0.76rem; color: var(--text-dim); display: flex; gap: 0.55rem; align-items: center; flex-wrap: wrap; }

.status-badge { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.7rem; padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); }
.status-badge.offline { color: var(--amber); border-color: var(--amber); }

/* --- Usage popover --- */
.usage-popover {
  position: fixed; bottom: 3.5rem; left: 0.75rem; z-index: 45;
  width: min(300px, calc(100vw - 1.5rem));
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.usage-popover-header { display: flex; justify-content: space-between; align-items: center; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border-soft); font-size: 0.8rem; font-weight: 600; }
.usage-popover-body { padding: 0.8rem; display: flex; flex-direction: column; gap: 0.8rem; font-size: 0.8rem; }
.usage-row { display: flex; flex-direction: column; gap: 0.3rem; }
.usage-row-label { display: flex; justify-content: space-between; color: var(--text-dim); font-size: 0.74rem; }
.usage-bar { height: 5px; border-radius: 3px; background: var(--bg-input); overflow: hidden; }
.usage-bar-fill { height: 100%; background: var(--accent); }
.usage-bar-fill.high { background: var(--amber); }
.usage-bar-fill.critical { background: var(--red); }

/* --- Mobile (default) vs desktop --- */
@media (max-width: 899px) {
  .usage-popover { left: 0.75rem; right: 0.75rem; width: auto; bottom: auto; top: 3.5rem; }
}

@media (min-width: 900px) {
  .sidebar { position: static; transform: none; }
  .sidebar-backdrop { display: none !important; }
  .sidebar-toggle { display: none; }
  .modal { align-items: center; }
  .modal-box { border-radius: 10px; }
}
