:root {
  --bg: #ffffff; --panel: #f7f7f8; --border: #e3e3e6; --text: #1c1c1e;
  --muted: #6b6b70; --accent: #cb0000; --danger: #c92a2a; --tool: #f1f3f9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a; --panel: #1e1f23; --border: #2e3036; --text: #e8e8ea;
    --muted: #9a9aa2; --accent: #d81212; --danger: #ff6b6b; --tool: #22242b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, sans-serif;
}
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); }
button { font: inherit; cursor: pointer; border-radius: 6px; }

/* login */
.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card label { display: block; margin: 16px 0 0; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 4px; padding: 9px 11px; font: inherit;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text);
}
.login-card button {
  width: 100%; margin-top: 20px; padding: 10px;
  background: var(--accent); color: #fff; border: 0; font-weight: 500;
}

/* layout */
#app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--border);
}
.sidebar-head { padding: 14px; border-bottom: 1px solid var(--border); }
.sidebar-head input {
  width: 100%; margin-top: 8px; padding: 6px 9px; font: inherit; font-size: 13px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text);
}
.site-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 6px; }
.site-list li { margin: 1px 0; }
.site-list button {
  display: block; width: 100%; text-align: left; padding: 7px 9px;
  background: none; border: 0; color: var(--text); font-size: 13px;
  border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-list button:hover { background: var(--border); }
.site-list button[aria-current="true"] { background: var(--accent); color: #fff; }
.site-list button.locked { opacity: .5; }
.sidebar-foot {
  padding: 12px 14px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.link { background: none; border: 0; color: var(--accent); font-size: 13px; padding: 0; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.topbar h2 { margin: 0 0 2px; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
/* Undo is a recovery action, not a destructive one, and brand red is now the
   accent -- so this reads neutral. Red stays reserved for errors and denials. */
.danger { background: none; border: 1px solid var(--border); color: var(--muted); padding: 5px 11px; font-size: 13px; }
.danger:hover { border-color: var(--text); color: var(--text); }

.transcript { flex: 1; overflow-y: auto; padding: 20px; }
.empty { color: var(--muted); text-align: center; margin-top: 15vh; }
.msg { margin: 0 0 18px; max-width: 780px; }
.msg.user { padding: 10px 13px; background: var(--panel); border-radius: 9px; white-space: pre-wrap; }
.msg.claude { white-space: pre-wrap; }
.msg.tool {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px;
  color: var(--muted); background: var(--tool); padding: 5px 10px;
  border-radius: 5px; margin-bottom: 6px; display: inline-block;
}
.msg.denied { border-left: 2px solid var(--danger); padding-left: 10px; color: var(--danger); font-size: 13px; }
.msg.failed { color: var(--danger); }

.changes { border-top: 1px solid var(--border); padding: 12px 20px; max-height: 160px; overflow-y: auto; }
.changes ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }

.composer { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.composer textarea {
  flex: 1; resize: vertical; padding: 9px 11px; font: inherit;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
.composer button {
  align-self: flex-end; padding: 9px 20px; background: var(--accent);
  color: #fff; border: 0; font-weight: 500;
}
.composer button:disabled, .composer textarea:disabled { opacity: .5; cursor: default; }

/* Hamburger, mobile only. Three bars so it reads as a menu without an icon font. */
.menu-btn {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 40px; height: 40px; padding: 0 9px; flex-shrink: 0;
  background: none; border: 1px solid var(--border);
}
.menu-btn span { display: block; height: 2px; background: var(--text); border-radius: 1px; }
.backdrop { display: none; }

@media (max-width: 760px) {
  /* The sidebar becomes an off-canvas drawer. It used to be display:none here,
     which left no way to choose a site at all on a phone. */
  #app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; z-index: 30; inset: 0 auto 0 0;
    width: min(84vw, 320px);
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 2px 0 18px rgba(0,0,0,.35);
  }
  body.drawer-open .sidebar { transform: translateX(0); }

  .backdrop {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0,0,0,.5);
  }

  .menu-btn { display: flex; }
  .topbar { gap: 12px; padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top)); align-items: center; }
  .topbar-title { min-width: 0; flex: 1; }
  .topbar h2 { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #site-sub { display: none; }

  .transcript { padding: 14px; }
  .msg { max-width: 100%; }

  .composer {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  /* 16px stops iOS zooming the page when the field is focused. */
  .composer textarea { font-size: 16px; }
  .composer-actions { flex-direction: row; gap: 8px; }
  .composer button { padding: 10px 16px; min-height: 44px; }

  /* Comfortable touch targets in the site list. */
  .site-list button { padding: 11px 10px; font-size: 14px; }
  .sidebar-head input { font-size: 16px; padding: 9px; }
  .changes { max-height: 120px; padding: 10px 14px; }
}

/* Landscape phones: the composer must not eat the whole screen. */
@media (max-width: 900px) and (max-height: 460px) {
  .composer textarea { rows: 1; min-height: 42px; }
  .changes { max-height: 80px; }
}

/* The [hidden] attribute works via the UA stylesheet, which any author rule
   with an explicit display (#app and .login-wrap below are display:grid) beats.
   Without this, hiding a panel silently does nothing. */
[hidden] { display: none !important; }

/* Brand */
.brand { display: block; }
.brand img { display: block; width: 100%; height: auto; }
.login-card .brand { max-width: 190px; margin: 0 auto 22px; }
.brand-sidebar { max-width: 132px; margin: 0 0 12px; }

/* Login logo is a plain <img>; the sidebar one is a <picture> that swaps. */
img.brand { display: block; height: auto; }
.login-card img.brand { width: 100%; max-width: 200px; margin: 2px auto 22px; }

/* Composer actions + upload */
.composer-actions { display: flex; flex-direction: column; gap: 8px; align-self: flex-end; }
.ghost {
  background: none; border: 1px solid var(--border); color: var(--muted);
  padding: 8px 14px; font-size: 13px;
}
.ghost:hover:not(:disabled) { border-color: var(--text); color: var(--text); }
.ghost:disabled { opacity: .45; cursor: default; }
.transcript.dropping { outline: 2px dashed var(--accent); outline-offset: -10px; }

.brand-sidebar { max-width: 132px; margin: 0 0 12px; }
