:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --ink: #17211d;
  --muted: #68756f;
  --line: #e2ded3;
  --accent: #0f5c4a;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe8;
  --danger: #c2412d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 8px 24px rgba(20, 30, 25, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513;
    --surface: #18201d;
    --ink: #e9efec;
    --muted: #93a19b;
    --line: #27322e;
    --accent: #4fc3a1;
    --accent-ink: #06231b;
    --accent-soft: #1c332c;
    --danger: #ff8a75;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
h2 { font-size: 1rem; margin: 0; font-weight: 650; }
.muted { color: var(--muted); font-size: .875rem; }
[hidden] { display: none !important; }

/* Top bar */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tab {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: .9rem; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.tab.active { background: var(--accent); color: var(--accent-ink); }

main { flex: 1; min-height: 0; width: 100%; max-width: 1200px; margin: 0 auto; padding: 16px 20px; display: flex; }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; gap: 14px; }
.view.active { display: flex; }
#view-historial, #view-ajustes { overflow-y: auto; max-width: 720px; margin: 0 auto; width: 100%; }

.banner {
  background: var(--accent-soft); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: .9rem;
}
.banner a { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; }

/* Modes */
.modes { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.mode {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: .9rem; padding: 7px 14px; border-radius: 999px; cursor: pointer;
}
.mode[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* Panes */
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pane {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.pane.out { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.pane-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 16px 4px; }
.pane textarea {
  flex: 1; min-height: 120px; border: 0; outline: 0; resize: none; background: transparent; color: inherit;
  font: inherit; font-size: 1.05rem; line-height: 1.6; padding: 8px 16px;
}
.pane textarea::placeholder { color: var(--muted); opacity: .8; }
.pane-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 12px 12px; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: .9rem; font-weight: 600; padding: 8px 16px; border-radius: 999px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); padding: 12px 22px; font-size: 1rem; }
.btn:disabled { opacity: .5; cursor: default; }

/* Dock */
.dock {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 4px 0 calc(6px + env(safe-area-inset-bottom));
}
.dock .btn.primary { justify-self: end; }
.dock-hint { color: var(--muted); font-size: .9rem; }
.mic {
  width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .15s ease, background .15s ease;
}
.mic:active { transform: scale(.95); }
.mic.on { background: var(--danger); color: #fff; animation: pulse 1.4s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent); }
  100% { box-shadow: 0 0 0 22px transparent; }
}
@media (prefers-reduced-motion: reduce) { .mic.on { animation: none; } }

/* History */
.list-head { display: flex; justify-content: space-between; align-items: center; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history li {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.history .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; margin-bottom: 6px; }
.history .text { white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.history li.open .text { display: block; }
.history .row { display: flex; gap: 6px; justify-content: flex-end; margin-top: 8px; }

/* Settings */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 600; font-size: .92rem; }
.field input[type=password], .field select, .field textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field small { color: var(--muted); font-size: .8rem; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.help { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-size: .92rem; }
.help summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.help ol { padding-left: 20px; margin: 10px 0; display: flex; flex-direction: column; gap: 6px; }
.help a { color: var(--accent); font-weight: 600; }
.help p { margin: 10px 0 8px; color: var(--muted); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Phones / portrait tablets */
@media (max-width: 760px) {
  .top { padding-left: 14px; padding-right: 14px; }
  .brand span { display: none; }
  main { padding: 12px 14px; }
  .panes { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .dock { grid-template-columns: 1fr auto 1fr; gap: 10px; }
  .dock .btn.primary { padding: 12px 14px; font-size: .92rem; }
  .dock-hint { font-size: .8rem; }
}
