/* Claude Remoto: interfaz móvil primero, tema oscuro por defecto. */
:root {
  --bg: #101114;
  --surface: #17191e;
  --surface-2: #1e2128;
  --surface-3: #262a33;
  --border: #2c313b;
  --text: #e8eaef;
  --muted: #9aa1ad;
  --faint: #6b7280;
  --accent: #e8a15c;
  --accent-ink: #1b1209;
  --accent-soft: rgba(232, 161, 92, 0.14);
  --ok: #5cc28f;
  --ok-soft: rgba(92, 194, 143, 0.14);
  --warn: #e6c15c;
  --warn-soft: rgba(230, 193, 92, 0.13);
  --danger: #ef6b6b;
  --danger-soft: rgba(239, 107, 107, 0.14);
  --info: #7ea6ff;
  --add-bg: rgba(92, 194, 143, 0.13);
  --del-bg: rgba(239, 107, 107, 0.13);
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f4;
    --surface: #ffffff;
    --surface-2: #f0f0ed;
    --surface-3: #e6e6e2;
    --border: #dddcd6;
    --text: #1d1f23;
    --muted: #5f6570;
    --faint: #8a8f98;
    --accent: #c4692b;
    --accent-ink: #ffffff;
    --accent-soft: rgba(196, 105, 43, 0.11);
    --ok: #1f8a57;
    --ok-soft: rgba(31, 138, 87, 0.1);
    --warn: #a77a07;
    --warn-soft: rgba(167, 122, 7, 0.1);
    --danger: #c93a3a;
    --danger-soft: rgba(201, 58, 58, 0.09);
    --info: #3461d1;
    --add-bg: rgba(31, 138, 87, 0.1);
    --del-bg: rgba(201, 58, 58, 0.09);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
[hidden] { display: none !important; }
.sprite { position: absolute; }
svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
code, pre, kbd { font-family: var(--mono); font-size: 13px; }
code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
a { color: var(--info); }

/* ---------- Botones y campos ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface-2); color: var(--text);
  font: 600 14px/1 var(--sans); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.danger-text { color: var(--danger); }

.icon-btn {
  position: relative;
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.round { width: 44px; height: 44px; border-radius: 50%; }
.icon-btn.primary { background: var(--accent); color: var(--accent-ink); }
.icon-btn.primary:hover { filter: brightness(1.06); }
.icon-btn.danger { background: var(--danger-soft); color: var(--danger); }
.icon-btn:disabled { opacity: .4; }

.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface-2); color: var(--text);
  font: 15px/1.4 var(--sans);
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.otp { font: 600 22px/1 var(--mono); letter-spacing: .3em; text-align: center; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > input { flex: 1 1 200px; width: auto; }
.stack { display: grid; gap: 10px; }
.error { color: var(--danger); background: var(--danger-soft); padding: 9px 12px; border-radius: 10px; font-size: 14px; margin: 0 0 12px; }

/* ---------- Carga ---------- */
.boot { height: 100%; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login y configuración ---------- */
.auth { height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; }
.auth-card h1 { margin: 10px 0 6px; font-size: 22px; }
.auth-card > .muted { margin: 0 0 20px; }
.auth-logo { display: block; }
.steps { padding-left: 20px; margin: 0 0 8px; }
.steps li { margin-bottom: 18px; }
.steps li::marker { color: var(--accent); font-weight: 700; }
.steps p { margin: 0 0 10px; }
.qr { width: 196px; height: 196px; background: #fff; border-radius: 12px; padding: 8px; margin: 4px 0 8px; }
.qr svg { width: 100%; height: 100%; stroke: none; }
.secret summary { cursor: pointer; color: var(--info); font-size: 13px; }
.secret code { display: block; word-break: break-all; padding: 8px; margin-top: 4px; }

/* ---------- Estructura principal ---------- */
.app { height: 100%; display: grid; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); }
.drawer {
  position: fixed; inset: 0 auto 0 0; z-index: 30;
  width: min(86vw, 320px);
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 12px calc(12px + var(--safe-b));
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform .22s ease;
}
.drawer.open { transform: none; }
.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .45); }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 2px 4px; }
.brand { font-weight: 700; font-size: 16px; flex: 1; }
.drawer-foot { margin-top: auto; }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.chat-group { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); padding: 14px 8px 6px; }
.chat-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center;
  width: 100%; text-align: left;
  padding: 9px 10px; margin-bottom: 2px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text);
  font: inherit; cursor: pointer;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-soft); }
.chat-item .t { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .m { grid-column: 1 / -1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.dot.running { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.waiting { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.ready { background: var(--ok); }
@keyframes pulse { 50% { opacity: .35; } }
.badge { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--warn); border: 2px solid var(--bg); }

.main { height: 100%; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 8px; min-height: 56px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.topbar-title { flex: 1; min-width: 0; padding: 0 6px; }
.title-text { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.running { background: var(--accent-soft); color: var(--accent); }
.pill.waiting { background: var(--warn-soft); color: var(--warn); }
.pill.ready { background: var(--ok-soft); color: var(--ok); }

@media (min-width: 900px) {
  .app { grid-template-columns: 300px 1fr; }
  .drawer { position: static; transform: none; width: auto; }
  .scrim, .only-mobile { display: none !important; }
}

/* ---------- Vacío ---------- */
.empty { flex: 1; display: grid; place-content: center; justify-items: center; text-align: center; gap: 6px; padding: 24px; }
.empty h2 { margin: 10px 0 0; }
.empty p { max-width: 360px; margin: 0 0 14px; }

/* ---------- Registro de la conversación ---------- */
.log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px 24px; overscroll-behavior: contain; }
.log > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.msg { margin: 0 auto 14px; overflow-wrap: anywhere; }
.msg.user {
  margin-left: auto; margin-right: 0; width: fit-content; max-width: min(88%, 680px);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 9px 13px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap;
}
@media (min-width: 900px) { .msg.user { margin-right: max(0px, calc((100% - 820px) / 2)); } }
.msg.assistant { padding: 0 2px; }
.msg.assistant.draft { white-space: pre-wrap; color: var(--muted); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 10px; }
.md li { margin: 3px 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 16px 0 8px; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md pre { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 10px; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }

.line { font-size: 12.5px; color: var(--faint); margin: 0 auto 12px; display: flex; align-items: center; gap: 8px; }
.line::before, .line::after { content: ''; height: 1px; flex: 1; background: var(--border); }
.notice { font-size: 13.5px; padding: 8px 12px; border-radius: 10px; margin: 0 auto 12px; background: var(--surface-2); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.error { background: var(--danger-soft); color: var(--danger); white-space: pre-wrap; }

.thinking { margin: 0 auto 12px; font-size: 13px; color: var(--muted); }
.thinking summary { cursor: pointer; color: var(--faint); }
.thinking div { white-space: pre-wrap; padding: 6px 0 0 12px; border-left: 2px solid var(--border); margin-top: 6px; }

/* Tarjetas de herramientas */
.tool { margin: 0 auto 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.tool.nested { margin-left: 22px; border-style: dashed; }
.tool > summary {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px; cursor: pointer; list-style: none; min-height: 40px;
}
.tool > summary::-webkit-details-marker { display: none; }
.tool .ico { color: var(--muted); }
.tool .name { font-weight: 600; font-size: 13.5px; }
.tool .sum { flex: 1; min-width: 0; font: 12.5px/1.4 var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool .st { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-3); flex: none; }
.tool.done .st { background: var(--ok); }
.tool.err .st { background: var(--danger); }
.tool.err { border-color: rgba(239, 107, 107, .35); }
.tool-body { padding: 0 11px 11px; display: grid; gap: 8px; }
.tool-body .label { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }

pre.code, pre.out, pre.diff {
  margin: 0; padding: 9px 11px; border-radius: 9px;
  background: var(--surface-2); overflow: auto; max-height: 360px;
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; line-height: 1.45;
}
pre.out.err { background: var(--danger-soft); color: var(--danger); }
pre.diff { white-space: pre; padding: 0; }
pre.diff span { display: block; padding: 0 11px; min-height: 1.45em; }
pre.diff .add { background: var(--add-bg); color: var(--ok); }
pre.diff .del { background: var(--del-bg); color: var(--danger); }
pre.diff .hunk { color: var(--info); background: var(--surface-3); }
pre.diff .meta { color: var(--faint); }
.path { font: 12.5px var(--mono); color: var(--info); overflow-wrap: anywhere; }
.todos { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 14px; }
.todos li { display: flex; gap: 8px; align-items: baseline; }
.todos .b { width: 14px; flex: none; text-align: center; color: var(--faint); }
.todos .completed { color: var(--muted); text-decoration: line-through; }
.todos .in_progress { color: var(--accent); font-weight: 600; }

.perm-line { font-size: 12.5px; color: var(--muted); margin: -2px auto 10px; display: flex; gap: 6px; align-items: center; }
.perm-line svg { width: 15px; height: 15px; }
.perm-line.allow { color: var(--ok); }
.perm-line.deny { color: var(--danger); }

.result { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--faint); margin: 2px auto 18px; }
.result.err { color: var(--danger); }

/* ---------- Trabajando ---------- */
.working { display: flex; align-items: center; gap: 10px; padding: 6px 18px 8px; font-size: 13px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Aprobaciones ---------- */
.approvals { flex: none; padding: 0 10px; max-height: 62dvh; overflow-y: auto; }
.working, .composer { flex: none; }
.approval {
  max-width: 820px; margin: 0 auto 8px;
  border: 1px solid var(--warn); border-radius: var(--radius);
  background: var(--surface); box-shadow: 0 -6px 24px rgba(0, 0, 0, .25);
  padding: 12px; display: grid; gap: 10px;
}
.approval.q { border-color: var(--info); }
.approval.plan { border-color: var(--accent); }
.approval-head { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.approval-head .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); }
.approval-head svg { color: var(--warn); }
.approval.q .approval-head svg { color: var(--info); }
.approval.plan .approval-head svg { color: var(--accent); }
.approval .reason { font-size: 13px; color: var(--muted); margin: 0; }
.approval .detail { display: grid; gap: 8px; max-height: 38vh; overflow-y: auto; }
.approval .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.approval .actions .wide { grid-column: 1 / -1; }
.approval .more { display: flex; flex-wrap: wrap; gap: 6px; }
.approval textarea { min-height: 70px; resize: vertical; }
.question { display: grid; gap: 8px; }
.question .qh { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--info); }
.question .qt { font-weight: 600; }
.opts { display: grid; gap: 6px; }
.opt {
  text-align: left; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; cursor: pointer; display: grid; gap: 2px;
}
.opt small { color: var(--muted); }
.opt.on { border-color: var(--info); background: rgba(126, 166, 255, .12); }

/* ---------- Composer ---------- */
.composer { border-top: 1px solid var(--border); background: var(--bg); padding: 8px 10px calc(8px + var(--safe-b)); }
.composer > * { max-width: 820px; margin: 0 auto; }
.composer-tools { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; }
.chip-select select {
  width: auto; min-height: 30px; padding: 4px 28px 4px 10px;
  font-size: 12.5px; font-weight: 600; border-radius: 999px;
  background-color: var(--surface-2); color: var(--muted);
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; min-height: 44px; border-radius: 22px; padding: 11px 16px; line-height: 1.4; }

/* ---------- Diálogos ---------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  max-height: 92dvh; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .5); }
dialog.sheet.full { max-width: 900px; height: 92dvh; }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: 20px; }
}
.sheet-body { padding: 14px 16px calc(18px + var(--safe-b)); display: grid; gap: 4px; max-height: 92dvh; overflow-y: auto; }
dialog.full .sheet-body { height: 100%; grid-template-rows: auto 1fr; }
.sheet-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; position: sticky; top: -14px; background: var(--surface); padding-top: 4px; z-index: 1; }
.sheet-head h2 { flex: 1; font-size: 18px; margin: 0; }
.card { background: var(--surface-2); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p { margin: 0 0 10px; }
.card input { background: var(--surface); }
.clone { margin-top: 14px; }
.clone summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 6px 0; }
.clone .row { margin: 8px 0 6px; }
.confirm { background: var(--danger-soft); border-radius: 12px; padding: 12px; margin-top: 8px; }
.confirm p { margin: 0 0 10px; }
#dlg-chat .btn.block { margin-top: 10px; }

.changes { overflow-y: auto; }
.file-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 6px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; color: var(--text); font: 13.5px var(--mono); text-align: left; cursor: pointer;
}
.file-row:hover { background: var(--surface-2); }
.file-row .code { width: 26px; flex: none; font-weight: 700; color: var(--warn); }
.file-row .code.A, .file-row .code.Q { color: var(--ok); }
.file-row .code.D { color: var(--danger); }
.file-row .f { flex: 1; overflow-wrap: anywhere; }
.changes pre.diff { max-height: none; border-radius: 0; background: transparent; }

/* ---------- Aviso flotante ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
.toast.error { background: var(--danger); color: #fff; border-color: transparent; }

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