:root {
  --bg: #f5f6fa; --panel: #fff; --text: #1f2430; --muted: #6b7280; --line: #e6e8ef;
  --accent: #4f46e5; --accent-soft: #eef0ff; --accent-text: #3730a3;
  --urgent: #fdecec; --urgent-line: #f2a3a3; --alert: #fff7e6; --alert-line: #f5c26b;
  --top: 56px; --tabbar: 64px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.logo { display: inline-block; flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px; background: url("icon.svg") center / cover; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.dots { fill: currentColor; stroke: none; }

/* Login */
.login { max-width: 340px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.login .logo { width: 64px; height: 64px; border-radius: 18px; }
.login h1 { margin: .6rem 0 .2rem; }
.login form { display: flex; flex-direction: column; gap: .7rem; margin-top: 1.4rem; }
.login input { padding: .8rem; border: 1px solid var(--line); border-radius: 10px; font: inherit; }
.login button { padding: .8rem; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; }
.error { color: #b91c1c; }

/* Barra superior y menú */
.top { position: fixed; inset: 0 0 auto; z-index: 2; display: flex; align-items: center; gap: .6rem; height: calc(var(--top) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 12px 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top h1 { flex: 1; margin: 0; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.icon-button:active { background: var(--bg); }
.menu { position: relative; }
.dropdown { position: absolute; right: 0; top: 44px; min-width: 210px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(16, 24, 40, .14); }
.dropdown button { display: block; width: 100%; padding: .7rem .8rem; border: 0; border-radius: 8px; background: none; text-align: left; }
.dropdown button:active, .dropdown button:hover { background: var(--bg); }
.dropdown form { margin: 0; }

.banner { position: fixed; z-index: 1; top: calc(var(--top) + env(safe-area-inset-top) + 8px); left: 12px; right: 12px; display: flex; align-items: center; gap: .8rem; justify-content: space-between; padding: .8rem 1rem; background: var(--accent-soft); color: var(--accent-text); border-radius: 12px; font-size: .92rem; box-shadow: 0 4px 12px rgba(16, 24, 40, .1); }
.banner button { border: 0; border-radius: 8px; padding: .45rem .9rem; background: var(--accent); color: #fff; }

/* Secciones: entre la barra superior y la inferior */
.screen { min-height: 100%; padding: calc(var(--top) + env(safe-area-inset-top)) 0 calc(var(--tabbar) + env(safe-area-inset-bottom)); }
.screen > main, .toolbar, .filters, .assistants { max-width: 720px; margin-left: auto; margin-right: auto; }

/* Barra inferior */
.tabbar { position: fixed; inset: auto 0 0; z-index: 2; display: flex; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--panel); border-top: 1px solid var(--line); }
.tabbar a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .72rem; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
.tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #dc2626; color: #fff; font-size: .68rem; line-height: 18px; text-align: center; }

.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: .3rem .8rem; font-size: .85rem; white-space: nowrap; }
.chip.on { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.empty { text-align: center; margin: 2.5rem 16px; }

/* Chat */
.chat { display: flex; flex-direction: column; height: 100%; }
.assistants { display: flex; gap: .4rem; overflow-x: auto; padding: 10px 12px 0; width: 100%; }
.conversation { flex: 1; overflow-y: auto; width: 100%; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: .5rem; }
.bubble { max-width: 85%; padding: .55rem .8rem .4rem; border-radius: 16px; line-height: 1.4; }
.bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble b { display: block; font-size: .78rem; color: var(--accent-text); }
.bubble .usage { display: block; margin-top: 4px; font-size: .68rem; color: var(--muted); }
.bubble time { display: block; text-align: right; font-size: .68rem; opacity: .65; margin-top: 2px; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.typing { color: var(--muted); font-style: italic; padding-bottom: .55rem; }
.composer { position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: .5rem; width: 100%; max-width: 720px; margin: 0 auto; padding: 8px 12px; background: var(--bg); }
.composer textarea { flex: 1; resize: none; max-height: 140px; padding: .65rem .9rem; border: 1px solid var(--line); border-radius: 20px; font: inherit; line-height: 1.35; background: var(--panel); }
.composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.composer button { display: grid; place-items: center; flex-shrink: 0; width: 42px; height: 42px; border: 0; border-radius: 50%; background: var(--accent); color: #fff; }

/* Informes */
.list { padding: 8px 12px 24px; }
.group h2 { margin: 1.2rem 4px .5rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .5rem; padding: .85rem 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; color: var(--text); text-decoration: none; }
.card span { font-size: .82rem; }
.report { max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }
.report h2 { margin: .8rem 0 .2rem; font-size: 1.3rem; }
.md { line-height: 1.55; }
.md h2 { font-size: 1.05rem; margin: 1.3rem 0 .4rem; }
.md h3 { font-size: .98rem; margin: 1rem 0 .3rem; }
.md ul, .md ol { padding-left: 1.3rem; }
.md li { margin: .25rem 0; }
.md .task-list-item { list-style: none; margin-left: -1.3rem; }
.md .task-list-item input { margin-right: .5rem; transform: scale(1.15); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: .35rem .6rem; }
.md blockquote { margin: .8rem 0; padding: .3rem 1rem; border-left: 3px solid var(--accent); color: var(--muted); }

/* Notificaciones */
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; padding: 12px 12px 0; }
.tabs { display: flex; gap: .3rem; background: var(--line); padding: 3px; border-radius: 10px; }
.tab { border: 0; background: none; padding: .35rem .8rem; border-radius: 8px; color: var(--muted); font-size: .92rem; }
.tab.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }
.count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; text-align: center; }
.actions { display: flex; gap: .9rem; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: .88rem; }
.filters { display: flex; gap: .4rem; overflow-x: auto; padding: 10px 12px 0; }
.feed { padding: 12px 12px 24px; display: flex; flex-direction: column; gap: .6rem; }
.message { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: .75rem .9rem; opacity: .72; }
.message.unread { opacity: 1; border-left: 4px solid var(--accent); cursor: pointer; }
.message header { display: flex; align-items: center; gap: .6rem; font-weight: 600; font-size: .9rem; }
.message header span { flex: 1; }
.message time { color: var(--muted); font-weight: 400; font-size: .8rem; white-space: nowrap; }
.message p { margin: .35rem 0 0; white-space: pre-wrap; line-height: 1.45; }
.message.urgent { background: var(--urgent); border-color: var(--urgent-line); }
.message.alert { background: var(--alert); border-color: var(--alert-line); }
.dismiss { border: 0; background: none; color: var(--muted); padding: 0 .2rem; line-height: 1; }
