:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --panel: #ffffff;
  --panel-2: #f0f2ef;
  --line: #d9ddd8;
  --line-strong: #bcc4bc;
  --text: #202420;
  --muted: #687068;
  --accent: #087f5b;
  --accent-hover: #06694b;
  --accent-soft: #dff4ea;
  --amber: #a45b00;
  --amber-soft: #fff0d5;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --blue: #2563a6;
  --shadow: 0 12px 32px rgba(26, 34, 28, .12);
  --sidebar: 292px;
  --detail: 340px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171a18;
  --panel: #1e221f;
  --panel-2: #262b27;
  --line: #343b35;
  --line-strong: #505951;
  --text: #eef1ed;
  --muted: #a3aba3;
  --accent: #4fd1a0;
  --accent-hover: #71dfb7;
  --accent-soft: #173f31;
  --amber: #f5b55c;
  --amber-soft: #46351c;
  --danger: #ff8d83;
  --danger-soft: #482522;
  --blue: #82b7f2;
  --shadow: 0 16px 40px rgba(0, 0, 0, .36);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #171a18;
    --panel: #1e221f;
    --panel-2: #262b27;
    --line: #343b35;
    --line-strong: #505951;
    --text: #eef1ed;
    --muted: #a3aba3;
    --accent: #4fd1a0;
    --accent-hover: #71dfb7;
    --accent-soft: #173f31;
    --amber: #f5b55c;
    --amber-soft: #46351c;
    --danger: #ff8d83;
    --danger-soft: #482522;
    --blue: #82b7f2;
    --shadow: 0 16px 40px rgba(0, 0, 0, .36);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.mobile-only { display: none !important; }

.login-shell { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(390px, 100%); padding: 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.login-panel h1 { margin: 16px 0 2px; font-size: 27px; }
.login-panel p { margin: 0 0 28px; }
.login-panel label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 650; }
.login-panel input { width: 100%; height: 44px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); padding: 0 12px; outline: none; }
.login-panel input:focus, textarea:focus, .search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; background: var(--accent); color: white; border-radius: 7px; font-weight: 800; font-size: 21px; }
.brand-mark.small { width: 30px; height: 30px; font-size: 15px; }
.primary, .secondary, .danger-button { height: 38px; border: 1px solid transparent; border-radius: 6px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 650; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-hover); }
.secondary { background: var(--panel-2); border-color: var(--line); }
.danger-button { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, var(--line)); }
.wide { width: 100%; margin-top: 16px; }
.form-error { min-height: 20px; margin: 10px 0 0 !important; color: var(--danger); font-size: 13px; }

.app-shell { height: 100%; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.app-shell.detail-open { grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--detail); }
.sidebar { min-width: 0; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar-header, .topbar, .detail-pane > header { height: 60px; min-height: 60px; display: flex; align-items: center; }
.sidebar-header { padding: 0 16px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 17px; }
.new-button { margin: 4px 12px 12px; height: 40px; }
.new-button svg, .danger-button svg { width: 17px; height: 17px; }
.search-box { height: 38px; margin: 0 12px 8px; border: 1px solid var(--line); border-radius: 6px; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--bg); }
.search-box svg { width: 16px; color: var(--muted); }
.search-box input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font-size: 13px; }
.sidebar-tabs { height: 40px; padding: 0 12px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.tab { height: 40px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 13px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 650; }
.sidebar-tabs .icon-button { margin-left: auto; }
.conversation-list { min-height: 0; flex: 1; overflow: auto; padding: 8px; }
.conversation-item { width: 100%; min-height: 64px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 8px; text-align: left; padding: 10px; margin-bottom: 4px; border: 1px solid transparent; border-radius: 6px; background: transparent; }
.conversation-item:hover { background: var(--panel-2); }
.conversation-item.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.conversation-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 620; }
.conversation-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.conversation-time { color: var(--muted); font-size: 11px; }
.pin-mini { width: 12px; height: 12px; color: var(--accent); }
.sidebar-footer { border-top: 1px solid var(--line); padding: 8px; }
.account-button { width: 100%; height: 50px; border: 0; border-radius: 6px; background: transparent; display: flex; align-items: center; gap: 10px; padding: 6px 8px; text-align: left; }
.account-button:hover { background: var(--panel-2); }
.account-button > svg { width: 17px; color: var(--muted); }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; background: var(--amber-soft); color: var(--amber); border-radius: 50%; font-weight: 750; }
.account-copy { min-width: 0; flex: 1; display: grid; }
.account-copy strong, .account-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: 13px; }.account-copy small { color: var(--muted); font-size: 11px; }

.main-pane { min-width: 0; display: grid; grid-template-rows: 60px minmax(0, 1fr) auto; background: var(--bg); }
.topbar { padding: 0 14px; gap: 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.title-block { min-width: 0; flex: 1; }
.title-row, .subtitle-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.title-row h2 { margin: 0; max-width: min(560px, 46vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.conversation-number, .subtitle-row { color: var(--muted); font-size: 11px; }
.workspace-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; background: var(--muted); }
.status-dot.running, .status-dot.pending { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status-dot.waiting, .status-dot.paused { background: var(--amber); }.status-dot.failed, .status-dot.cancelled { background: var(--danger); }.status-dot.completed { background: var(--blue); }
.toolbar { display: flex; align-items: center; gap: 2px; }
.toolbar-divider { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.icon-button { width: 34px; height: 34px; flex: 0 0 34px; display: inline-grid; place-items: center; border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 0; }
.icon-button:hover { background: var(--panel-2); color: var(--text); }
.danger-hover:hover { background: var(--danger-soft); color: var(--danger); }
.icon-button svg { width: 18px; height: 18px; }

.empty-state { display: grid; align-content: center; justify-items: center; gap: 12px; color: var(--muted); min-height: 0; }
.empty-state h2 { margin: 0; color: var(--text); font-size: 20px; }
.message-feed { min-height: 0; overflow: auto; padding: 26px max(18px, calc((100% - 820px) / 2)) 140px; scroll-behavior: smooth; }
.message { margin: 0 0 22px; }
.message-head { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; color: var(--muted); font-size: 11px; }
.message-head strong { color: var(--text); font-size: 12px; }
.message.user { margin-left: min(16%, 120px); }
.message.user .message-body { background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); border-radius: 8px; padding: 12px 14px; }
.message.assistant .message-body { line-height: 1.68; }
.message-body p { margin: 0 0 10px; }.message-body p:last-child { margin-bottom: 0; }
.message-body code { padding: 2px 5px; border-radius: 4px; background: var(--panel-2); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.message-body pre, .tool-block pre { margin: 10px 0; overflow: auto; background: #111713; color: #eef5ef; border-radius: 6px; padding: 13px; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
.event-row, .approval-box, .attachment-row { border-left: 2px solid var(--line-strong); margin: 12px 0; padding: 8px 0 8px 12px; font-size: 12px; }
.event-row summary { cursor: pointer; color: var(--muted); }.event-row pre { max-height: 320px; white-space: pre-wrap; overflow: auto; }
.plan-block { margin: 12px 0; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 12px; }
.plan-block ol { margin: 8px 0 0; padding-left: 22px; }.plan-block li { margin: 6px 0; }
.approval-box { border-left-color: var(--amber); background: var(--amber-soft); padding: 12px; border-radius: 0 6px 6px 0; }
.approval-actions { display: flex; gap: 8px; margin-top: 10px; }
.attachment-row { display: flex; align-items: center; gap: 9px; }.attachment-row svg { width: 17px; }.attachment-row a { color: var(--blue); text-decoration: none; }

.composer-wrap { position: relative; z-index: 2; padding: 0 max(18px, calc((100% - 820px) / 2)) 18px; background: linear-gradient(transparent, var(--bg) 24px); }
.composer { min-height: 104px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(28, 38, 30, .08); padding: 10px; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { width: 100%; max-height: 180px; resize: none; border: 0; outline: 0; background: transparent; padding: 2px 4px 8px; line-height: 1.5; }
.composer-footer, .composer-tools { display: flex; align-items: center; gap: 8px; }
.composer-footer { justify-content: space-between; }
.composer-tools { min-width: 0; }
#workspace-select { width: min(210px, 24vw); height: 32px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); padding: 0 8px; font-size: 12px; }
.segmented { display: inline-flex; height: 32px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.segmented button { min-width: 38px; border: 0; border-right: 1px solid var(--line); background: transparent; padding: 0 9px; font-size: 12px; }.segmented button:last-child { border-right: 0; }.segmented button.active { background: var(--panel); color: var(--accent); font-weight: 700; }
.segmented.full { width: 100%; }.segmented.full button { flex: 1; }
.send-button { width: 34px; height: 34px; border: 0; border-radius: 6px; background: var(--accent); color: white; display: grid; place-items: center; }.send-button:hover { background: var(--accent-hover); }.send-button svg { width: 18px; }
.upload-strip { margin-bottom: 8px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }

.detail-pane { min-width: 0; background: var(--panel); border-left: 1px solid var(--line); overflow: hidden; }
.detail-pane > header { padding: 0 12px 0 16px; justify-content: space-between; border-bottom: 1px solid var(--line); }.detail-pane h3 { margin: 0; font-size: 14px; }
.detail-content { height: calc(100% - 60px); overflow: auto; padding: 16px; }
.detail-group { margin-bottom: 22px; }.detail-group h4 { margin: 0 0 9px; font-size: 12px; text-transform: uppercase; color: var(--muted); }.detail-table { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 7px; font-size: 12px; }.detail-table dt { color: var(--muted); }.detail-table dd { margin: 0; overflow-wrap: anywhere; }
.file-list { display: grid; gap: 4px; }.file-button { min-width: 0; width: 100%; height: 34px; display: flex; align-items: center; gap: 7px; border: 0; border-radius: 5px; background: transparent; padding: 0 7px; text-align: left; }.file-button:hover { background: var(--panel-2); }.file-button svg { width: 15px; flex: 0 0 15px; }.file-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }.diff-view { max-height: 360px; overflow: auto; margin-top: 10px; background: #111713; color: #eef5ef; border-radius: 6px; padding: 10px; white-space: pre; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }

.settings-dialog { width: min(650px, calc(100% - 28px)); max-height: min(760px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }.settings-dialog::backdrop { background: rgba(12, 16, 13, .46); }
.actions-dialog { width: min(280px, calc(100% - 28px)); padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }.actions-dialog::backdrop { background: rgba(12, 16, 13, .38); }
.action-menu { display: grid; }.action-menu button { height: 42px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 5px; padding: 0 11px; background: transparent; text-align: left; }.action-menu button:hover { background: var(--panel-2); }.action-menu svg { width: 17px; height: 17px; color: var(--muted); }.action-menu .danger-text { color: var(--danger); }.action-menu .danger-text svg { color: var(--danger); }
.dialog-header { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px 0 20px; border-bottom: 1px solid var(--line); }.dialog-header h2 { font-size: 16px; margin: 0; }
.settings-body { max-height: calc(min(760px, 100vh - 28px) - 56px); overflow: auto; }.settings-section { padding: 18px 20px; border-bottom: 1px solid var(--line); }.settings-section h3 { margin: 0 0 12px; font-size: 13px; }.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }.row-between h3 { margin: 0; }
.inline-form { display: flex; gap: 8px; }.inline-form input { min-width: 0; flex: 1; height: 38px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); padding: 0 10px; }.success-text { color: var(--accent); font-size: 13px; }
.device-row, .workspace-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px 0; border-top: 1px solid var(--line); }.device-row:first-child, .workspace-row:first-child { border-top: 0; }.device-row small, .workspace-row small { color: var(--muted); }.workspace-row > div { min-width: 0; }.workspace-row small { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }.system-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }.system-item { border: 1px solid var(--line); border-radius: 6px; padding: 10px; }.system-item strong { display: block; font-size: 12px; }.system-item span { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 20; display: grid; gap: 8px; }.toast { max-width: min(380px, calc(100vw - 36px)); padding: 11px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); box-shadow: var(--shadow); font-size: 13px; }.toast.error { border-color: var(--danger); color: var(--danger); }

@media (max-width: 1080px) {
  .toolbar .desktop-only { display: none; }
  .app-shell.detail-open { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .detail-pane { position: fixed; z-index: 12; top: 60px; right: 0; bottom: 0; width: min(var(--detail), 92vw); box-shadow: var(--shadow); }
}

@media (max-width: 760px) {
  :root { --sidebar: min(88vw, 330px); }
  .mobile-only { display: inline-grid !important; }
  .desktop-only { display: none !important; }
  .app-shell, .app-shell.detail-open { display: block; }
  .sidebar { position: fixed; z-index: 15; inset: 0 auto 0 0; width: var(--sidebar); transform: translateX(-102%); transition: transform .18s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: fixed; z-index: 14; inset: 0; background: rgba(12, 16, 13, .48); }
  .main-pane { height: 100%; }
  .topbar { padding: 0 8px; }.title-row h2 { max-width: 42vw; }
  .toolbar-divider, .toolbar [data-action="pin"], .toolbar [data-action="rename"] { display: none; }
  .toolbar [data-action="pause"], .toolbar [data-action="resume"], .toolbar [data-action="archive"] { display: none; }
  .message-feed { padding: 20px 14px 138px; }.message.user { margin-left: 8%; }
  .composer-wrap { padding: 0 10px 10px; }.composer { min-height: 100px; }
  #workspace-select { width: 128px; }.segmented button { min-width: 34px; padding: 0 6px; }
  .detail-pane { top: 0; width: min(94vw, 380px); z-index: 18; }
  .system-grid { grid-template-columns: 1fr; }
  .inline-form { display: grid; }
}
