:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0d1014;
  color: #eef2f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  background: #0d1014;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid #384252;
  border-radius: 6px;
  background: #202833;
  color: #f5f7fa;
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
}

button:hover {
  background: #2b3543;
}

button.active,
button[aria-pressed="true"] {
  border-color: #72a7ff;
  background: #17375f;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  min-width: 0;
  border: 1px solid #333d4b;
  border-radius: 6px;
  background: #111820;
  color: #f5f7fa;
  min-height: 36px;
  padding: 0 10px;
}

.sidebar {
  min-width: 0;
  border-right: 1px solid #252d39;
  background: #11161d;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.mobile-only {
  display: none;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.session-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.session-picker {
  display: grid;
  grid-template-columns: auto minmax(180px, 280px);
  gap: 8px;
  align-items: center;
  color: #a8b3c3;
  font-size: 13px;
  min-width: 0;
}

.session-picker select {
  min-height: 36px;
  max-width: 280px;
}

.new-session {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: min(300px, 34vw);
}

.window-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow: auto;
  padding-right: 2px;
}

.window-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 5px;
  align-items: stretch;
}

.window-button {
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  min-height: 44px;
}

.window-row.active .window-button {
  border-color: #5b9dff;
  background: #18304f;
}

.window-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
  line-height: 1.15;
}

.window-meta,
.sidebar-empty {
  display: block;
  margin-top: 3px;
  color: #a8b3c3;
  font-size: 12px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-button {
  min-width: 32px;
  min-height: 32px;
  align-self: center;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

.workspace {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.toolbar {
  min-height: 64px;
  border-bottom: 1px solid #252d39;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: #131922;
}

.label {
  color: #94a0b2;
  font-size: 12px;
}

.terminal-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.terminal-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 10px;
  background: #05070a;
}

#terminal {
  width: 100%;
  height: 100%;
  min-height: 0;
  contain: strict;
}

#terminal .xterm-viewport {
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

#terminal .xterm-screen {
  touch-action: pan-y;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #8e98a8;
  background: #070a0e;
  z-index: 2;
}

.empty-state.hidden {
  display: none;
}

#dropOverlay {
  position: absolute;
  inset: 10px;
  display: none;
  place-items: center;
  border: 2px dashed #6aa4ff;
  background: rgba(8, 24, 42, 0.88);
  color: #f4f8ff;
  font-weight: 700;
  z-index: 5;
}

.terminal-shell.dragging #dropOverlay {
  display: grid;
}

.status-bar {
  min-height: 30px;
  border-top: 1px solid #252d39;
  padding: 6px 12px;
  color: #aab5c3;
  background: #11161d;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pwa-notice {
  position: fixed;
  right: 12px;
  bottom: 40px;
  z-index: 30;
  border: 1px solid #5b6a80;
  border-radius: 8px;
  background: #172232;
  color: #f5f7fa;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(360px, calc(100vw - 24px));
  padding: 7px 8px 7px 10px;
  font-size: 12px;
  line-height: 1.25;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.pwa-notice.hidden {
  display: none;
}

.pwa-notice button {
  flex: 0 0 auto;
  min-width: 26px;
  min-height: 26px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 7, 10, 0.62);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(1100px, calc(100vw - 32px));
  height: min(820px, calc(100vh - 32px));
  border: 1px solid #303947;
  border-radius: 8px;
  background: #121820;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

#autosaveStatus {
  color: #a8b3c3;
  font-size: 13px;
}

.modal-header {
  border-bottom: 1px solid #252d39;
}

.modal-header h2 {
  margin: 2px 0 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.icon-button {
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.note-editor-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

#notesText {
  width: 100%;
  height: 100%;
  resize: vertical;
  min-height: 0;
  border: 1px solid #333d4b;
  border-radius: 6px;
  background: #0b1118;
  color: #f5f7fa;
  padding: 10px;
  font: inherit;
}

.notion-picker {
  display: grid;
  gap: 6px;
}

.notion-picker label {
  display: grid;
  gap: 5px;
  color: #a8b3c3;
  font-size: 13px;
}

#notionPageSelect {
  width: 100%;
}

@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #252d39;
    gap: 8px;
    padding: 8px 10px;
    max-height: none;
    min-height: 0;
  }

  .brand {
    min-height: 34px;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .brand h1 {
    font-size: 15px;
  }

  .brand button,
  .note-button {
    min-height: 30px;
  }

  .window-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(150px, 44vw);
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 4px;
    scrollbar-width: thin;
  }

  .window-row {
    grid-template-columns: minmax(0, 1fr) 30px;
  }

  .window-button {
    min-height: 38px;
    padding: 6px 8px;
  }

  .window-name {
    font-size: 13px;
  }

  .window-meta,
  .sidebar-empty {
    font-size: 11px;
    margin-top: 2px;
  }

  .workspace {
    min-height: 0;
    height: 100%;
  }

  .toolbar {
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding: 8px 10px;
  }

  .terminal-controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .session-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .session-picker {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .session-picker span {
    display: none;
  }

  .session-picker select,
  .new-session {
    max-width: none;
    width: 100%;
  }

  .new-session {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) 74px;
  }

  #renameSessionButton {
    grid-column: 2;
    grid-row: 1;
    width: 86px;
    padding: 0 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  button,
  input,
  select {
    min-height: 34px;
    font-size: 13px;
  }

  button {
    padding: 0 8px;
  }

  .terminal-shell {
    padding: 6px;
  }

  #terminal {
    height: 100%;
  }

  #dropOverlay {
    inset: 6px;
    text-align: center;
    padding: 12px;
  }

  .status-bar {
    min-height: 28px;
    padding: 6px 10px;
  }

  .pwa-notice {
    left: 8px;
    right: 8px;
    bottom: 34px;
    max-width: none;
    padding: 6px 7px 6px 9px;
    font-size: 11px;
  }

  .mobile-panel-collapsed {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mobile-panel-collapsed .sidebar {
    padding-bottom: 8px;
  }

  .mobile-panel-collapsed .window-list,
  .mobile-panel-collapsed .toolbar .session-controls {
    display: none;
  }

  .mobile-panel-collapsed .toolbar {
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .modal {
    padding: 0;
    place-items: stretch;
  }

  .modal-panel {
    width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .modal-header,
  .modal-actions,
  .note-editor-panel {
    padding: 10px;
  }
}

@media (max-width: 430px) {
  .window-list {
    grid-auto-columns: minmax(132px, 58vw);
  }

  .terminal-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #selectModeButton,
  #copySelectedButton,
  #uploadButton {
    font-size: 12px;
  }

  .new-session {
    grid-template-columns: minmax(0, 1fr) 66px;
  }

  #renameSessionButton {
    width: 88px;
  }
}
