:root {
  color-scheme: light dark;
  --paper: #f6f7f9;
  --card: #ffffff;
  --ink: #191c20;
  --muted: #707782;
  --line: #e1e5ea;
  --soft: #eef1f5;
  --accent: #2563eb;
  --accent-soft: #e7efff;
  --safe: #18794e;
  --safe-soft: #e7f7ef;
  --danger: #b42318;
  --danger-soft: #feeceb;
  --warning: #8a5d00;
  --warning-soft: #fff2cc;
  --shadow: 0 12px 34px rgba(26, 35, 50, .09);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 19px; letter-spacing: -.025em; }
h2 { margin-bottom: 3px; font-size: 27px; letter-spacing: -.04em; }
h3 { margin-bottom: 7px; font-size: 18px; letter-spacing: -.025em; }

.topbar {
  position: sticky;
  z-index: 8;
  top: 0;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  max-width: 800px;
  min-height: calc(64px + env(safe-area-inset-top));
  margin: auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  backdrop-filter: blur(20px);
}

.brand-copy { padding-left: 6px; }
.eyebrow, .card-kicker {
  margin-bottom: 1px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: var(--soft);
  color: var(--ink);
  font-size: 22px;
}
.icon-button.elevated { background: var(--card); box-shadow: var(--shadow); color: var(--accent); }

.connection {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.connection::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #a6acb5; }
.connection.online::before { background: #23a068; box-shadow: 0 0 0 3px rgba(35, 160, 104, .13); }
.connection.warning::before { background: #d48b00; box-shadow: 0 0 0 3px rgba(212, 139, 0, .13); }
.connection.error::before { background: var(--danger); }

main { max-width: 800px; margin: auto; padding: 14px 14px 112px; }
.view { animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }

.card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.login-card { max-width: 560px; margin: 28px auto 0; }
.body-copy, .hint, .workspace-heading p, .empty-state p, .dictation-hint { color: var(--muted); }
.body-copy { margin-bottom: 12px; font-size: 14px; }
.hint { margin: 7px 0 0; font-size: 11px; }

label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 700; }
input, textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: var(--card);
  color: var(--ink);
}
textarea { min-height: 116px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent); }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

button {
  min-height: 46px;
  padding: 10px 15px;
  border: 0;
  border-radius: 13px;
  font-weight: 750;
}
.primary { width: 100%; margin-top: 15px; background: var(--accent); color: white; box-shadow: 0 8px 18px rgba(37, 99, 235, .19); }
.primary.compact { width: auto; min-width: 76px; margin-top: 0; }
.secondary { width: 100%; margin-top: 9px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.text-button { min-height: 42px; padding: 7px 9px; background: transparent; color: var(--accent); }
.danger { width: 100%; margin-top: 11px; background: var(--danger); color: white; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  max-width: 430px;
  margin: 2px auto 19px;
  padding: 4px;
  border-radius: 14px;
  background: var(--soft);
}
.mode-button { min-height: 40px; padding: 7px; background: transparent; color: var(--muted); }
.mode-button.active { border-radius: 11px; background: var(--card); color: var(--ink); box-shadow: 0 2px 8px rgba(30, 40, 55, .1); }

.workspace-heading, .project-toolbar, .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.workspace-heading { padding: 7px 4px 15px; }
.workspace-heading p { margin-bottom: 0; font-size: 13px; }
.permission-badge {
  display: inline-flex;
  margin-bottom: 7px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
}
.permission-badge.safe { background: var(--safe-soft); color: var(--safe); }

.empty-state { padding: 38px 22px; text-align: center; }
.empty-state p { max-width: 430px; margin: 0 auto 10px; font-size: 14px; }
.empty-icon { width: 58px; height: 58px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 19px; background: var(--accent-soft); color: var(--accent); font-size: 28px; }
.compact-empty { padding: 50px 16px; text-align: center; }

.chat-shell { min-height: 56vh; }
.message-list { display: flex; min-height: 280px; flex-direction: column; justify-content: flex-end; gap: 10px; padding: 8px 3px 160px; }
.message { max-width: 88%; padding: 11px 13px; border-radius: 17px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.message.user { align-self: flex-end; border-bottom-right-radius: 6px; background: var(--accent); color: white; }
.message.assistant, .message.system { align-self: flex-start; border: 1px solid var(--line); border-bottom-left-radius: 6px; background: var(--card); }
.message.system { border-color: #efc7c3; color: var(--danger); }
.message-time { display: block; margin-top: 5px; opacity: .65; font-size: 9px; }
.typing { align-self: flex-start; padding: 8px 11px; border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 11px; }

.message-composer {
  position: fixed;
  z-index: 4;
  right: 14px;
  bottom: calc(79px + env(safe-area-inset-bottom));
  left: 14px;
  max-width: 772px;
  margin: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  box-shadow: 0 12px 36px rgba(25, 36, 54, .16);
  backdrop-filter: blur(18px);
}
.message-composer textarea { min-height: 48px; max-height: 130px; padding: 10px; border: 0; background: transparent; resize: none; box-shadow: none; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 3px 2px 9px; }
.dictation-hint { font-size: 10px; }
.send-button { width: 40px; min-width: 40px; min-height: 40px; padding: 0; border-radius: 13px; background: var(--accent); color: white; font-size: 22px; }
.utility-button { display: block; margin: -145px auto 155px; background: transparent; color: var(--muted); font-size: 11px; }

.project-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; }
.project-card { min-height: 112px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); text-align: left; box-shadow: 0 6px 18px rgba(28, 38, 54, .05); }
.project-card .folder { display: grid; width: 36px; height: 36px; margin-bottom: 12px; place-items: center; border-radius: 11px; background: var(--accent-soft); }
.project-card strong { display: block; margin-bottom: 2px; }
.project-card small { color: var(--muted); font-size: 10px; }
.project-actions { margin-top: 14px; }
.project-form { margin-top: 14px; }

.project-toolbar { padding: 2px 0 12px; }
.project-toolbar > div { min-width: 0; flex: 1; }
.project-toolbar h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 22px; }
.project-tabs { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 -14px 10px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--card); }
.project-tab { min-height: 44px; border-radius: 0; background: transparent; color: var(--muted); font-size: 12px; }
.project-tab.active { color: var(--accent); box-shadow: inset 0 -2px var(--accent); }
.conversation-strip { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.conversation-chip { flex: 0 0 auto; max-width: 180px; min-height: 38px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.conversation-chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.file-toolbar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.icon-button.small { width: 38px; min-width: 38px; height: 38px; border-radius: 12px; font-size: 18px; }
.file-breadcrumbs { display: flex; min-width: 0; flex: 1; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.file-crumb { min-height: 36px; padding: 6px 8px; border-radius: 10px; background: transparent; color: var(--muted); white-space: nowrap; font-size: 11px; }
.file-crumb:last-child { color: var(--ink); }
.file-crumb-separator { color: var(--muted); font-size: 11px; }
.file-security-note { margin: 0 0 10px; color: var(--muted); font-size: 10px; }
.file-operation-toggle { margin: 0 0 10px; }
.file-operation-form { margin: 0 0 12px; padding: 15px; }
.file-operation-form label { margin-top: 10px; }
.file-loading { padding: 34px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.file-list { display: grid; gap: 7px; }
.file-row { display: grid; grid-template-columns: 35px minmax(0, 1fr) auto; width: 100%; min-height: 56px; align-items: center; gap: 9px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); text-align: left; }
.file-row-icon { display: grid; width: 35px; height: 35px; place-items: center; border-radius: 10px; background: var(--soft); }
.file-row.directory .file-row-icon { background: var(--accent-soft); }
.file-row-copy { min-width: 0; }
.file-row-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-row-meta { display: block; color: var(--muted); font-size: 9px; }
.file-row-arrow { color: var(--muted); }
.file-preview { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.file-preview-heading { display: flex; align-items: center; gap: 7px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.file-preview-heading .text-button { padding-left: 0; }
.file-preview-heading div { min-width: 0; }
.file-preview-heading h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.file-preview-heading p { margin: 1px 0 0; color: var(--muted); font-size: 9px; }
.file-preview-warning { margin: 0; padding: 12px; background: var(--warning-soft); color: var(--warning); font-size: 12px; }
.file-preview pre { max-height: 60vh; margin: 0; padding: 14px; overflow: auto; background: color-mix(in srgb, var(--soft) 70%, var(--card)); color: var(--ink); font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; tab-size: 2; }

.notice { position: fixed; z-index: 20; top: calc(76px + env(safe-area-inset-top)); right: 14px; left: 14px; max-width: 620px; margin: auto; padding: 13px 15px; border-radius: 15px; background: #183d2d; color: white; box-shadow: var(--shadow); white-space: pre-wrap; font-size: 13px; }
.notice.error { background: var(--danger); }

.page-heading { padding: 12px 4px 15px; }
.task-list { display: grid; gap: 10px; }
.task-card { padding: 15px; border: 1px solid var(--line); border-radius: 17px; background: var(--card); box-shadow: 0 5px 16px rgba(30, 40, 55, .05); }
.task-card.deep-linked { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), 0 5px 16px rgba(30, 40, 55, .05); }
.task-top { display: flex; justify-content: space-between; gap: 10px; }
.task-title { margin-bottom: 4px; font-size: 14px; font-weight: 750; }
.task-meta { color: var(--muted); font-size: 10px; }
.task-result { margin: 11px 0 0; padding-top: 10px; border-top: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: 12px; }
.status-pill { flex: none; padding: 4px 7px; border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 9px; font-weight: 750; }
.status-pill.completed { background: var(--safe-soft); color: var(--safe); }
.status-pill.failed { background: var(--danger-soft); color: var(--danger); }
.status-pill.awaiting_approval { background: var(--warning-soft); color: var(--warning); }
.approve { width: 100%; margin-top: 11px; background: var(--ink); color: var(--card); }
.empty { padding: 42px 0; text-align: center; color: var(--muted); font-size: 13px; }

.danger-card { border-color: #efc7c3; }
.danger-text { color: var(--danger); }
.safety-state { display: inline-block; margin: 4px 0 0; padding: 5px 8px; border-radius: 999px; background: var(--soft); font-size: 11px; font-weight: 750; }
.safety-state.paused { background: var(--danger-soft); color: var(--danger); }

.drawer {
  position: fixed;
  z-index: 30;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(86vw, 370px);
  padding: calc(19px + env(safe-area-inset-top)) 14px 30px;
  background: var(--card);
  box-shadow: 18px 0 46px rgba(15, 25, 40, .21);
  overflow-y: auto;
}
.drawer-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.history-list { display: grid; gap: 5px; }
.history-item { width: 100%; min-height: 48px; padding: 9px 11px; border-radius: 12px; background: transparent; color: var(--ink); text-align: left; }
.history-item.active { background: var(--accent-soft); color: var(--accent); }
.history-item small { display: block; color: var(--muted); font-size: 9px; }
.drawer-scrim { position: fixed; z-index: 29; inset: 0; background: rgba(9, 18, 30, .35); backdrop-filter: blur(2px); }

.tabbar {
  position: fixed;
  z-index: 10;
  right: 12px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  max-width: 760px;
  margin: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  box-shadow: 0 10px 34px rgba(22, 31, 46, .18);
  backdrop-filter: blur(20px);
}
.tab { display: flex; min-height: 49px; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 3px; background: transparent; color: var(--muted); font-size: 10px; }
.tab span { font-size: 17px; line-height: 1; }
.tab.active { border-radius: 15px; background: var(--accent-soft); color: var(--accent); }

@media (max-width: 520px) {
  main { padding-right: 11px; padding-left: 11px; }
  .project-list { grid-template-columns: 1fr 1fr; }
  .project-card { min-height: 106px; }
  .workspace-heading h2 { font-size: 25px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111419;
    --card: #1a1e24;
    --ink: #f3f5f8;
    --muted: #a4abb5;
    --line: #2d333d;
    --soft: #242a32;
    --accent: #78a7ff;
    --accent-soft: #1c3158;
    --safe: #6ed6a7;
    --safe-soft: #16382a;
    --danger: #ff9188;
    --danger-soft: #49201f;
    --warning: #f4ca68;
    --warning-soft: #463815;
    --shadow: 0 12px 34px rgba(0, 0, 0, .24);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
