:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --line: #2a303b;
  --text: #e3e6eb;
  --dim: #8b93a1;
  --accent: #5aa2ff;
  --accent-text: #08121f;
  --ok: #3fb67b;
  --warn: #e0a83a;
  --err: #ef6b6b;
  --add-bg: rgba(63, 182, 123, 0.14);
  --del-bg: rgba(239, 107, 107, 0.14);
  --hunk: #7f8cff;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --panel-2: #eef0f3;
    --line: #d8dce2;
    --text: #1b1f24;
    --dim: #5f6773;
    --accent: #1f6fe0;
    --accent-text: #ffffff;
    --add-bg: rgba(46, 160, 67, 0.15);
    --del-bg: rgba(220, 60, 60, 0.13);
    --hunk: #4b55c9;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 11px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  display: inline-block;
}
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--err); }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.dim { color: var(--dim); }
.small { font-size: 12.5px; }
.error { color: var(--err); min-height: 1em; margin: 6px 0 0; }
.note { color: var(--dim); }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(420px, 100%); }
.card h1, .card h2 { margin: 0 0 14px; font-size: 18px; }
.card label { display: block; margin: 10px 0; color: var(--dim); font-size: 13px; }
.card label input, .card label textarea { margin-top: 4px; color: var(--text); }
.card label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.card label.check input { width: auto; margin: 0; }
.card .primary { width: 100%; margin-top: 6px; padding: 8px; }
.card .row .primary { width: auto; margin-top: 0; padding: 5px 14px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 10px 0; padding: 8px 10px; }
legend { color: var(--dim); font-size: 13px; padding: 0 4px; }
.card label.repo-choice { display: flex; align-items: center; gap: 8px; margin: 2px 0; padding: 3px 0; color: var(--text); font-size: 14px; }
.card label.repo-choice input[type=checkbox] { width: auto; margin: 0; }
.card label.repo-choice select { margin: 0; }
.repo-choice span { flex: 1; }
.repo-choice select { width: auto; padding: 2px 6px; }
dialog { border: none; padding: 0; background: transparent; color: var(--text); max-width: calc(100vw - 24px); }
dialog .card { width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.progress { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; max-height: 260px; overflow: auto; font: 12px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; }

/* App layout */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "side main";
}
.topbar { grid-area: top; display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 600; }
.icon { padding: 2px 10px; font-size: 18px; line-height: 1; }
.only-narrow { display: none; }
.sidebar { grid-area: side; min-width: 0; overflow: auto; border-right: 1px solid var(--line); background: var(--panel); }
.sidebar .note { padding: 12px; }
.task-list { list-style: none; margin: 0; padding: 6px; }
.task-list li button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 10px 1fr auto;
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  white-space: normal;
}
.task-list li button:hover { background: var(--panel-2); border-color: transparent; }
.task-list li button[aria-current="true"] { background: var(--panel-2); border-color: var(--line); }
.task-list .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-list .meta { grid-column: 2 / 4; color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dim); }
.dot.running { background: var(--ok); }
.dot.setup { background: var(--warn); }
.dot.error { background: var(--err); }
.dot.creating { background: var(--accent); }

.task-view { grid-area: main; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.placeholder { margin: auto; color: var(--dim); }
#task-pane { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.task-head { padding: 10px 14px 6px; border-bottom: 1px solid var(--line); }
.task-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.task-title h2 { margin: 0; font-size: 17px; }
.task-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.task-head p { margin: 6px 0 0; }
.badge { font-size: 11.5px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line); color: var(--dim); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.err { color: var(--err); border-color: var(--err); }
.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; padding: 8px 12px; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Terminal */
.terminal-tab { background: #000; }
.term-bar, .files-bar { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.files-bar select { width: auto; max-width: 220px; }
.term { flex: 1; min-height: 0; padding: 4px 0 0 6px; position: relative; }
.term.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; }
.keys { display: none; gap: 4px; padding: 6px; background: var(--panel); border-top: 1px solid var(--line); overflow-x: auto; }
.keys button { flex: 1 0 auto; padding: 6px 10px; font-family: var(--mono); }

/* Files */
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; font-family: var(--mono); font-size: 12.5px; }
.crumbs button { background: none; border: none; padding: 2px 4px; color: var(--accent); }
.files-body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.files-body.dragging { outline: 2px dashed var(--accent); outline-offset: -6px; }
.file-list { list-style: none; margin: 0; padding: 4px 0; }
.file-list li button { width: 100%; text-align: left; border: none; border-radius: 0; background: transparent; padding: 5px 14px; display: flex; gap: 10px; font-family: var(--mono); font-size: 12.5px; }
.file-list li button:hover { background: var(--panel-2); }
.file-list .size { margin-left: auto; color: var(--dim); }
.file-view { display: flex; flex-direction: column; min-height: 100%; }
.file-view-bar { position: sticky; top: 0; display: flex; gap: 8px; align-items: center; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.code { margin: 0; padding: 10px 0; font: 12.5px/1.5 var(--mono); tab-size: 4; overflow: auto; }
.code .ln { display: block; padding-right: 14px; white-space: pre; }
.code .ln::before { content: attr(data-n); display: inline-block; width: 4.5em; padding-right: 1em; text-align: right; color: var(--dim); user-select: none; }
.drop-hint { padding: 0 14px 14px; }

/* Diff */
.diff { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
.diff details { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--panel); overflow: hidden; }
.diff summary { cursor: pointer; padding: 6px 10px; font-family: var(--mono); font-size: 12.5px; display: flex; gap: 10px; }
.diff summary .add { color: var(--ok); }
.diff summary .del { color: var(--err); }
.diff pre { margin: 0; font: 12px/1.45 var(--mono); overflow-x: auto; border-top: 1px solid var(--line); }
.diff .l { display: block; padding: 0 10px; white-space: pre; min-width: max-content; }
.diff .l.a { background: var(--add-bg); }
.diff .l.d { background: var(--del-bg); }
.diff .l.h { color: var(--hunk); background: var(--panel-2); }
.diff .l.m { color: var(--dim); }
.diff .empty { color: var(--dim); padding: 20px; text-align: center; }

.devices { list-style: none; margin: 0; padding: 0; }
.devices li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.devices li div { flex: 1; min-width: 0; }

/* Claude state */
.pill { font-size: 11.5px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.pill.working { color: var(--ok); border-color: var(--ok); }
.pill.shell { color: var(--accent); border-color: var(--accent); }
.pill.idle { color: var(--dim); }
.pill.waiting { color: #1b1300; background: var(--warn); border-color: var(--warn); font-weight: 600; }
.pill.attention { animation: owb-pulse 1.2s ease-in-out infinite; }
.pill.small { font-size: 11px; padding: 0 6px; }
@keyframes owb-pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .pill.attention { animation: none; outline: 2px solid var(--warn); outline-offset: 1px; } }
.sessions { list-style: none; margin: 6px 0 0; padding: 0; }
.sessions > li { margin: 3px 0; }
.sessions ul { list-style: none; margin: 2px 0 0 18px; padding: 0 0 0 10px; border-left: 1px solid var(--line); }
.sessions ul li { margin: 2px 0; }
#notify-btn[aria-pressed="true"] { border-color: var(--accent); }

/* Phone width: one panel at a time. */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .only-narrow { display: inline-block; }
  .app:not(.show-task) #back { display: none; }
  .app:not(.show-task) .task-view { display: none; }
  .app.show-task .sidebar { display: none; }
  .app:not(.show-task) .sidebar { grid-area: main; border-right: none; }
  .app.show-task #new-task-btn, .app.show-task #devices-btn { display: none; }
  .keys { display: flex; }
  .task-list .pill { font-size: 13px; padding: 3px 10px; }
  .topbar { gap: 6px; padding: 6px 8px; }
  .topbar button { padding: 4px 8px; }
  .brand { white-space: nowrap; font-size: 13px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .task-actions button, .task-actions .button { padding: 5px 9px; }
}
