:root {
    --bg: #f0f2f5;
    --bg-panel: #ffffff;
    --bg-elev: #f7f8fa;
    --bg-input: #f4f5f7;
    --border: #d9dde4;
    --border-strong: #c4c9d4;
    --text: #1a2236;
    --text-dim: #5a6578;
    --text-muted: #8b95a8;
    --accent: #1a6fc4;
    --accent-2: #0d8fd4;
    --accent-soft: rgba(26, 111, 196, 0.08);
    --green: #1a8a4a;
    --red: #d4362e;
    --amber: #b07d14;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
    --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
    --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

html {
    overscroll-behavior: none;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.5;
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(800px 400px at 92% -10%, rgba(26, 111, 196, 0.04), transparent 70%),
        radial-gradient(600px 340px at 2% 110%, rgba(13, 143, 212, 0.03), transparent 70%);
}

button, select, textarea, input { font-family: inherit; font-size: inherit; color: inherit; }

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

::selection { background: rgba(26, 111, 196, 0.2); }

:focus-visible { outline: 2px solid rgba(26, 111, 196, 0.5); outline-offset: 1px; }

/* ================= layout ================= */

.app {
    position: relative;
    display: grid;
    height: 100%;
    padding: 12px;
    gap: 12px;
    overflow: hidden;
    grid-template-columns: minmax(0, 1fr) clamp(210px, 22vw, 330px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
        "topbar topbar"
        "center console";
}

.app.console-hidden { grid-template-columns: minmax(0, 1fr); }

.panel,
.topbar,
.console {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.topbar { grid-area: topbar; }
.panel-center { grid-area: center; }

/* ================= topbar ================= */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 16px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-img {
    height: 38px;
    width: auto;
    object-fit: contain;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.brand-name {
    font-weight: 500;
    letter-spacing: 2px;
    font-size: 16px;
    color: #3a4252;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-sub {
    font-weight: 600;
    letter-spacing: 3px;
    font-size: 9px;
    color: #1a6fc4;
    text-transform: uppercase;
}

.brand-version {
    color: var(--text-muted);
    font-family: var(--mono);
    font-size: 10.5px;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1px 7px;
    flex: 0 0 auto;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; flex: 0 1 auto; min-width: 0; }

.project-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 11.5px;
    color: #1a5fa8;
    background: rgba(26, 111, 196, 0.06);
    border: 1px solid rgba(26, 111, 196, 0.2);
    border-radius: 20px;
    padding: 5px 12px;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 0 0 auto;
}

.project-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px rgba(63, 185, 80, 0.8);
    flex: 0 0 auto;
}

.field { display: flex; align-items: center; gap: 8px; min-width: 0; }

.field-label {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    flex: 0 0 auto;
}

.select {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    min-width: 158px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.select:hover { border-color: #a0a8b8; }
.select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26, 111, 196, 0.1); }

/* ================= panel ================= */

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}

.panel-title {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    color: var(--text-dim);
}

.badge {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-dim);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2px 9px;
}

.muted { color: var(--text-muted); font-size: 11px; }

/* ================= pestañas ================= */

.tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 7px 8px 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex: 0 0 auto;
    min-height: 44px;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs:empty { display: none; }

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 11px;
    height: 32px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    cursor: pointer;
    white-space: nowrap;
    max-width: 220px;
    transition: background 0.14s, color 0.14s, border-color 0.14s;
    margin-bottom: 4px;
}

.tab:hover { background: var(--bg-elev); color: var(--text); }

.tab.active {
    background: var(--bg-input);
    border-color: var(--border-strong);
    color: var(--text);
}

.tab .tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-family: var(--mono);
}

.tab .tab-close {
    color: var(--text-muted);
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0 3px;
    border-radius: 4px;
    line-height: 1;
    font-size: 14px;
}

.tab .tab-close:hover { color: var(--red); background: rgba(248, 81, 73, 0.12); }

/* ================= vistas ================= */

.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

/* ================= chat ================= */

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-right: 18px;
    flex: 0 0 auto;
    min-height: 44px;
}

.panel-head .tabs {
    border-bottom: none;
    flex: 1 1 auto;
    min-width: 0;
}

.chat-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    white-space: nowrap;
}

.chat-messages {
    flex: 1 1 auto;
    overflow: auto;
    padding: 22px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.msg {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 820px;
    animation: msg-in 0.22s ease both;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.msg-head { display: flex; align-items: center; gap: 9px; }

.avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 17px;
    line-height: 1;
    background: var(--bg-elev);
    border: 1px solid var(--border);
}

.avatar-assistant {
    background: linear-gradient(135deg, #2b3440, #12171d);
    border-color: transparent;
    box-shadow: 0 3px 12px rgba(46, 123, 214, 0.35);
    padding: 3px;
    overflow: hidden;
}

.avatar-assistant img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.avatar-assistant.avatar-fallback {
    padding: 0;
    color: #fff;
    font-size: 17px;
}

.avatar-system { background: transparent; border-style: dashed; border-color: var(--border-strong); }

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

.msg-body {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 4px 12px 12px 12px;
    padding: 12px 15px;
    line-height: 1.68;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg.user { align-self: flex-end; align-items: flex-end; }

.msg.user .msg-body {
    background: linear-gradient(135deg, #e8f0fc, #dbe7f8);
    border-color: #c4d8f0;
    border-radius: 12px 4px 12px 12px;
}

.msg.system .msg-body {
    background: transparent;
    border-style: dashed;
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 12px;
    border-radius: 12px;
}

.msg-body .md-code-wrap {
    margin: 12px 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #f4f5f7;
}

.msg-body .md-lang {
    display: block;
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border);
    padding: 5px 11px;
}

.msg-body .md-code {
    margin: 0;
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
}

.msg-body .md-inline {
    font-family: var(--mono);
    font-size: 12px;
    background: rgba(46, 123, 214, 0.14);
    border-radius: 5px;
    padding: 1.5px 6px;
}

.msg-body .md-h2, .msg-body .md-h3, .msg-body .md-h4 {
    display: block;
    font-weight: 650;
    color: var(--text);
    margin: 6px 0 3px;
}

.msg-body .md-h2 { font-size: 16px; }
.msg-body .md-h3 { font-size: 14.5px; }
.msg-body .md-h4 { font-size: 13.5px; }

.msg-body .md-table-wrap {
    margin: 12px 0;
    overflow-x: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    -webkit-overflow-scrolling: touch;
}

.msg-body .md-table { border-collapse: collapse; width: 100%; font-size: 12px; }

.msg-body .md-table th,
.msg-body .md-table td {
    text-align: left;
    padding: 7px 11px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    white-space: nowrap;
}

.msg-body .md-table th {
    background: #eef1f6;
    color: #3a4252;
    font-weight: 700;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.msg-body .md-table tr:last-child td { border-bottom: none; }
.msg-body .md-table td { transition: background 0.15s ease; }
.msg-body .md-table tbody tr:hover td { background: #f2f4f8; }

.msg-error { color: #d4362e; font-family: var(--mono); font-size: 12px; }

.msg-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-tools:empty { display: none; }

.tool-chip {
    display: inline-flex;
    align-items: center;
    font-family: var(--mono);
    font-size: 10.5px;
    color: #1a5fa8;
    background: rgba(26, 111, 196, 0.06);
    border: 1px solid rgba(26, 111, 196, 0.2);
    border-radius: 20px;
    padding: 3px 11px;
    max-width: 100%;
}

.tool-chip.err {
    color: #d4362e;
    background: rgba(212, 54, 46, 0.06);
    border-color: rgba(212, 54, 46, 0.25);
}

.speak-btn {
    margin-left: auto;
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 3px 7px;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.speak-btn:hover { background: var(--bg-elev); color: var(--text); border-color: var(--border-strong); }

.speak-btn.speaking {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
    animation: mic-pulse 1.4s infinite;
}

#btn-auto-speak.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.chip-icon { font-size: 11px; line-height: 1; margin-right: 6px; }
.chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thinking {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 2px;
    color: var(--text-dim);
    font-size: 12.5px;
    animation: msg-in 0.2s ease both;
}

.thinking[hidden] { display: none; }

.thinking-dots { display: inline-flex; gap: 4px; }

.thinking-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: thinking-dot 1.2s infinite ease-in-out;
}

.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

.thinking-label { font-weight: 500; }

.msg-body[hidden] { display: none; }

@keyframes thinking-dot {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.chat-form {
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    background: rgba(0, 0, 0, 0.12);
}

.chat-input {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 11px 14px;
    resize: none;
    outline: none;
    line-height: 1.55;
    max-height: 160px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input::placeholder { color: #8b95a8; }
.chat-input:hover { border-color: #a0a8b8; }
.chat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26, 111, 196, 0.1); }
.chat-input:disabled { opacity: 0.6; }

.mic-btn {
    position: relative;
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    font-size: 16px;
    line-height: 1;
    padding: 9px 13px;
}

.mic-btn:hover { color: var(--text); border-color: #a0a8b8; }

.mic-btn.listening {
    color: #fff;
    border-color: var(--red);
    background: var(--red);
    animation: mic-pulse 1.4s infinite;
    transform: scale(1.06);
}

.mic-btn { user-select: none; }

.mic-dot { display: none; }

.mic-btn.listening .mic-dot {
    display: block;
    position: absolute;
    top: 5px;
    right: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--red);
    box-shadow: 0 0 8px rgba(248, 81, 73, 0.9);
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.45); }
    50% { box-shadow: 0 0 0 7px rgba(248, 81, 73, 0); }
}

.chat-form-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chat-form-buttons { display: flex; align-items: center; gap: 8px; }

/* ================= imágenes adjuntas ================= */

.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 0 9px;
}

.chat-attachments[hidden] { display: none; }

.attach-item {
    position: relative;
    width: 74px;
    height: 74px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    overflow: hidden;
    flex: 0 0 auto;
}

.attach-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attach-item .attach-name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 2px 5px;
    font-family: var(--mono);
    font-size: 9px;
    color: #d5dbe6;
    background: rgba(5, 7, 11, 0.78);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attach-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 19px;
    height: 19px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(5, 7, 11, 0.82);
    color: #ffb4ae;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.attach-remove:hover { background: var(--red); color: #fff; }

.attach-loading {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--text-dim);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 11px;
}

/* Imágenes ya enviadas, dentro de la burbuja del usuario */
.msg-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 9px;
}

.msg-attachments a { display: block; line-height: 0; }

.msg-attachments img {
    max-width: 190px;
    max-height: 190px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    display: block;
}

.msg-attachments .msg-attach-name {
    display: block;
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-form.dragging {
    outline: 2px dashed var(--accent);
    outline-offset: -6px;
    border-radius: var(--radius);
}

#chat-hint {
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ================= editor ================= */

.file-meta {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.12);
}

.file-title {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta .btn { margin-left: auto; flex: 0 0 auto; }
.file-body { flex: 1 1 auto; overflow: auto; min-height: 0; }

.code-wrap { display: flex; align-items: flex-start; min-height: 100%; }

.gutter {
    flex: 0 0 auto;
    padding: 14px 12px 14px 16px;
    text-align: right;
    color: #3f4757;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.62;
    user-select: none;
    border-right: 1px solid var(--border);
    white-space: pre;
}

.code {
    margin: 0;
    padding: 14px 18px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.62;
    white-space: pre;
    flex: 1 1 auto;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 12px;
    padding: 30px;
    text-align: center;
}

.empty-state.error { color: var(--red); }

/* ================= consola ================= */

.console {
    grid-area: console;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.console-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
}

.console-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    color: inherit;
}

.console-toggle:hover { background: var(--bg-elev); }

.console-toggle .caret {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.18s ease;
}

.app.console-hidden .console-toggle .caret { transform: rotate(180deg); }

#btn-activity { padding: 8px 13px; }
#btn-activity .status-dot { width: 9px; height: 9px; box-shadow: none; }

.console-actions { display: flex; align-items: center; gap: 10px; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    box-shadow: 0 0 0 3px rgba(92, 102, 117, 0.15);
    transition: background 0.2s, box-shadow 0.2s;
    flex: 0 0 auto;
}

.status-dot.busy { background: var(--amber); box-shadow: 0 0 0 3px rgba(210, 153, 34, 0.18); animation: pulse 1.3s infinite; }
.status-dot.ok { background: var(--green); box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.16); }
.status-dot.err { background: var(--red); box-shadow: 0 0 0 3px rgba(248, 81, 73, 0.18); }

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

.console-body {
    flex: 1 1 auto;
    overflow: auto;
    padding: 10px 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.7;
    min-height: 0;
}

.log-line { display: flex; gap: 9px; align-items: baseline; }
.log-time { color: #8b95a8; flex: 0 0 auto; font-size: 11px; }
.log-icon { flex: 0 0 auto; font-size: 10px; line-height: 1; }
.log-line .log-msg { white-space: pre-wrap; word-break: break-word; }
.log-line.info .log-msg { color: var(--text-dim); }
.log-line.ok .log-msg { color: #1a8a4a; }
.log-line.warn .log-msg { color: #b07d14; }
.log-line.err .log-msg { color: #d4362e; }

/* ================= gráficas y reportes ================= */

.msg-artifacts { display: flex; flex-direction: column; gap: 12px; }
.msg-artifacts:empty { display: none; }

.artifact {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.artifact-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 13px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.015);
}

.artifact-title { font-size: 12.5px; font-weight: 600; color: var(--text); }
.artifact-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.artifact-badge {
    font-family: var(--mono);
    font-size: 9.5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--accent);
    background: rgba(26, 111, 196, 0.08);
    border: 1px solid rgba(26, 111, 196, 0.2);
    border-radius: 20px;
    padding: 2px 9px;
}

.artifact-canvas { position: relative; height: 300px; padding: 14px; }

.artifact-preview { background: var(--bg-input); border-bottom: 1px solid var(--border); }

.artifact-frame {
    display: block;
    width: 100%;
    height: 540px;
    border: 0;
    background: #fff;
}

.artifact-img {
    display: block;
    max-width: 100%;
    max-height: 540px;
    margin: 0 auto;
    padding: 12px;
}

.artifact-foot {
    padding: 8px 13px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--text-muted);
    word-break: break-word;
}

.artifact-file { display: flex; align-items: center; gap: 14px; padding: 13px; }
.artifact-icon { font-size: 22px; line-height: 1; flex: 0 0 auto; }
.artifact-info { flex: 1 1 auto; min-width: 0; }
.artifact-info .artifact-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.artifact-meta { font-size: 11px; color: var(--text-muted); font-family: var(--mono); margin-top: 3px; }

/* ================= modal ================= */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    backdrop-filter: blur(3px);
    animation: fade-in 0.15s ease;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-backdrop[hidden] { display: none; }

.modal {
    width: min(580px, 100%);
    max-height: 100%;
    margin: auto;
    background: #ffffff;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modal-in 0.18s ease;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px) scale(0.99); }
    to { opacity: 1; transform: none; }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.modal-body { padding: 18px; overflow: auto; display: flex; flex-direction: column; gap: 15px; overscroll-behavior: contain; }

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 18px;
    border-top: 1px solid var(--border);
    background: #f7f8fa;
    flex-wrap: wrap;
}

.form-row { display: flex; flex-direction: column; gap: 7px; }

.form-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-dim);
}

.input {
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    outline: none;
    width: 100%;
    font-family: var(--mono);
    font-size: 12.5px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:hover { border-color: #a0a8b8; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26, 111, 196, 0.1); }
.input[readonly] { background: var(--bg-elev); color: var(--text-dim); cursor: default; }
.input[readonly]:hover { border-color: var(--border-strong); }
.input[readonly]:focus { border-color: var(--border-strong); box-shadow: none; }

.form-help { font-size: 11px; color: var(--text-muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

.form-section-title {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    color: var(--accent);
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.form-section-title:first-child { border-top: none; padding-top: 0; }

.modal-subactions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-subactions .btn { padding: 8px 13px; font-size: 12px; }

.form-note {
    margin: 0;
    font-size: 11.5px;
    line-height: 1.65;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 13px;
}

.form-note code {
    font-family: var(--mono);
    background: var(--bg-elev);
    border-radius: 4px;
    padding: 1.5px 6px;
}

/* ================= botones ================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--bg-elev);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 15px;
    cursor: pointer;
    color: var(--text);
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.btn:hover { border-color: #a0a8b8; background: #eef1f6; }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: linear-gradient(135deg, #1a6fc4, #0d8fd4);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(26, 111, 196, 0.22);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #1663b0, #0b7fbe);
    box-shadow: 0 4px 14px rgba(26, 111, 196, 0.32);
}

.btn-danger {
    background: transparent;
    border-color: rgba(212, 54, 46, 0.35);
    color: #d4362e;
}

.btn-danger:hover { background: rgba(212, 54, 46, 0.06); border-color: var(--red); }

.btn-icon { padding: 8px 11px; font-size: 15px; line-height: 1; flex: 0 0 auto; }

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-dim);
    padding: 3px 9px;
    font-size: 11px;
}

.btn-ghost:hover { background: var(--bg-elev); color: var(--text); border-color: transparent; }

.btn:disabled { opacity: 0.55; cursor: default; transform: none; box-shadow: none; }

/* ================= consola: derecha en escritorio, deslizante en móvil ================= */

.console-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(4, 6, 10, 0.5);
    z-index: 44;
}

.console-backdrop[hidden] { display: none; }

@media (min-width: 901px) {
    .app.console-hidden .console { display: none; }
    .console-backdrop { display: none !important; }
}

@media (max-width: 900px) {
    .brand-name { display: none; }
    .field-label { display: none; }
    .select { min-width: 0; }

    .app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        grid-template-areas:
            "topbar"
            "center";
    }

    .console {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(44vw, 300px);
        min-width: 210px;
        z-index: 45;
        border-radius: 12px 0 0 12px;
        transform: translateX(103%);
        transition: transform 0.24s ease;
        box-shadow: -20px 0 46px rgba(0, 0, 0, 0.55);
    }

    .app:not(.console-hidden) .console { transform: none; }
}

/* ================= móvil ================= */

@media (max-width: 640px) {
    .app {
        padding: 0;
        gap: 0;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
        grid-template-areas:
            "topbar"
            "center";
    }

    .panel, .topbar, .console {
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    .topbar {
        padding: 9px 12px;
        gap: 8px;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .brand-version { display: none; }
    .topbar-actions { flex: 1; gap: 8px; }
    .field { flex: 1; min-width: 0; }
    .select { width: 100%; padding: 9px 10px; font-size: 13px; }
    .btn-icon { padding: 9px 12px; }

    .chat-messages { padding: 16px 12px 6px; gap: 16px; }
    .msg { max-width: 100%; }
    .msg-body { padding: 11px 13px; font-size: 13.5px; border-radius: 4px 12px 12px 12px; }
    .msg.user .msg-body { border-radius: 12px 4px 12px 12px; }

    .msg-body .md-table { font-size: 12.5px; }
    .msg-body .md-table th, .msg-body .md-table td { padding: 8px 10px; }
    .msg-body .md-code { font-size: 11.5px; }

    .chat-form { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
    .chat-input { font-size: 16px; }
    .chat-form-actions { gap: 8px; }
    #chat-hint { display: none; }
    .btn { padding: 9px 16px; }
    .btn-primary { padding: 9px 20px; }

    /* En móvil: Enviar a la izquierda y el micrófono al extremo derecho. */
    .chat-form-buttons { flex: 1; gap: 8px; }
    #btn-send { order: 1; flex: 1; }
    #btn-stop { order: 2; }
    #btn-mic { order: 3; padding: 9px 14px; }
    #btn-attach { order: 0; padding: 9px 14px; }

    .tabs { padding: 6px 6px 0; min-height: 40px; }
    .tab { max-width: 160px; }
    .tab .tab-label { max-width: 110px; }

    .console { border-radius: 12px 0 0 12px; }
    .console-body { font-size: 11.5px; }
    .console-head { padding: 8px 10px; }

    .artifact-canvas { height: 240px; padding: 10px; }
    .artifact-frame { height: 420px; }
    .artifact-img { max-height: 420px; padding: 8px; }
    .modal { border-radius: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .modal-foot { flex-direction: column; align-items: stretch; }
    .modal-foot .chat-form-buttons { flex-wrap: wrap; }
    .modal-foot .chat-form-buttons .btn { flex: 1 1 auto; }
}

/* ================= usuario y conversaciones ================= */

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 11.5px;
    color: #1a8a4a;
    background: rgba(26, 138, 74, 0.06);
    border: 1px solid rgba(26, 138, 74, 0.2);
    border-radius: 20px;
    padding: 5px 12px;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 0 0 auto;
}

.user-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px rgba(26, 138, 74, 0.6);
    flex: 0 0 auto;
}

.user-chip.is-off {
    color: #d4362e;
    background: rgba(212, 54, 46, 0.06);
    border-color: rgba(212, 54, 46, 0.2);
}

.user-chip.is-off::before {
    background: var(--red);
    box-shadow: 0 0 6px rgba(248, 81, 73, 0.75);
}

.modal-narrow { width: min(430px, 100%); }

.conv-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.conv-list { display: flex; flex-direction: column; gap: 8px; }

.conv-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.conv-item:hover { border-color: var(--border-strong); background: var(--bg-elev); }

.conv-item.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
}

.conv-icon { font-size: 15px; line-height: 1.35; flex: 0 0 auto; }
.conv-main { flex: 1 1 auto; min-width: 0; }
.conv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { font-size: 10.5px; color: var(--text-muted); font-family: var(--mono); margin-top: 3px; }

.conv-preview {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 5px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.conv-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.conv-actions .btn { padding: 5px 9px; font-size: 11px; }

.conv-empty {
    color: var(--text-muted);
    font-size: 12px;
    padding: 14px;
    text-align: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
    .user-chip { display: none; }
}

/* ================= login ================= */

.modal-login {
    width: min(400px, 100%);
    border-radius: 16px;
    overflow: hidden;
}

.login-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 30px 24px 22px;
    background: linear-gradient(180deg, #f4f8fd 0%, #ffffff 100%);
    border-bottom: 1px solid var(--border);
}

.login-logo {
    height: 50px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.login-tagline {
    margin: 0;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #6b7a90;
    text-align: center;
}

.login-body {
    padding: 22px 24px 8px;
    gap: 15px;
}

.input-login {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--sans);
    font-size: 14px;
    border-radius: 9px;
    background: #ffffff;
}

.login-status {
    display: block;
    min-height: 16px;
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
}

.login-status:empty { display: none; }

.modal-foot-login {
    padding: 12px 24px 22px;
    background: #ffffff;
    border-top: none;
    justify-content: stretch;
}

.btn-login {
    width: 100%;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 9px;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 8px rgba(26, 111, 196, 0.25);
}

.btn-login:hover {
    box-shadow: 0 4px 14px rgba(26, 111, 196, 0.35);
}

[data-theme="dark"] .login-hero {
    background: linear-gradient(180deg, #131b2b 0%, var(--bg-panel) 100%);
}

[data-theme="dark"] .login-tagline { color: #7e8fa6; }
[data-theme="dark"] .input-login { background: var(--bg-input); }
[data-theme="dark"] .modal-foot-login { background: var(--bg-panel); }

/* ================= theme toggle ================= */

#btn-theme {
    font-size: 16px;
    line-height: 1;
}

/* ================= light theme ================= */

[data-theme="dark"] {
    --bg: #0a0e18;
    --bg-panel: #0f1520;
    --bg-elev: #151c2a;
    --bg-input: #0b1019;
    --border: #1c2538;
    --border-strong: #263048;
    --text: #d8e2f0;
    --text-dim: #7e8fa6;
    --text-muted: #4e5d75;
    --accent: #4a9af5;
    --accent-2: #2e7bd6;
    --accent-soft: rgba(74, 154, 245, 0.13);
    --green: #3fb950;
    --red: #f85149;
    --amber: #d29922;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 8px 24px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] body::before {
    background:
        radial-gradient(800px 400px at 92% -10%, rgba(74, 154, 245, 0.12), transparent 70%),
        radial-gradient(600px 340px at 2% 110%, rgba(46, 123, 214, 0.08), transparent 70%);
}

[data-theme="dark"] .panel,
[data-theme="dark"] .topbar,
[data-theme="dark"] .console {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 130px), var(--bg-panel);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #232b3a; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #33405a; }

[data-theme="dark"] ::selection { background: rgba(74, 154, 245, 0.35); }
[data-theme="dark"] :focus-visible { outline-color: rgba(74, 154, 245, 0.6); }

[data-theme="dark"] .msg.user .msg-body {
    background: linear-gradient(135deg, rgba(74, 154, 245, 0.22), rgba(46, 123, 214, 0.14));
    border-color: rgba(74, 154, 245, 0.4);
    color: #d8e2f0;
}

[data-theme="dark"] .msg.assistant .msg-body {
    background: var(--bg-elev);
    border-color: var(--border);
    color: #d8e2f0;
}

[data-theme="dark"] .msg-body .md-code-wrap { background: #0a0d14; }

[data-theme="dark"] .msg-body .md-table th {
    background: rgba(255, 255, 255, 0.04);
    color: #7e8fa6;
}

[data-theme="dark"] .msg-body .md-table tbody tr:hover td { filter: brightness(1.22); }

[data-theme="dark"] .msg-error { color: #ff9a94; }

[data-theme="dark"] .tool-chip {
    color: #c0b5ff;
    background: rgba(74, 154, 245, 0.11);
    border-color: rgba(74, 154, 245, 0.32);
}

[data-theme="dark"] .tool-chip.err {
    color: #ff9a94;
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.35);
}

[data-theme="dark"] .user-chip {
    color: #a9e3bb;
    background: rgba(63, 185, 80, 0.11);
    border-color: rgba(63, 185, 80, 0.3);
}

[data-theme="dark"] .user-chip::before { box-shadow: 0 0 6px rgba(63, 185, 80, 0.8); }

[data-theme="dark"] .user-chip.is-off {
    color: #ffb4ae;
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.32);
}

[data-theme="dark"] .chat-input {
    background: var(--bg-input);
    border-color: var(--border-strong);
    color: #d8e2f0;
}

[data-theme="dark"] .chat-input::placeholder { color: #4e5d75; }
[data-theme="dark"] .chat-input:hover { border-color: #3a4560; }
[data-theme="dark"] .chat-input:focus { box-shadow: 0 0 0 3px rgba(74, 154, 245, 0.14); }

[data-theme="dark"] .input {
    background: var(--bg-input);
    border-color: var(--border-strong);
    color: #d8e2f0;
}

[data-theme="dark"] .input:hover { border-color: #3a4560; }
[data-theme="dark"] .input:focus { box-shadow: 0 0 0 3px rgba(74, 154, 245, 0.14); }

[data-theme="dark"] .modal {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 120px), var(--bg-panel);
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .modal-backdrop { background: rgba(4, 6, 10, 0.74); }
[data-theme="dark"] .modal-foot { background: rgba(0, 0, 0, 0.2); }

[data-theme="dark"] .console {
    background: var(--bg-panel);
    border-color: var(--border);
}

[data-theme="dark"] .console-body { color: #d8e2f0; }

[data-theme="dark"] .log-time { color: #3f4757; }
[data-theme="dark"] .log-line.ok .log-msg { color: #7ee787; }
[data-theme="dark"] .log-line.warn .log-msg { color: #e3b341; }
[data-theme="dark"] .log-line.err .log-msg { color: #ff9a94; }

[data-theme="dark"] .badge {
    background: rgba(74, 154, 245, 0.1);
    color: #7ab4f5;
    border-color: rgba(74, 154, 245, 0.3);
}

[data-theme="dark"] .project-chip {
    color: #7ab4f5;
    background: rgba(74, 154, 245, 0.1);
    border-color: rgba(74, 154, 245, 0.28);
}

[data-theme="dark"] .btn:hover { border-color: #3f4a63; background: #1d2330; }

[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, #4a9af5, #2e7bd6);
    box-shadow: 0 3px 14px rgba(74, 154, 245, 0.32);
}

[data-theme="dark"] .btn-primary:hover {
    background: linear-gradient(135deg, #5fa8f8, #3f8ae0);
    box-shadow: 0 5px 18px rgba(74, 154, 245, 0.42);
}

[data-theme="dark"] .btn-danger {
    border-color: rgba(248, 81, 73, 0.45);
    color: #ff9a94;
}

[data-theme="dark"] .btn-danger:hover { background: rgba(248, 81, 73, 0.13); }

[data-theme="dark"] .select:hover { border-color: #3a4560; }
[data-theme="dark"] .select:focus { box-shadow: 0 0 0 3px rgba(74, 154, 245, 0.16); }

/* ================= login en móvil ================= */

@media (max-width: 640px) {
    .modal-backdrop {
        padding: 16px;
        align-items: center;
    }

    .modal-login {
        width: 100%;
        max-width: 100%;
        border-radius: 16px;
    }

    .login-hero { padding: 26px 20px 20px; gap: 8px; }
    .login-logo { height: 44px; }
    .login-tagline { font-size: 10px; letter-spacing: 1.2px; }

    .login-body { padding: 20px 20px 6px; gap: 14px; }

    .input-login { padding: 13px 14px; font-size: 16px; }

    .modal-foot-login { padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); }

    .btn-login { padding: 14px 24px; font-size: 15px; }
}

/* ================= sweetalert ================= */

.swal2-popup.swal-app-popup {
    font-family: var(--sans);
    border-radius: 14px;
    border: 1px solid var(--border-strong);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
    padding: 24px 22px 20px;
}

.swal2-title.swal-app-title {
    font-size: 17px;
    font-weight: 650;
    padding: 0;
    margin-bottom: 6px;
}

.swal2-html-container {
    font-size: 13.5px;
    line-height: 1.6;
    margin: 6px 0 4px;
}

.swal2-actions {
    gap: 10px;
    margin-top: 18px;
}

.swal2-confirm.swal-app-confirm,
.swal2-cancel.swal-app-cancel {
    font-family: var(--sans);
    font-size: 13.5px;
    font-weight: 600;
    border-radius: 9px;
    padding: 10px 22px;
    box-shadow: none;
}

.swal2-confirm.swal-app-confirm:focus,
.swal2-cancel.swal-app-cancel:focus {
    box-shadow: 0 0 0 3px rgba(26, 111, 196, 0.2);
}

.swal2-cancel.swal-app-cancel {
    border: 1px solid var(--border-strong);
    color: var(--text);
}

.swal2-input.swal-app-input {
    font-family: var(--sans);
    font-size: 14px;
    border-radius: 9px;
    border: 1px solid var(--border-strong);
    box-shadow: none;
}

.swal2-input.swal-app-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 111, 196, 0.1);
}

.swal2-icon.swal2-warning {
    border-color: #d49b2a;
    color: #d49b2a;
}

.swal2-icon.swal2-error {
    border-color: var(--red);
    color: var(--red);
}

.swal2-icon.swal2-info {
    border-color: var(--accent);
    color: var(--accent);
}

.swal2-icon {
    margin: 4px auto 16px;
}

@media (max-width: 640px) {
    .swal2-popup.swal-app-popup {
        width: calc(100% - 32px);
        padding: 22px 18px 18px;
    }

    .swal2-title.swal-app-title { font-size: 16px; }

    .swal2-actions { width: 100%; }

    .swal2-confirm.swal-app-confirm,
    .swal2-cancel.swal-app-cancel {
        flex: 1 1 auto;
        padding: 12px 18px;
    }
}

/* ---------------- formulario de campos dentro del chat ---------------- */

.artifact-fields {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-panel);
    overflow: hidden;
}

.artifact-fields .artifact-body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fields-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.fields-hint {
    margin: 0;
    font-size: 11.5px;
    color: var(--text-muted);
}

.fields-date input:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.fields-date {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fields-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

.fields-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.fields-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fields-count {
    font-size: 11.5px;
    color: var(--text-muted);
    font-family: var(--mono);
}

.btn-mini {
    padding: 4px 10px;
    font-size: 11.5px;
    border-radius: var(--radius-sm);
}

.fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 2px 10px;
    max-height: 260px;
    overflow-y: auto;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
}

.fields-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12.5px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}

.fields-item:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.fields-item input[type="checkbox"] {
    margin: 0;
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--accent);
    flex: 0 0 auto;
}

.fields-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.fields-status {
    font-size: 12px;
    color: var(--text-muted);
    min-height: 16px;
}


/* ================= dashboard ================= */

.view-dashboard {
    overflow-y: auto;
    padding: 0 20px 28px;
    gap: 18px;
}

.dash-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 18px 0 14px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-panel);
    z-index: 5;
}

.dash-title {
    margin: 0;
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.dash-subtitle {
    display: block;
    margin-top: 3px;
    font-size: 12px;
    color: var(--text-muted);
}

.dash-head-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-range-wrap { position: relative; }

.dash-range {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 9px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-panel);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-width: 230px;
    justify-content: space-between;
}

.dash-range:hover { border-color: var(--accent); }

.dash-range-caret { color: var(--text-muted); font-size: 10px; }

.dash-pop {
    position: fixed;
    top: 74px;
    right: 24px;
    width: 560px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
    padding: 14px;
    z-index: 60;
}

.dash-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.dash-presets button {
    padding: 5px 11px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-elev);
    color: var(--text-dim);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

.dash-presets button:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.dash-cal-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.dash-cal-nav-group {
    display: flex;
    gap: 4px;
}

.dash-cal-nav span {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    text-transform: capitalize;
}

.dash-cal-nav button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--bg-elev);
    color: var(--text-dim);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.dash-cal-nav button:hover { border-color: var(--accent); color: var(--accent); }

.dash-cals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.dash-cal { min-width: 0; }

.dash-cal-month {
    font-size: 12px;
    font-weight: 700;
    color: var(--text);
    text-align: center;
    margin-bottom: 6px;
    text-transform: capitalize;
}

.dash-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
}

.dash-cal-dow {
    font-size: 9.5px;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    padding: 3px 0;
    text-transform: uppercase;
}

.dash-cal-day {
    border: none;
    background: transparent;
    padding: 4px 0;
    border-radius: 5px;
    font-size: 11px;
    color: var(--text-dim);
    cursor: pointer;
    text-align: center;
}

.dash-cal-day:hover { background: var(--accent-soft); color: var(--accent); }
.dash-cal-day.is-empty { cursor: default; }
.dash-cal-day.is-empty:hover { background: transparent; }
.dash-cal-day.is-today { font-weight: 700; color: var(--accent); }

.dash-cal-day.is-in-range {
    background: var(--accent-soft);
    border-radius: 0;
    color: var(--accent);
}

.dash-cal-day.is-start,
.dash-cal-day.is-end {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
}

.dash-cal-day.is-start { border-radius: 6px 0 0 6px; }
.dash-cal-day.is-end { border-radius: 0 6px 6px 0; }
.dash-cal-day.is-start.is-end { border-radius: 6px; }

.dash-pop-foot {
    position: sticky;
    bottom: -14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    padding: 12px 0 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
}

#dash-pick-hint { font-size: 12px; color: var(--text-muted); }

.dash-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.dash-card {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px 14px 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.dash-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--accent);
    opacity: 0.85;
}

.dash-card.is-money::before { background: #1a8a4a; }
.dash-card.is-clinical::before { background: #0d8fd4; }
.dash-card.is-alert::before { background: #b07d14; }

.dash-card-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 7px;
}

.dash-card-value {
    font-size: 27px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    letter-spacing: -0.02em;
}

.dash-card-detail {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 6px;
}

.dash-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 14px;
}

.dash-chart {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px 10px;
    box-shadow: var(--shadow);
    min-width: 0;
}

.dash-chart-title {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
}

.dash-chart-canvas {
    position: relative;
    height: 250px;
}

@media (max-width: 760px) {
    .view-dashboard { padding: 0 12px 20px; }
    .dash-card-value { font-size: 22px; }
    .dash-charts { grid-template-columns: 1fr; }
    .dash-cals { grid-template-columns: 1fr; }
    .dash-range { min-width: 0; }
}

/* ---- carga del panel ---- */

.view-dashboard { position: relative; }

.dash-loading[hidden] { display: none; }

.dash-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg-panel);
    z-index: 20;
    border-radius: var(--radius);
}

.dash-spinner {
    width: 46px;
    height: 46px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-right-color: var(--accent-2);
    border-radius: 50%;
    animation: dash-spin 0.75s linear infinite;
}

.dash-loading-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    animation: dash-pulse 1.4s ease-in-out infinite;
}

@keyframes dash-spin {
    to { transform: rotate(360deg); }
}

@keyframes dash-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.dash-refresh.is-spinning {
    animation: dash-spin 0.9s linear infinite;
    pointer-events: none;
    opacity: 0.7;
}

/* ---- spinner dentro del boton de fecha ---- */

.dash-range.is-loading {
    pointer-events: none;
    opacity: 0.75;
}

.dash-range.is-loading .dash-range-caret { display: none; }

.dash-range.is-loading::after {
    content: '';
    width: 15px;
    height: 15px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: dash-spin 0.75s linear infinite;
    flex: 0 0 auto;
}

/* ---- pantalla completa ---- */

.view-dashboard:fullscreen {
    background: var(--bg);
    padding: 0 32px 32px;
    overflow-y: auto;
}

.view-dashboard:-webkit-full-screen {
    background: var(--bg);
    padding: 0 32px 32px;
    overflow-y: auto;
}

.view-dashboard:fullscreen .dash-head {
    padding-top: 24px;
    background: var(--bg-panel);
}

.view-dashboard:fullscreen .dash-cards {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.view-dashboard:fullscreen .dash-card-value {
    font-size: 32px;
}
