/* ==========================================================================
   Z3_us Almighty — lightweight interface
   Light-first, dark via prefers-color-scheme. No framework, no build step.
   ========================================================================== */

:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --border: #e6e8ec;
  --border-strong: #d3d7de;
  --text: #10141a;
  --text-soft: #3d444d;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --accent-contrast: #ffffff;
  --danger: #d92d20;
  --success: #12b76a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 20, 26, 0.04), 0 8px 24px rgba(16, 20, 26, 0.05);
  --sidebar-width: 216px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --bg-soft: #10161e;
    --surface: #131a23;
    --surface-2: #1a222d;
    --border: #232c38;
    --border-strong: #333d4b;
    --text: #e6edf3;
    --text-soft: #c2cad4;
    --muted: #8b949e;
    --accent: #2dd4bf;
    --accent-soft: #102b2a;
    --accent-contrast: #06231f;
    --danger: #f97066;
    --success: #3fb950;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- buttons ----------------------------------------------------------- */

button { font: inherit; cursor: pointer; }

.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-weight: 600;
  font-size: 14px;
  transition: filter 120ms ease, opacity 120ms ease;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.primary.block { width: 100%; }

.ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
}
.ghost:hover { background: var(--surface-2); color: var(--text); }

.link {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--text); }

.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* --- brand ------------------------------------------------------------- */

.brand { display: flex; align-items: center; gap: 9px; }
.brand-lg { flex-direction: column; gap: 12px; text-align: center; }

.mark {
  display: block;
  width: 30px; height: 30px;
  border-radius: 9px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.35), 0 0 14px rgba(45, 212, 191, 0.25);
}
.brand-lg .mark { width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.35), 0 0 32px rgba(45, 212, 191, 0.35); }

.brand-name { font-weight: 600; letter-spacing: -0.01em; }

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

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-soft);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.auth-card .sub { color: var(--muted); font-size: 14px; margin: 4px 0 24px; text-align: center; }

.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 500; color: var(--text-soft); margin-bottom: 6px; }
.field-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 5px; }

input[type="email"], input[type="password"], textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.error { color: var(--danger); font-size: 13px; margin: 0 0 14px; }

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

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand { flex: 1; min-width: 0; }

.topbar-meta { display: flex; align-items: center; gap: 8px; }

.chip {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 10px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.live { color: var(--success); }
.chip.busy { color: var(--accent); }

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg);
}

.sidebar nav { display: grid; gap: 2px; }

.nav-item {
  background: transparent;
  border: 0;
  text-align: left;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.sidebar-foot { margin-top: auto; padding: 0 10px; word-break: break-all; }

.main { flex: 1; min-width: 0; display: flex; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.view-panel { padding: 32px 40px; overflow-y: auto; }
.view-title { font-size: 20px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }

/* --- chat -------------------------------------------------------------- */

.view-chat { height: calc(100vh - 56px); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 8px;
  scroll-behavior: smooth;
}

.thread { max-width: 760px; margin: 0 auto; display: grid; gap: 26px; }

.msg { display: grid; gap: 8px; }

.msg-role {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.msg-body { white-space: pre-wrap; word-break: break-word; color: var(--text-soft); }
.msg-body a { color: var(--accent); }

.msg.user .msg-body {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text);
}

.msg.assistant .msg-body { padding: 2px 0; }
.msg.error .msg-body { color: var(--danger); }

.empty {
  max-width: 760px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 14px;
  padding: 40px 0;
  text-align: center;
}

/* --- tool activity ----------------------------------------------------- */

.tools { display: grid; gap: 4px; margin: 2px 0 2px; }

.tool {
  display: grid;
  grid-template-columns: 14px auto 1fr;
  align-items: baseline;
  gap: 9px;
  font-size: 13px;
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  cursor: pointer;
}
.tool:hover { border-color: var(--border-strong); }

.tool-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  align-self: center;
}
.tool.running .tool-dot { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.tool.ok .tool-dot { background: var(--success); }
.tool.fail .tool-dot { background: var(--danger); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.tool-name { font-family: var(--mono); font-size: 12.5px; color: var(--text-soft); }
.tool-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tool-detail {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 2px 0 6px 23px;
  max-height: 320px;
  overflow: auto;
}

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

.composer { padding: 8px 24px 20px; }

.composer form {
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.composer form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer textarea {
  border: 0;
  padding: 4px 0;
  background: transparent;
  resize: none;
  max-height: 220px;
  min-height: 26px;
  line-height: 1.5;
}
.composer textarea:focus-visible { outline: none; box-shadow: none; }

.composer-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }

.picker {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  max-width: 260px;
  cursor: pointer;
}
.picker:hover { border-color: var(--border-strong); color: var(--text); }

.settings-form {
  max-width: 520px;
  margin-top: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px 24px;
  background: var(--surface);
}
.settings-title { margin: 0 0 16px; font-size: 15px; font-weight: 600; }
.settings-actions { display: flex; align-items: center; gap: 12px; }
.settings-form select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.hint {
  max-width: 760px;
  margin: 8px auto 0;
  font-size: 12px;
  color: var(--muted);
}

/* --- lists ------------------------------------------------------------- */

.list { display: grid; gap: 8px; margin-top: 18px; max-width: 760px; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface);
}
.card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.card .meta { font-size: 13px; color: var(--muted); word-break: break-word; }

.code {
  margin: 18px 0 0;
  max-width: 760px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-soft);
  white-space: pre-wrap;
  overflow-x: auto;
}

/* --- responsive -------------------------------------------------------- */

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 56px; bottom: 0; left: 0;
    z-index: 15;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .view-panel { padding: 24px 18px; }
  .messages { padding: 20px 16px 4px; }
  .composer { padding: 8px 16px 16px; }
  .chip { max-width: 110px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .messages { scroll-behavior: auto; }
}
