:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #1e293b;
    --primary-hover: #0f172a;
    --accent: #0284c7;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 10px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; color: var(--text); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

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

.sidebar {
    width: 264px;
    background: #0f172a;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 18px 14px;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.brand-mark {
    width: 36px; height: 36px;
    border-radius: 8px;
    background: #f8fafc;
    color: #0f172a;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 18px;
    flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 0.95rem; color: #fff; }
.brand-sub { font-size: 0.75rem; color: #94a3b8; }
.brand-logo-img { max-height: 40px; max-width: 110px; object-fit: contain; border-radius: 6px; background: #fff; padding: 3px; flex-shrink: 0; }

.sidebar-nav { flex: 1; margin-top: 14px; display: flex; flex-direction: column; gap: 3px; }
.nav-group-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
    padding: 12px 10px 4px;
}
.nav-link {
    display: flex; align-items: center; justify-content: space-between;
    color: #cbd5e1;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 0.88rem;
}
.nav-link:hover { background: rgba(255,255,255,0.08); text-decoration: none; color: #fff; }
.nav-link.active { background: #1e293b; color: #fff; font-weight: 600; border-left: 3px solid #38bdf8; }
.nav-badge {
    background: #0284c7; color: #fff; font-size: 0.72rem; font-weight: 700;
    padding: 1px 7px; border-radius: 999px;
}
.nav-badge.warn { background: #d97706; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.1); padding-top: 12px; }
.user-card { margin-bottom: 10px; }
.user-name { font-weight: 600; font-size: 0.86rem; color: #fff; }
.user-role { font-size: 0.75rem; color: #94a3b8; }

.main-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.mobile-menu-btn { display: none; }

.content { padding: 22px 24px; max-width: 1480px; width: 100%; margin: 0 auto; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 17px; }
.kpi-label { font-size: 0.8rem; color: var(--muted); }
.kpi-value { font-size: 1.55rem; font-weight: 700; margin: 4px 0; }
.kpi-link { font-size: 0.8rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-2-portal { display: grid; grid-template-columns: 1fr 1.15fr; gap: 18px; align-items: start; }
.grid-2-projects { display: grid; grid-template-columns: 420px 1fr; gap: 18px; align-items: start; }
.grid-2-corpus { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.studio-grid { display: grid; grid-template-columns: 1fr 1.05fr; gap: 18px; align-items: start; }
.split-workspace { display: grid; grid-template-columns: 1.05fr 0.95fr; gap: 18px; align-items: start; }

.wizard-quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.wizard-tile {
    display: flex; flex-direction: column; gap: 4px;
    border: 1px solid var(--border); border-radius: 8px; padding: 12px;
    background: var(--surface-muted); color: var(--text);
}
.wizard-tile:hover { border-color: var(--accent); background: #f0f9ff; text-decoration: none; }
.wizard-tile span { font-size: 0.8rem; color: var(--muted); }

.agents-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; margin-top: 12px; }
.agent-card { border: 1px solid var(--border); border-radius: 8px; padding: 13px; background: var(--surface-muted); display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.agent-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.agent-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 8px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.82rem; font-weight: 600; color: #334155; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(2, 132, 199, 0.2); border-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px;
    border-radius: 7px;
    border: 1px solid transparent;
    font-size: 0.86rem; font-weight: 600;
    cursor: pointer; text-decoration: none;
    background: var(--surface); color: var(--text);
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-outline { border-color: #cbd5e1; background: #fff; color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger-outline { border-color: #fecaca; background: #fff; color: var(--danger); }
.btn-danger-outline:hover { background: #fef2f2; }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; }
.btn-xs { padding: 4px 8px; font-size: 0.76rem; }
.btn-block { width: 100%; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.74rem; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0f2fe; color: #075985; }
.badge-neutral { background: #f1f5f9; color: #475569; }

.status-pill { padding: 4px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; }
.status-pill.ok { background: #dcfce7; color: #166534; }
.status-pill.warn { background: #fef3c7; color: #92400e; }

.alert { padding: 10px 14px; border-radius: 8px; border: 1px solid transparent; font-size: 0.88rem; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info { background: #f0f9ff; border-color: #bae6fd; color: #075985; }

.seal-banner { padding: 9px 14px; border-radius: 8px; font-size: 0.86rem; font-weight: 600; }
.seal-banner.approved { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }

.tabs-bar { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tab-link {
    padding: 7px 13px; border-radius: 7px; font-size: 0.85rem; font-weight: 600;
    color: var(--muted); background: transparent; border: 1px solid transparent; cursor: pointer;
}
.tab-link:hover { background: #e2e8f0; text-decoration: none; color: var(--text); }
.tab-link.active { background: var(--primary); color: #fff; }

.subtabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.subtab {
    padding: 5px 11px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--surface-muted); font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.subtab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.table th { text-align: left; background: #f8fafc; color: #334155; padding: 9px 10px; border-bottom: 1px solid var(--border); font-weight: 650; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }

.list-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface-muted);
}
.row-unread { border-left: 3px solid var(--accent); background: #f0f9ff; }

.meta-strip { display: flex; flex-wrap: wrap; gap: 14px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 0.84rem; }
.meta-strip span { color: var(--muted); }

.expedition-top { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.expedition-pills { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill { background: var(--surface-muted); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 0.8rem; }

.router-box { background: #f8fafc; border: 1px solid #cbd5e1; border-left: 4px solid var(--accent); border-radius: 7px; padding: 9px 12px; font-size: 0.85rem; }
.finding-card, .finding-mini { border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; background: #fff; }

.doc-check-list { display: flex; flex-direction: column; gap: 5px; max-height: 170px; overflow-y: auto; }
.doc-check-item { display: flex; align-items: center; gap: 7px; font-size: 0.84rem; }

.checkbox-grid { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.84rem; }
.checkbox-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 0.84rem; cursor: pointer; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.filter-bar { display: flex; gap: 14px; flex-wrap: wrap; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface-muted); padding: 4px 10px; border-radius: 999px; font-size: 0.8rem; cursor: pointer; color: var(--text); }
.chip:hover { border-color: var(--accent); background: #f0f9ff; }

.sticky-viewer { position: sticky; top: 16px; }
.source-viewer-frame-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; height: 620px; background: #f1f5f9; }
.source-viewer-frame-wrap iframe { width: 100%; height: 100%; border: 0; }
.empty-viewer, .empty-state { padding: 36px 20px; text-align: center; color: var(--muted); }

/* Notificaciones dropdown */
.notif-wrapper { position: relative; }
.notif-count { background: #e2e8f0; color: #334155; padding: 1px 6px; border-radius: 999px; font-size: 0.72rem; }
.notif-count.has-unread { background: var(--danger); color: #fff; }
.notif-dropdown {
    position: absolute; right: 0; top: 38px; width: 340px; max-width: 92vw;
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 25px rgba(15,23,42,0.14); z-index: 50;
}
.notif-dd-head, .notif-dd-foot { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.notif-dd-foot { border-bottom: 0; border-top: 1px solid var(--border); justify-content: center; }
.notif-dd-list { max-height: 320px; overflow-y: auto; }
.notif-item { display: block; padding: 9px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.notif-item.unread { background: #f0f9ff; }
.notif-item:hover { background: #f8fafc; text-decoration: none; }
.notif-item-title { font-weight: 600; font-size: 0.83rem; }
.notif-item-msg { font-size: 0.78rem; color: var(--muted); }
.notif-item-time { font-size: 0.72rem; color: #94a3b8; margin-top: 2px; }
.notif-empty { padding: 16px; text-align: center; color: var(--muted); font-size: 0.84rem; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 0.8rem; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; padding: 20px; width: 900px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
.code-textarea { font-family: Consolas, monospace; font-size: 0.84rem; }

/* Markdown prose */
.markdown-box h2, .markdown-box h3 { margin-top: 12px; margin-bottom: 5px; }
.markdown-box p { margin: 6px 0; }
.markdown-box ul { margin: 6px 0; padding-left: 20px; }

/* Login */
.login-body { background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-shell { width: 430px; max-width: 100%; }
.login-brand { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 16px; }
.login-brand h1 { color: #fff; font-size: 1.3rem; }
.login-brand p { margin: 0; color: #cbd5e1; font-size: 0.84rem; }
.demo-credentials { margin-top: 16px; padding: 10px 12px; background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 8px; font-size: 0.8rem; display: flex; flex-direction: column; gap: 4px; }

.stack-xs { display: flex; flex-direction: column; gap: 6px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
.text-warn { color: var(--warning); }
.hidden { display: none !important; }
.mt-xs { margin-top: 6px; } .mt-sm { margin-top: 10px; } .mt-md { margin-top: 14px; } .mt-lg { margin-top: 20px; }
.mb-xs { margin-bottom: 6px; } .mb-sm { margin-bottom: 10px; } .mb-md { margin-bottom: 14px; } .mb-lg { margin-bottom: 20px; }

@media (max-width: 1024px) {
    .grid-2, .grid-3, .grid-2-portal, .grid-2-projects, .grid-2-corpus, .studio-grid, .split-workspace {
        grid-template-columns: 1fr;
    }
    .sidebar { position: fixed; left: -270px; top: 0; bottom: 0; z-index: 60; transition: left 0.2s; }
    body.sidebar-open .sidebar { left: 0; }
    .mobile-menu-btn { display: inline-flex; }
}
