/* M²智能体母体平台 · Maggio Technologies
   Light, calm, enterprise. One accent (Maggio red), generous whitespace, no decoration that
   does not carry meaning. Every surface the platform renders uses these tokens. */

:root {
  --red: #e01b22;
  --red-dark: #b31319;
  --red-soft: #fdf1f1;
  --red-line: #f5cfd1;
  --ink: #16171b;
  --ink-2: #3c3f46;
  --muted: #6e737d;
  --faint: #9aa0aa;
  --line: #e6e7eb;
  --line-strong: #d5d7dd;
  --bg: #f6f6f8;
  --card: #ffffff;
  --hover: #f3f3f5;
  --ok: #137a4b;
  --ok-soft: #e9f6ef;
  --warn: #966000;
  --warn-soft: #fff6e5;
  --bad: #b3261e;
  --bad-soft: #fcedec;
  --info: #1f5faf;
  --info-soft: #edf3fc;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 22, 28, 0.05), 0 10px 30px rgba(20, 22, 28, 0.07);
  --shadow-sm: 0 1px 2px rgba(20, 22, 28, 0.06);
  --font: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d9dade; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #c3c5cb; background-clip: content-box; border: 3px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ boot */

.app-root { min-height: 100%; }

.boot {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.boot-logo { height: 34px; }
.boot-bar { width: 180px; height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.boot-bar span { display: block; width: 40%; height: 100%; background: var(--red); border-radius: 3px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }
.boot-text { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------------ auth */

.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: var(--card);
}

.auth-brand {
  position: relative;
  padding: 56px 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(900px 420px at 12% 8%, rgba(224, 27, 34, 0.10), transparent 62%),
    radial-gradient(700px 520px at 88% 92%, rgba(224, 27, 34, 0.06), transparent 60%),
    #fbfbfc;
  border-right: 1px solid var(--line);
}
.auth-brand .brand-logo { height: 30px; align-self: flex-start; }
.auth-hero { max-width: 460px; }
.auth-hero h1 { font-size: 34px; line-height: 1.25; letter-spacing: -0.02em; }
.auth-hero h1 em { font-style: normal; color: var(--red); }
.auth-hero p { margin-top: 18px; color: var(--muted); font-size: 15px; line-height: 1.75; }
.auth-points { margin: 30px 0 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.auth-points li { display: flex; gap: 10px; color: var(--ink-2); font-size: 13.5px; }
.auth-points svg { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--red); }
.auth-meta { color: var(--faint); font-size: 12px; }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 32px;
}
.auth-card { width: 100%; max-width: 384px; }
.auth-card h2 { font-size: 22px; }
.auth-card .sub { margin-top: 8px; color: var(--muted); font-size: 13.5px; }
.auth-form { margin-top: 26px; display: grid; gap: 16px; }
.auth-aside { margin-top: 22px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { margin-top: 6px; font-size: 12px; color: var(--faint); }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(224, 27, 34, 0.12);
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.input-row { display: flex; gap: 10px; }
.input-row .input { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: #000; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--red); }
.btn.primary:hover { background: var(--red-dark); }
.btn.ghost { background: #fff; border-color: var(--line-strong); color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
.btn.subtle { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn.subtle:hover { background: var(--hover); color: var(--ink); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn svg { width: 15px; height: 15px; }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; border: 1px solid transparent; }
.alert.error { background: var(--bad-soft); color: var(--bad); border-color: #f3cfcc; }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: #cbe8d9; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dfba; }
.alert.info { background: var(--info-soft); color: var(--info); border-color: #d3e2f7; }
.alert code { font-family: var(--mono); font-size: 12.5px; background: rgba(0,0,0,.05); padding: 1px 5px; border-radius: 4px; }

/* ----------------------------------------------------------------- shell */

.shell {
  height: 100vh;
  height: 100dvh;            /* mobile URL bar: 100vh overflows, 100dvh does not */
  display: grid;
  grid-template-rows: 58px 1fr 38px;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { height: 24px; width: auto; display: block; }
.brand-divider { width: 1px; height: 20px; background: var(--line); }
.brand { min-width: 0; }
.brand > div { min-width: 0; }
.brand-name { font-size: 14.5px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.brand-tag { font-size: 11.5px; color: var(--faint); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 28vw; }

.topnav { display: flex; align-items: center; gap: 4px; margin-left: 8px; }
.topnav a {
  padding: 6px 11px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
}
.topnav a:hover { background: var(--hover); text-decoration: none; }
.topnav a.active { background: var(--red-soft); color: var(--red); }

.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tenant-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: #fbfbfc;
}
.tenant-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.tenant-chip .dot.off { background: var(--faint); }
/* Live push indicator: green means the socket is up, grey means the page still works but
   only updates when you ask it to. */
.stream-chip { font-family: var(--mono); font-size: 11.5px; }
.stream-chip.off { color: var(--faint); }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  border: none;
}
.menu { position: relative; }
.menu-pop {
  position: absolute;
  right: 0;
  top: 40px;
  min-width: 210px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 40;
}
.menu-pop .who { padding: 9px 10px; border-bottom: 1px solid var(--line); margin-bottom: 5px; }
.menu-pop .who strong { display: block; font-size: 13px; }
.menu-pop .who span { font-size: 12px; color: var(--muted); }
.menu-pop button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px;
  background: none; border: 0; border-radius: 7px;
  font-size: 13px; color: var(--ink-2); cursor: pointer; text-align: left;
}
.menu-pop button:hover { background: var(--hover); }
.menu-pop button svg { width: 15px; height: 15px; color: var(--muted); }

.workspace-body {
  display: grid;
  grid-template-columns: 312px minmax(0, 1fr) 336px;
  min-height: 0;
  overflow: hidden;
}
.workspace-body.rail-hidden { grid-template-columns: 312px minmax(0, 1fr); }
.workspace-body.rail-hidden .rail { display: none; }
.workspace-body.sidebar-hidden { grid-template-columns: minmax(0, 1fr) 336px; }
.workspace-body.sidebar-hidden .sidebar { display: none; }

/* --------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
}
.sidebar-head { padding: 16px 16px 10px; display: grid; gap: 12px; }
.sidebar-title { display: flex; align-items: center; justify-content: space-between; }
.sidebar-title h2 { font-size: 13px; color: var(--muted); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); }
.search input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfbfc;
  outline: none;
  font-size: 13px;
}
.search input:focus { border-color: var(--red-line); background: #fff; }

.task-list { flex: 1; overflow-y: auto; padding: 4px 10px 16px; display: grid; gap: 2px; align-content: start; }
.task-item {
  display: grid;
  gap: 4px;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  background: none;
  width: 100%;
}
.task-item:hover { background: var(--hover); }
.task-item.active { background: var(--red-soft); border-color: var(--red-line); }
.task-item .row1 { display: flex; align-items: center; gap: 7px; }
.task-item .title { font-size: 13.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.task-item .meta { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--faint); }
.task-item .meta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--line-strong); }
.task-item .preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot-status { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.dot-status.completed { background: var(--ok); }
.dot-status.awaiting_approval { background: var(--warn); }
.dot-status.blocked { background: var(--bad); }
.dot-status.running { background: var(--info); animation: pulse 1.4s infinite; }
.dot-status.open { background: var(--faint); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.sidebar-foot { border-top: 1px solid var(--line); padding: 10px 14px; font-size: 11.5px; color: var(--faint); display: grid; gap: 3px; }
.sidebar-foot .path { font-family: var(--mono); font-size: 11px; color: var(--muted); word-break: break-all; }

/* ------------------------------------------------------------------ main */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.main-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  min-height: 58px;
}
.main-head .titles { min-width: 0; flex: 1; }
.head-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.main-head h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-head .sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.main-head .sub code { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

.messages { flex: 1; overflow-y: auto; padding: 22px 0 8px; }
.messages-inner { max-width: 820px; margin: 0 auto; padding: 0 24px; display: grid; gap: 16px; }

.msg { display: flex; gap: 10px; }
.msg .avatar-sm {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 650;
  background: var(--red); color: #fff;
}
.msg .avatar-sm.user { background: #2a2c33; }
.msg .bubble {
  max-width: min(680px, 100%);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.72;
  word-break: break-word;
}
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 20px; }
.bubble li { margin: 2px 0; }
.msg.assistant .bubble { background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: var(--red-soft); border: 1px solid var(--red-line); }
.msg .stamp { font-size: 11px; color: var(--faint); align-self: flex-end; padding-bottom: 2px; white-space: nowrap; }
.msg.system { justify-content: center; }
.msg.system .bubble {
  background: transparent; color: var(--muted); font-size: 12px;
  border: 1px dashed var(--line-strong); padding: 6px 12px;
}
.bubble strong { font-weight: 650; }
.bubble code { font-family: var(--mono); font-size: 12.5px; background: rgba(20,22,28,.05); padding: 1px 5px; border-radius: 4px; }
.bubble .tag { display: inline-block; padding: 0 7px; border-radius: 6px; background: var(--hover); font-family: var(--mono); font-size: 11.5px; margin: 0 2px; }

.attachments { display: grid; gap: 6px; margin-top: 8px; }
.attachment {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 12px; color: var(--ink-2);
}
.attachment .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .size { color: var(--faint); font-size: 11px; }
.attachment svg { width: 14px; height: 14px; color: var(--muted); }
.attachment.bad { border-color: #f3cfcc; background: var(--bad-soft); }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
}
.chip:hover { border-color: var(--red-line); background: var(--red-soft); color: var(--red); }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 24px;
  text-align: center;
}
.empty .glyph {
  width: 52px; height: 52px; border-radius: 14px;
  background: #fff; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  color: var(--red); box-shadow: var(--shadow-sm);
}
.empty .glyph svg { width: 24px; height: 24px; }
.empty h3 { font-size: 16px; }
.empty p { color: var(--muted); font-size: 13px; max-width: 420px; }
.empty .starter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 4px; width: min(520px, 100%); }
.starter {
  text-align: left;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
}
.starter:hover { border-color: var(--red-line); box-shadow: var(--shadow-sm); }
.starter span { display: block; color: var(--faint); font-size: 11px; margin-top: 2px; }

/* -------------------------------------------------------------- composer */

.composer-wrap { padding: 8px 24px 18px; }
.composer {
  max-width: 820px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--red); box-shadow: 0 0 0 3px rgba(224,27,34,.10); }
.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  padding: 13px 14px 4px;
  min-height: 56px;
  max-height: 220px;
  font-size: 13.5px;
  line-height: 1.65;
  background: transparent;
}
.composer-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 8px;
}
.composer-tools { display: flex; align-items: center; gap: 4px; min-width: 0; }
.composer-bar .spacer { flex: 1; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 9px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--muted);
  font-size: 12.5px; cursor: pointer;
}
.tool:hover { background: var(--hover); color: var(--ink); }
.tool svg { width: 16px; height: 16px; }
.send {
  width: 34px; height: 34px;
  border-radius: 9px; border: 0;
  background: var(--red); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.send:disabled { background: #e4e5e9; color: #a9adb6; cursor: not-allowed; }
.send svg { width: 16px; height: 16px; }
.composer-hint { max-width: 820px; margin: 8px auto 0; font-size: 11.5px; color: var(--faint); display: flex; justify-content: space-between; gap: 12px; }

/* ------------------------------------------------------------------ rail */

.rail {
  border-left: 1px solid var(--line);
  background: var(--card);
  overflow-y: auto;
  padding: 16px 16px 26px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px; font-weight: 650; color: var(--ink-2);
}
.card-head .hint { font-weight: 400; color: var(--faint); font-size: 11.5px; }
.card-body { padding: 12px 13px; display: grid; gap: 9px; font-size: 12.5px; }
.kv { display: flex; justify-content: space-between; gap: 10px; }
.kv .k { color: var(--muted); }
.kv .v { color: var(--ink); font-weight: 550; text-align: right; word-break: break-all; }
.kv .v.mono { font-family: var(--mono); font-size: 11.5px; font-weight: 400; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--hover); color: var(--muted);
}
.pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.awaiting_approval { background: var(--warn-soft); color: var(--warn); }
.pill.blocked { background: var(--bad-soft); color: var(--bad); }
.pill.running { background: var(--info-soft); color: var(--info); }
.pill.open { background: var(--hover); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips .tag { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--hover); color: var(--ink-2); }
.chips .tag.bad { background: var(--bad-soft); color: var(--bad); }
.chips .tag.warn { background: var(--warn-soft); color: var(--warn); }

.approval { border: 1px solid #f0dfba; background: var(--warn-soft); border-radius: 10px; padding: 11px; display: grid; gap: 8px; }
.approval .what { font-family: var(--mono); font-size: 11.5px; color: #7a4f00; word-break: break-all; }
.approval .why { font-size: 12px; color: #7a5a17; }
.approval .actions { display: flex; gap: 8px; }

.files { display: grid; gap: 2px; max-height: 280px; overflow-y: auto; }
.file-row { display: flex; align-items: center; gap: 7px; padding: 4px 4px; border-radius: 6px; font-size: 12px; color: var(--ink-2); }
.file-row:hover { background: var(--hover); }
.file-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .size { color: var(--faint); font-size: 11px; }
.file-row svg { width: 13px; height: 13px; color: var(--faint); flex: none; }
.file-row.dir { font-weight: 600; }
.file-row.dir svg { color: var(--red); }
.file-empty { color: var(--faint); font-size: 12px; }

/* A tap-anywhere-to-close layer behind the mobile drawers. */
.scrim {
  display: none;
  position: fixed; inset: 58px 0 38px;
  background: rgba(18, 19, 24, 0.34);
  border: 0; padding: 0;
  z-index: 24;
  cursor: pointer;
}
.file-row .mini {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex: none;
}
.file-row .mini:hover { border-color: var(--red-line); color: var(--red); background: var(--red-soft); }
.file-row .mini svg { width: 13px; height: 13px; }

/* ----------------------------------------------------------------- table */

.page { overflow-y: auto; padding: 26px 30px 40px; }
.page-inner { max-width: 1080px; margin: 0 auto; display: grid; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; }
.page-head p { color: var(--muted); font-size: 13px; margin-top: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 14px 15px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 3px; letter-spacing: -0.02em; }
.stat .note { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--faint); font-weight: 650; padding: 9px 12px; border-bottom: 1px solid var(--line);
  background: #fbfbfc;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fcfcfd; }
.table .who-cell strong { display: block; font-size: 13px; }
.table .who-cell span { color: var(--faint); font-size: 11.5px; }
.table select, .table .select { padding: 5px 8px; font-size: 12.5px; border-radius: 7px; width: auto; }
.tag-role { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--ink-2); }
.tag-role.admin { background: var(--red-soft); color: var(--red); }
.tag-role.manager { background: var(--info-soft); color: var(--info); }
.tag-role.disabled { background: var(--bad-soft); color: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button {
  padding: 9px 13px; border: 0; background: none; cursor: pointer;
  font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--ink); border-bottom-color: var(--red); font-weight: 600; }

.audit { display: grid; gap: 0; font-size: 12.5px; }
.audit-row { display: grid; grid-template-columns: 132px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.audit-row:last-child { border-bottom: 0; }
.audit-row .when { color: var(--faint); font-size: 11.5px; font-family: var(--mono); }
.audit-row .what strong { font-weight: 600; }
.audit-row .what span { color: var(--muted); }

/* ----------------------------------------------------------------- modal */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(18, 19, 24, 0.38);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 100;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 520px;
  background: #fff; border-radius: 16px;
  box-shadow: 0 24px 60px rgba(16, 18, 24, .25);
  overflow: hidden;
  max-height: 86vh;
  display: flex; flex-direction: column;
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 15px; }
.modal-body { padding: 18px; overflow-y: auto; display: grid; gap: 14px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fcfcfd; }
.modal-foot .left { margin-right: auto; }

.browser-crumbs { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11.5px; color: var(--muted); word-break: break-all; }
.browser-list { border: 1px solid var(--line); border-radius: 10px; max-height: 300px; overflow-y: auto; }
.browser-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 11px; background: none; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 12.5px; text-align: left; }
.browser-row:last-child { border-bottom: 0; }
.browser-row:hover { background: var(--hover); }
.browser-row svg { width: 14px; height: 14px; color: var(--red); flex: none; }
.browser-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browser-empty { padding: 20px; text-align: center; color: var(--faint); font-size: 12.5px; }
.path-input { font-family: var(--mono); font-size: 12px; }

/* ---------------------------------------------------------------- footer */

.footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px;
  border-top: 1px solid var(--line);
  background: var(--card);
  color: var(--faint);
  font-size: 11.5px;
  white-space: nowrap;
}
.footer .left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.footer .sep { width: 1px; height: 12px; background: var(--line); }
.footer .copy { color: var(--muted); }
.auth .footer { position: fixed; bottom: 0; left: 0; right: 0; height: 38px; }

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%) translateY(12px);
  background: #1b1c21; color: #fff;
  padding: 9px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 200; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }
.toast.ok { background: #14532d; }

.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
.progress-line {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ------------------------------------------------------------ responsive */
/* Three layouts, not one shrinking one:
     ≥1181  three columns (tasks | conversation | results)
     901-1180  two columns + the results rail becomes a drawer
     ≤900  one column + the task list becomes a drawer
     ≤640  phone: sheets instead of dialogs, thumb-sized targets, one-handed composer
   The breakpoints follow the content, not the device names: what breaks at 1180 is the third
   column, and what breaks at 900 is the 300px task list. */

@media (max-width: 1180px) {
  .workspace-body,
  .workspace-body.rail-hidden { grid-template-columns: 272px minmax(0, 1fr); }
  .workspace-body.rail-hidden .rail { display: grid; }
  .workspace-body .rail,
  .workspace-body.rail-hidden .rail {
    position: fixed;
    top: 58px; right: 0; bottom: 38px;
    width: min(360px, 88vw);
    z-index: 34;
    display: grid;
    transform: translateX(102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
    border-left: 1px solid var(--line);
  }
  .workspace-body.rail-open .rail { transform: translateX(0); }
  .workspace-body.rail-open .scrim { display: block; }
}

@media (max-width: 820px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-panel { padding: 40px 20px 70px; }

  .topbar { gap: 10px; padding: 0 12px; }
  .brand-divider, .brand-tag, .tenant-chip { display: none; }
  .topnav { margin-left: 0; gap: 2px; }
  .topnav a { padding: 7px 9px; font-size: 12.5px; }

  .workspace-body,
  .workspace-body.rail-hidden,
  .workspace-body.rail-open,
  .workspace-body.sidebar-open { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 58px; bottom: 38px; left: 0;
    width: min(320px, 86vw); z-index: 32;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .workspace-body.sidebar-open .scrim { display: block; }

  .rail { display: grid !important; }
  .page { padding: 18px 14px 32px; }
  .page-inner { gap: 14px; }
  .messages-inner { padding: 0 14px; gap: 14px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .footer { font-size: 11px; padding: 0 12px; }
  .footer .hide-sm { display: none; }
}

@media (max-width: 640px) {
  html, body { font-size: 14px; }
  .shell { grid-template-rows: 54px 1fr 34px; }

  /* top bar: mark + current page, everything else behind the avatar menu */
  .topbar { height: 54px; padding: 0 10px; gap: 8px; }
  .brand-logo { height: 20px; }
  /* The nav is the thing people came for; the wordmark is already carried by the logo. */
  .brand-name { display: none; }
  .brand { gap: 0; }
  .topnav a { padding: 6px 7px; font-size: 12px; }

  /* conversation fills the width; bubbles stop pretending to be columns */
  .main-head { padding: 8px 12px; min-height: 50px; gap: 6px; flex-wrap: wrap; }
  .main-head .titles { flex: 1 1 100%; }
  .head-actions { width: 100%; justify-content: flex-end; }
  .main-head h1 { font-size: 14.5px; }
  .main-head .sub { row-gap: 4px; flex-wrap: wrap; font-size: 11.5px; }
  .main-head .sub code { max-width: 52vw; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; }
  .icon-btn { width: 36px; height: 36px; }
  .messages { padding: 14px 0 4px; }
  .messages-inner { padding: 0 10px; }
  .msg { gap: 7px; }
  .msg .avatar-sm { width: 24px; height: 24px; }
  .msg .bubble { max-width: calc(100% - 40px); font-size: 13.5px; padding: 10px 12px; }
  .msg .stamp { display: none; }
  .suggestions .chip { font-size: 12px; }

  /* composer: thumb-sized, above the home indicator */
  .composer-wrap { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer textarea { font-size: 15px; min-height: 46px; }  /* 15px+: iOS stops zooming in */
  .composer-bar { gap: 6px; padding: 4px 6px 6px; flex-wrap: nowrap; }
  /* One row, scrollable sideways: wrapping made three lines of chrome above a two-line message. */
  .composer-tools { flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
  .composer-tools::-webkit-scrollbar { display: none; }
  .tool { padding: 7px 8px; flex: 0 0 auto; white-space: nowrap; max-width: 46vw;
    overflow: hidden; text-overflow: ellipsis; }
  .composer-bar .spacer { display: none; }
  .composer-hint { display: none; }
  .send { width: 38px; height: 38px; }

  /* dialogs become bottom sheets: reachable with a thumb, no tiny scroll area */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal, .modal.wide {
    max-width: none; width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 92dvh;
  }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; }

  /* admin tables scroll sideways instead of squeezing eight columns into 360px */
  .card { overflow-x: auto; }
  .table { min-width: 680px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 19px; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { white-space: nowrap; padding: 9px 11px; }

  .page { padding: 14px 12px 28px; }
  .page-head h1 { font-size: 18px; }
  .page-head { align-items: flex-start; }
  .audit-row { grid-template-columns: 1fr; gap: 2px; }

  .task-item { padding: 12px 12px; }
  .search input { font-size: 16px; }       /* avoids the iOS zoom-on-focus jump */

  .approval .actions .btn { flex: 1; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); max-width: 92vw; font-size: 12.5px; }
  .footer .copy { font-size: 10.5px; }
}

@media (max-width: 380px) {
  .brand-name { display: none; }
  .msg .bubble { max-width: calc(100% - 34px); }
}
