:root {
  --terminal-font-size: 14px;
  --terminal-line-height: 1.16;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b100d;
  color: #e2eadf;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; touch-action: manipulation; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
.hidden { display: none !important; }
.muted { color: #829187; }
.eyebrow { margin: 0 0 6px; color: #70d49a; font: 700 11px/1.2 ui-monospace, monospace; letter-spacing: .16em; }
.error { min-height: 20px; margin: 0; color: #ff938e; font-size: 13px; }

.login-view {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 18% 10%, #1d3a2a 0, transparent 38%), #0b100d;
}
.panel, dialog { border: 1px solid #2a3a30; background: rgba(18, 26, 21, .96); box-shadow: 0 24px 80px #0008; }
.login-card { width: min(430px, 100%); padding: 36px; border-radius: 18px; }
.login-card h1, .dialog-form h2 { margin: 0 0 8px; }
label { display: grid; gap: 7px; color: #b6c2b9; font-size: 13px; }
input, select { width: 100%; border: 1px solid #35473b; border-radius: 9px; outline: 0; background: #0b110d; color: #eff7ed; padding: 11px 12px; }
input:focus, select:focus { border-color: #70d49a; box-shadow: 0 0 0 3px #70d49a22; }
.login-card label { margin: 24px 0 10px; }

.primary, .secondary, .danger, .text-button, .icon-button {
  border: 0;
  border-radius: 8px;
  color: inherit;
  padding: 9px 13px;
}
.primary { background: #80e7aa; color: #07120b; font-weight: 750; }
.primary:hover { background: #a4f6c3; }
.secondary { border: 1px solid #3a4c40; background: #1b261f; }
.danger { border: 1px solid #6c3837; background: #311c1b; color: #ffaaa6; }
.text-button, .icon-button { background: transparent; color: #a8b6ac; }
.icon-button { min-width: 34px; padding: 7px; font-size: 18px; }
.full-width { width: 100%; }

.app-shell { display: grid; grid-template-columns: 310px minmax(0, 1fr); width: 100%; height: 100%; height: 100dvh; }
.app-shell.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
.app-shell.sidebar-collapsed .sidebar { display: none; }
.sidebar { display: flex; min-height: 0; flex-direction: column; gap: 16px; border-right: 1px solid #253128; background: #101612; padding: 20px; }
.brand, .section-heading, .terminal-toolbar, .terminal-actions, .dialog-form header, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand h1 { margin: 0; font-size: 20px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #7ce8a8; box-shadow: 0 0 14px #7ce8a8; }
.section-heading { margin-top: 5px; color: #829187; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.session-list { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 8px; overflow: auto; }
.sidebar-mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; border: 1px solid #2b3930; border-radius: 10px; background: #0c120e; }
.sidebar-mode-switch button { border: 0; background: transparent; color: #91a397; padding: 8px; }
.sidebar-mode-switch button.active { background: #25362a; color: #eff7f0; box-shadow: 0 1px 4px #0008; }
.sidebar-panel { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 12px; }
.file-tree { min-height: 0; flex: 1; overflow: auto; font-family: "SFMono-Regular", "Cascadia Code", monospace; font-size: 12px; }
.file-tree-children { margin-left: 14px; border-left: 1px solid #26342a; padding-left: 4px; }
.file-tree-row { display: flex; width: 100%; align-items: center; gap: 6px; border: 0; border-radius: 5px; background: transparent; color: #cdd8cf; padding: 5px 6px; text-align: left; }
.file-tree-row:hover, .file-tree-row.active { background: #243329; color: #fff; }
.file-tree-row .tree-icon { width: 14px; color: #8da493; text-align: center; }
.file-view { height: 100%; overflow: auto; background: #0d130f; padding: 22px; }
.file-view-header { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid #28352c; padding-bottom: 14px; }
.file-view-header h2 { margin: 2px 0 4px; overflow-wrap: anywhere; }
.file-meta { display: flex; flex-wrap: wrap; gap: 10px 24px; margin: 14px 0; color: #9cad9f; font-size: 12px; }
.file-meta div { display: flex; gap: 6px; }.file-meta dt { color: #6f8274; }.file-meta dd { margin: 0; }
.file-content { min-height: calc(100% - 130px); margin: 0; overflow: auto; border: 1px solid #26342a; border-radius: 8px; background: #101713; color: #dce7de; padding: 16px; font-family: "SFMono-Regular", "Cascadia Code", monospace; font-size: 13px; line-height: 1.5; tab-size: 2; white-space: pre; }
.session-card { position: relative; display: grid; gap: 5px; width: 100%; border: 1px solid transparent; border-radius: 11px; background: #151e18; color: inherit; padding: 13px 52px 13px 13px; text-align: left; }
.session-card:hover, .session-card.active { border-color: #3b5946; background: #1a2720; }
.session-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.session-card span { overflow: hidden; color: #76847a; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.session-card i { position: absolute; top: 13px; right: 10px; border-radius: 999px; padding: 3px 6px; font-size: 9px; font-style: normal; }
.session-card i.live { background: #214d33; color: #9af0b8; }
.session-card i.ended { background: #2a2e2b; color: #879089; }
.list-empty { padding: 16px 4px; text-align: center; }
.sidebar footer { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; font-size: 11px; }
.display-mode-switch { display: grid; grid-column: 1 / -1; grid-template-columns: 1fr 1fr; gap: 3px; border: 1px solid #304137; border-radius: 10px; background: #0b110d; padding: 3px; }
.display-mode-switch button { border: 0; border-radius: 7px; background: transparent; color: #829187; padding: 7px 10px; }
.display-mode-switch button.is-active { background: #294536; color: #b8f5cf; box-shadow: 0 1px 5px #0006; }
.logout-button { color: #d59b98; }

.workspace { position: relative; min-width: 0; min-height: 0; background: #0c120e; }
.sidebar-expand { position: absolute; z-index: 5; top: 12px; left: 10px; border: 1px solid #35473b; background: #17221b; }
.empty-state { display: grid; height: 100%; place-content: center; padding: 30px; text-align: center; }
.empty-state h2 { margin: 0 0 10px; }
.empty-state p:last-child { max-width: 520px; color: #829187; }
.multi-session-view { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100%; min-width: 0; min-height: 0; }
.session-tabs { display: flex; min-width: 0; gap: 5px; overflow-x: auto; border-bottom: 1px solid #263229; background: #0e1510; padding: 6px 8px; scrollbar-width: none; }
.session-tabs::-webkit-scrollbar { display: none; }
.session-tab { min-width: 120px; max-width: 240px; flex: 0 0 auto; overflow: hidden; border: 1px solid transparent; border-radius: 8px; background: transparent; color: #91a097; padding: 7px 14px; text-overflow: ellipsis; white-space: nowrap; }
.session-tab:hover { border-color: #35473b; background: #17221b; color: #dce8df; }
.session-tab.active { border-color: #477158; background: #203328; color: #a9f1c4; }
.session-tab.waiting-for-input { border-color: #6fe49b; background: #1d4a30; color: #c5ffda; animation: session-tab-awaiting 1.25s ease-in-out infinite; box-shadow: 0 0 0 2px #65e99a22; }
@keyframes session-tab-awaiting { 50% { border-color: #b4ffd0; background: #2d7049; box-shadow: 0 0 14px #65e99a88; } }
@media (prefers-reduced-motion: reduce) { .session-tab.waiting-for-input { animation: none; } }
.session-panes { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; min-height: 0; overflow: hidden; }
.terminal-view { position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; height: 100%; overscroll-behavior-x: none; }
.embedded-session .app-shell { grid-template-columns: minmax(0, 1fr); }
.embedded-session .sidebar, .embedded-session .sidebar-expand { display: none !important; }
.embedded-session .session-tabs { display: none !important; }
.embedded-session .multi-session-view { grid-template-rows: minmax(0, 1fr); }
.terminal-toolbar { min-height: 65px; border-bottom: 1px solid #263229; background: #111813; padding: 10px 16px; }
.context-meter {
  --context-used: 0%;
  position: relative;
  min-width: 180px;
  max-width: 560px;
  height: 30px;
  flex: 1 1 360px;
  overflow: hidden;
  border: 1px solid #34453a;
  border-radius: 999px;
  background: #0a100c;
  box-shadow: inset 0 1px 4px #0008;
}
.context-meter-fill { width: var(--context-used); height: 100%; background: #49c87d; transition: width .35s ease, background-color .2s ease; }
.context-meter.attention .context-meter-fill { background: #d4b84c; }
.context-meter.warning .context-meter-fill { background: #e68a3f; }
.context-meter.critical .context-meter-fill { background: #e05252; }
.context-meter-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #f5faf6;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .01em;
  text-shadow: 0 1px 3px #000, 0 0 5px #000;
  white-space: nowrap;
}
.terminal-actions { min-width: 0; overflow-x: auto; scrollbar-width: none; }
.terminal-actions::-webkit-scrollbar { display: none; }
.terminal-actions button { flex: 0 0 auto; white-space: nowrap; }
.toolbar-icon-button { display: inline-grid; width: 38px; height: 38px; place-items: center; padding: 8px; }
.toolbar-icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar-icon-button { position: relative; }
.toolbar-icon-button .speech-disabled-mark { stroke: #e76567; }
.toolbar-icon-button.auto-speech-enabled .speech-disabled-mark,
.toolbar-icon-button:not(.auto-speech-enabled) .speech-enabled-waves { display: none; }
.toolbar-icon-button.auto-speech-enabled { border-color: #6fe49b; background: #1d4a30; color: #c5ffda; box-shadow: 0 0 0 2px #65e99a22; }
.control-state { color: #829187; font-size: 11px; }
.control-state.owned { color: #8feab2; }
.terminal-surface { position: relative; grid-row: 2; min-width: 0; min-height: 0; overflow-x: hidden; overscroll-behavior-x: none; touch-action: pan-y; background: #101713; }
.terminal-container { width: 100%; height: 100%; min-width: 0; min-height: 0; overscroll-behavior-x: none; touch-action: pan-y; background: #101713; padding: 10px 8px 8px 12px; }
.terminal-container .xterm { height: 100%; }
.terminal-scrollback { position: absolute; z-index: 2; inset: 0; min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; background: #101713; padding: 10px 8px 8px 12px; }
.terminal-scrollback .xterm, .history-content .xterm { height: 100%; }
.terminal-scrollback .xterm-viewport, .history-content .xterm-viewport { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.touch-input { display: block; border-top: 1px solid #263229; background: #111813; padding: 7px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
.touch-key-row, .touch-composer-row { display: flex; align-items: center; gap: 7px; }
.touch-key-row { margin-bottom: 7px; }
.composer-attachment-preview { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; border: 1px solid #dde2de; border-radius: 14px; background: #f7f8f6; padding: 8px 10px; color: #555a55; font-size: 13px; }
.composer-attachment-preview.hidden { display: none; }
.composer-attachment-preview img { width: 54px; height: 54px; flex: 0 0 auto; border-radius: 9px; object-fit: cover; }
.composer-attachment-preview span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-attachment-preview button { width: 32px; height: 32px; flex: 0 0 auto; border: 0; border-radius: 50%; background: #e8ebe7; color: #626762; padding: 0; font-size: 18px; }
.touch-key-row button { min-width: 58px; padding: 6px 9px; font-size: 12px; }
.touch-composer-row textarea { min-width: 0; min-height: 42px; max-height: 112px; flex: 1; resize: vertical; border: 1px solid #35473b; border-radius: 9px; outline: 0; background: #0b110d; color: #eff7ed; padding: 10px 11px; }
.touch-composer-row textarea:focus { border-color: #70d49a; box-shadow: 0 0 0 3px #70d49a22; }
.touch-composer-row button { align-self: stretch; }
.touch-composer-row .composer-action {
  width: 52px;
  min-width: 52px;
  flex: 0 0 52px;
  border-width: 1px;
  border-style: solid;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}
.touch-composer-row .composer-action.primary { border-color: transparent; }
.touch-composer-row .composer-action svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.attachment-upload { display: inline-flex; align-self: stretch; align-items: center; justify-content: center; cursor: pointer; }
.attachment-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.history-view { position: absolute; z-index: 4; inset: 65px 0 0; display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; max-width: 100%; overflow-x: hidden; overscroll-behavior-x: none; touch-action: pan-y; background: #101713; }
.todo-view { z-index: 3; display: grid; grid-row: 2; grid-template-rows: auto minmax(72px, 1fr) auto; min-width: 0; min-height: 0; overflow: hidden; border-top: 1px solid #2a3a30; background: #101713; }
.todo-view > header { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #2a3a30; padding: 12px 16px; }
.todo-view > header div { display: grid; gap: 3px; }
.todo-view > header small { color: #829187; font-weight: 400; }
#todo-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; border-top: 1px solid #263229; padding: 12px; }
#todo-form .todo-attachment-preview { grid-column: 1 / -1; margin: 0; }
#todo-form textarea { min-width: 0; min-height: 44px; max-height: 72px; resize: vertical; }
.todo-list { display: flex; flex-direction: column; gap: 9px; overflow: auto; padding: 12px; }
.todo-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: start; gap: 8px; border: 1px solid #304137; border-radius: 11px; background: #151e18; padding: 11px; }
.todo-item p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.todo-empty { color: #829187; text-align: center; }
.todo-composer-button { position: relative; align-self: stretch; }
.todo-count { position: absolute; top: -5px; right: -5px; min-width: 17px; border-radius: 999px; background: #80e7aa; color: #07120b; padding: 1px 4px; font-size: 10px; font-weight: 800; }
.history-view header { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #2a3a30; padding: 9px 14px; }
.history-content { width: 100%; min-width: 0; max-width: 100%; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior-x: none; overscroll-behavior-y: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; background: #101713; padding: 10px 8px 8px 12px; }
.native-history-source { position: absolute !important; inset: 0; visibility: hidden; pointer-events: none; }
.native-terminal-history { width: 100%; min-width: 0; max-width: 100%; overflow-wrap: anywhere; color: #e2eadf; font-family: "SFMono-Regular", "Cascadia Code", "Noto Sans Mono CJK SC", monospace; font-size: var(--terminal-font-size); font-kerning: none; font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; line-height: var(--terminal-line-height); -webkit-font-smoothing: antialiased; }
.native-terminal-line { min-height: var(--native-terminal-row-height, calc(var(--terminal-font-size) * var(--terminal-line-height))); white-space: pre-wrap; overflow-wrap: anywhere; }
.native-terminal-wide-cell { display: inline-block; width: calc(var(--native-terminal-cell-width) * 2); overflow: visible; vertical-align: top; }
.scrollback-live-button { position: sticky; z-index: 3; top: max(0px, env(safe-area-inset-top)); float: right; width: 38px; height: 38px; margin: 0 0 8px 8px; border: 1px solid #3b5143; border-radius: 9px; background: #18231cee; color: #dfe9dc; padding: 8px; }
.scrollback-live-button svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.connection-banner { position: fixed; z-index: 20; top: 50%; left: 50%; width: max-content; max-width: min(430px, calc(100% - 32px)); transform: translate(-50%, -50%); border: 1px solid #5a4430; border-radius: 12px; background: #2a2118ee; color: #ffd0a0; padding: 11px 15px; box-shadow: 0 12px 35px #0008; font-size: 13px; text-align: center; pointer-events: none; animation: toast-visible 4s ease both; }
@keyframes toast-visible { 0% { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); } 10%, 72% { opacity: 1; transform: translate(-50%, -50%); } 100% { opacity: 0; transform: translate(-50%, calc(-50% - 6px)); } }
@media (prefers-reduced-motion: reduce) { .connection-banner { animation: none; } }
.mobile-only { display: none; }
.desktop-only { display: inline-flex; }

dialog { width: min(520px, calc(100% - 28px)); border-radius: 16px; color: inherit; padding: 0; }
dialog::backdrop { background: #020503bb; backdrop-filter: blur(5px); }
.dialog-form { display: grid; gap: 18px; padding: 24px; }
.checkbox-label { display: flex; align-items: center; gap: 9px; }
.checkbox-label input { width: auto; }
.dialog-actions { justify-content: flex-end; }
.dialog-hint { margin: -8px 0 0; font-size: 12px; line-height: 1.5; }
.notification-options { display: grid; gap: 9px; }
.notification-options label { display: flex; align-items: center; gap: 12px; border: 1px solid #304137; border-radius: 12px; background: #121b16; padding: 13px; cursor: pointer; }
.notification-options label:has(input:checked) { border-color: #70d49a; background: #19291f; }
.notification-options input { width: auto; accent-color: #70d49a; }
.notification-options span { display: grid; gap: 3px; }
.notification-options small { color: #829187; }

@media (max-width: 760px) {
  :root { --terminal-font-size: 12px; }
  .app-shell { display: block; }
  .sidebar { width: 100%; height: 100%; border: 0; }
  .workspace { display: none; width: 100%; height: 100%; }
  .app-shell.terminal-open .sidebar { display: none; }
  .app-shell.terminal-open .workspace { display: block; }
  .app-shell.file-open .sidebar { display: none; }
  .app-shell.file-open .workspace { display: block; }
  .file-view { padding: max(14px, env(safe-area-inset-top)) 10px 10px; }
  .embedded-session .workspace { display: block; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
  .terminal-toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-height: 0; padding: max(9px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left)); }
  .context-meter { width: 100%; min-width: 0; max-width: none; height: 26px; }
  .context-meter-label { overflow: hidden; padding: 0 8px; text-overflow: ellipsis; }
  .terminal-actions { width: 100%; justify-content: flex-start; gap: 5px; }
  .terminal-actions button { padding: 7px 8px; font-size: 11px; }
  .terminal-actions .toolbar-icon-button { width: 36px; height: 36px; padding: 7px; }
  .control-state { display: none; }
  .terminal-container { padding: 7px 3px 5px 7px; }
  .history-view { position: relative; grid-row: 2 / 4; inset: auto; }
  #todo-form { grid-template-columns: minmax(0, 1fr) auto; padding: 8px; }
}

@media (min-width: 1400px) {
  .session-panes { grid-template-columns: minmax(0, 1fr); }
}

@media (min-width: 2200px) {
  .session-panes { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 479px) {
  .touch-composer-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }
  .touch-composer-row textarea { grid-column: 1 / -1; }
  .touch-composer-row .composer-action {
    width: auto;
    min-width: 0;
    min-height: 40px;
    flex: none;
  }
}

@media (min-width: 480px) and (max-width: 620px) {
  .terminal-toolbar {
    gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) 6px 6px;
  }
  .terminal-actions { gap: 4px; }
  .terminal-actions button { padding: 5px 7px; font-size: 10px; }
  .terminal-actions .toolbar-icon-button { width: 32px; height: 32px; padding: 6px; }
  .touch-input {
    display: block;
    padding: 5px max(6px, env(safe-area-inset-right)) max(5px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }
  .touch-key-row, .touch-composer-row { min-width: 0; gap: 4px; }
  .touch-key-row { margin-bottom: 5px; }
  .touch-key-row button { min-width: 0; padding: 6px; font-size: 11px; }
  .touch-composer-row textarea {
    min-height: 36px;
    max-height: 72px;
    padding: 7px 8px;
  }
  .touch-composer-row .composer-action {
    width: 44px;
    min-width: 44px;
    flex-basis: 44px;
    padding: 0;
    font-size: 11px;
  }
}
