* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
button { min-height: 36px; padding: 8px 13px; color: var(--text); background: var(--button); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; transition: background-color .15s, border-color .15s; }
button:hover { background: var(--button-hover); }
button:disabled { opacity: .55; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, .machine:focus-visible, .session-row:focus-visible, .log-row:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input, select, textarea { min-height: 38px; padding: 8px 10px; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 8px; }
input::placeholder { color: var(--subtle); opacity: 1; }
textarea { min-height: 100px; resize: vertical; }
label { display: block; color: var(--muted); font-size: 12px; font-weight: 550; }
label input, label select, label textarea { display: block; width: 100%; margin-top: 6px; font-size: 14px; font-weight: 400; }
p { line-height: 1.55; }
a { color: var(--accent); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.primary { color: var(--on-primary); background: var(--primary); border-color: var(--primary); font-weight: 600; }
.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.danger { color: var(--danger); background: transparent; border-color: var(--danger); }
.danger:hover { background: var(--danger-soft); }
.error { color: var(--danger) !important; }
.icon { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; padding: 8px; }
.icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.text-button { background: transparent; border: 0; font-size: 22px; line-height: 1; min-width: 36px; padding: 5px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 500; color: var(--text); }
.check input, input[type="checkbox"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--primary); margin: 0; flex: none; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; }
.toggle input[type="checkbox"] { order: 2; display: inline-block; width: 38px; height: 22px; margin: 0; appearance: none; border: 1px solid var(--line); border-radius: 20px; background: radial-gradient(circle at 10px 50%, var(--muted) 0 7px, transparent 8px), var(--button); cursor: pointer; }
.toggle input[type="checkbox"]:checked { background: radial-gradient(circle at 27px 50%, var(--on-primary) 0 7px, transparent 8px), var(--primary); border-color: var(--primary); }
.toggle input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.workspace { display: grid; grid-template-columns: 250px 238px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 32px; height: 100dvh; min-width: 740px; }
.workspace.no-sessions { grid-template-columns: 250px minmax(0, 1fr); }
.workspace.no-sessions .sessions-pane { display: none; }
.machines-pane, .sessions-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.machines-pane { padding: 24px 14px 14px; background: var(--panel); }
.sessions-pane { padding: 26px 12px 14px; background: var(--pane); }
.brand { display: flex; align-items: center; gap: 11px; margin: 0 5px 24px; }
.brand img { width: 42px; height: 42px; border-radius: 10px; }
.brand strong { font-size: 21px; font-weight: 700; letter-spacing: -.03em; }
.icon-row { display: flex; gap: 7px; }
.icon-row .icon { flex: 1; }
.search-label { margin-top: 23px; }
.search-label input { width: 100%; }
.eyebrow, .sessions-pane h2 { margin: 22px 8px 9px; color: var(--subtle); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sessions-pane h2 { margin: 0 7px 17px; }
.scroll { overflow: auto; min-height: 0; scrollbar-color: var(--line) transparent; }
.list { flex: 1; }
.machine, .session-row { padding: 10px 11px; margin: 3px 0; border: 1px solid transparent; border-radius: 8px; cursor: pointer; overflow: hidden; }
.machine:hover, .session-row:hover { background: var(--button); }
.machine.selected, .session-row.selected { background: var(--selected); border-color: var(--accent); }
.machine strong, .session-row strong { display: block; font-size: 13px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.machine small, .session-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.machine .connected-dot { display: inline-block; width: 7px; height: 7px; margin: 0 7px 1px 0; background: var(--accent); border-radius: 50%; }
.machine.dragging { display: none; }
.machine-placeholder { padding: 10px 11px; margin: 3px 0; color: var(--text); background: var(--accent-soft); border: 2px solid var(--accent); border-radius: 8px; font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main-pane { min-width: 0; min-height: 0; padding: 18px; background: var(--bg); }
.welcome { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; height: 100%; max-width: 600px; margin: auto; padding: clamp(24px, 6vw, 76px); }
.welcome h1 { margin: 0 0 8px; font-size: clamp(27px, 3vw, 36px); line-height: 1.2; letter-spacing: -.035em; }
.welcome p { max-width: 430px; margin: 0; color: var(--muted); font-size: 14px; }
.welcome button { margin-top: 26px; }
.session-view { display: flex; flex-direction: column; gap: 10px; height: 100%; }
.agent-strip { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--accent-soft); border: 1px solid var(--line); border-radius: 8px; }
.agent-strip .actions { display: flex; gap: 6px; margin: 0; }
.agent-strip button { min-height: 32px; padding: 5px 9px; }
.terminal-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 2px; }
.terminal-top > div:first-child { min-width: 0; }
.terminal-top strong { display: block; font-size: 15px; }
.terminal-top span { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar { display: flex; gap: 7px; }
.terminal-and-files { display: flex; flex: 1; min-height: 0; gap: 10px; }
#terminal { flex: 1; min-width: 0; padding: 4px 6px; overflow: hidden; background: var(--terminal-bg); border: 1px solid var(--line); border-radius: 10px; }
.files-pane { display: flex; flex-direction: column; width: 330px; min-width: 0; gap: 9px; padding: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.files-head, .path-row, .file-actions { display: flex; align-items: center; gap: 7px; }
.files-head { justify-content: space-between; }
.path-row input { flex: 1; min-width: 0; }
.file-actions { flex-wrap: wrap; }
.file-actions button { min-height: 30px; padding: 5px 8px; font-size: 11px; }
#files-list { flex: 1; }
.file-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px; border-radius: 7px; cursor: pointer; }
.file-row:hover, .file-row.selected { background: var(--selected); }
.file-row small { color: var(--muted); }
#status { grid-column: 1 / -1; display: flex; align-items: center; padding: 0 15px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 18px; background: #07120fba; }
.modal { width: min(940px, 100%); max-height: min(90dvh, 900px); padding: 26px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.modal.narrow { width: min(550px, 100%); }
.modal h2 { margin: 0; font-size: 22px; letter-spacing: -.025em; }
.modal h3 { font-size: 14px; margin: 22px 0 8px; }
.modal p { color: var(--muted); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.modal-header p { margin: 4px 0 0; font-size: 13px; }
.modal-tabs { display: flex; gap: 6px; margin: 0 0 18px; padding-bottom: 8px; border-bottom: 1px solid var(--line); overflow-x: auto; white-space: nowrap; }
.modal-tabs button { flex: none; min-height: 34px; padding: 6px 12px; background: transparent; border-color: transparent; }
.modal-tabs button:hover { background: var(--button); }
.modal-tabs button.active { color: var(--accent); background: var(--accent-soft); font-weight: 650; }
.settings-layout { display: grid; grid-template-columns: 178px minmax(0, 1fr); gap: 24px; }
.settings-nav { display: flex; flex-direction: column; gap: 4px; padding-right: 14px; border-right: 1px solid var(--line); }
.settings-nav button { width: 100%; min-height: 38px; text-align: left; background: transparent; border-color: transparent; }
.settings-nav button:hover { background: var(--button); }
.settings-nav button.active { color: var(--accent); background: var(--accent-soft); font-weight: 650; }
#settings-content { min-width: 0; }
#settings-content > p:first-child { margin-top: 0; }
.settings-heading { margin: 1px 0 13px !important; font-size: 15px !important; }
.theme-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.theme-options button { min-height: 100px; padding: 14px; text-align: left; background: var(--pane); }
.theme-options button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.theme-options strong, .theme-options small { display: block; }
.theme-options strong { font-size: 14px; }
.theme-options small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.terminal-preview-label { margin: 18px 0 7px; color: var(--muted); font-size: 12px; font-weight: 550; }
.terminal-preview { padding: 13px 15px; overflow-x: auto; color: #e8f0ec; background: #000; border: 1px solid var(--line); border-radius: 8px; line-height: 1.12; white-space: pre; }
.terminal-preview > div + div { margin-top: 5px; }
.preview-prompt { color: #8fd1aa; }
.preview-directory { color: #92b9ef; }
.preview-cursor { display: inline-block; width: .6em; height: 1.1em; background: #e8f0ec; vertical-align: -.2em; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.setting-row, .log-row, .request-row { margin: 9px 0; padding: 13px 15px; background: var(--pane); border: 1px solid var(--line); border-radius: 9px; }
.setting-row strong, .log-row strong { display: block; font-size: 13px; }
.setting-row small, .log-row small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.setting-row p { margin: 7px 0 0; }
.setting-row .actions { margin-top: 12px; justify-content: flex-start; }
.setting-row.check { display: flex; }
.log-row { cursor: pointer; }
.log-row:hover { background: var(--surface-soft); }
.request-row p { margin: 7px 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.request-row small { color: var(--muted); }
.scores { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.score { padding: 4px 8px; background: var(--button); border-radius: 6px; font-size: 11px; font-weight: 600; }
.score.low { color: var(--danger); background: var(--danger-soft); }
.score.mid { color: #e7c77e; background: #4b3d23; }
.score.high { color: var(--accent); background: var(--accent-soft); }
:root[data-theme="light"] .score.mid { color: #84560d; background: #f8edce; }
.code { max-height: 48vh; padding: 13px; overflow: auto; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 8px; font: 12px/1.5 "Hilait Mono", ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.toast { position: fixed; right: 18px; bottom: 48px; z-index: 20; max-width: min(380px, calc(100vw - 36px)); padding: 11px 15px; color: var(--text); background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 8px; box-shadow: var(--shadow); }
.context-menu { position: fixed; z-index: 30; min-width: 190px; padding: 5px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow); }
.context-menu button { display: block; width: 100%; min-height: 35px; text-align: left; background: transparent; border-color: transparent; }
.context-menu button:hover { background: var(--button); }
.setting-hint { font-size: 12px; }
.empty-message { margin: 0; padding: 18px 2px 4px; color: var(--muted); }

.login-shell { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.login-card { width: min(420px, 100%); padding: 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.login-top { display: flex; align-items: flex-start; justify-content: space-between; }
.login-top img { border-radius: 11px; }
.login-card h1 { margin: 25px 0 7px; font-size: 26px; line-height: 1.2; letter-spacing: -.03em; }
.login-card p { margin: 0 0 23px; color: var(--muted); font-size: 13px; }
.login-card button.primary { width: 100%; margin-top: 17px; }
.login-card .error { margin: 12px 0 0; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 220px 210px minmax(0, 1fr); }
  .workspace.no-sessions { grid-template-columns: 220px minmax(0, 1fr); }
  .main-pane { padding: 12px; }
  .files-pane { width: 285px; }
}
@media (max-width: 700px) {
  .modal { padding: 18px; }
  .settings-layout { display: block; }
  .settings-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 0; border-bottom: 1px solid var(--line); padding: 0 0 12px; margin-bottom: 18px; }
  .settings-nav button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: 1; }
  .theme-options { grid-template-columns: 1fr; }
  .theme-options button { min-height: 62px; }
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}
