/* ==========================================================================
   SERED Hub - Sistema de diseño compartido (Hub + Panel admin)
   ========================================================================== */

:root {
    --bg: #f6f7fb;
    --bg-soft: #eef0f6;
    --surface: #ffffff;
    --surface-2: #f9fafc;
    --border: #e4e7ef;
    --border-strong: #d3d8e4;
    --text: #151a2d;
    --text-2: #4a5270;
    --text-3: #8189a3;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef0ff;
    --accent-text: #3f37c9;
    --success: #0f9d6b;
    --success-soft: #e6f7f0;
    --danger: #dc3545;
    --danger-soft: #fdecee;
    --warning: #b7791f;
    --warning-soft: #fdf4e3;
    --shadow-sm: 0 1px 2px rgba(20, 24, 45, .06);
    --shadow: 0 1px 3px rgba(20, 24, 45, .06), 0 6px 16px rgba(20, 24, 45, .06);
    --shadow-lg: 0 20px 50px rgba(20, 24, 45, .18);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --sidebar-w: 264px;
    --topbar-h: 64px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e1120;
        --bg-soft: #151a2e;
        --surface: #161b2e;
        --surface-2: #1b2136;
        --border: #262d45;
        --border-strong: #333b57;
        --text: #e8eaf3;
        --text-2: #b0b6cc;
        --text-3: #7c84a0;
        --accent: #7c73ff;
        --accent-hover: #8f88ff;
        --accent-soft: #232650;
        --accent-text: #b1acff;
        --success: #34c38f;
        --success-soft: #11332a;
        --danger: #f06272;
        --danger-soft: #3a1a22;
        --warning: #f0b95a;
        --warning-soft: #3a2e14;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .25);
        --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0e1120; --bg-soft: #151a2e; --surface: #161b2e; --surface-2: #1b2136;
    --border: #262d45; --border-strong: #333b57; --text: #e8eaf3; --text-2: #b0b6cc; --text-3: #7c84a0;
    --accent: #7c73ff; --accent-hover: #8f88ff; --accent-soft: #232650; --accent-text: #b1acff;
    --success: #34c38f; --success-soft: #11332a; --danger: #f06272; --danger-soft: #3a1a22;
    --warning: #f0b95a; --warning-soft: #3a2e14;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 3px rgba(0,0,0,.3), 0 6px 16px rgba(0,0,0,.25); --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
kbd {
    font-family: inherit; font-size: 11px; font-weight: 600; color: var(--text-3);
    border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
    padding: 1px 6px; background: var(--surface);
}
.muted { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
    border: 1px solid transparent; background: var(--surface-2); color: var(--text);
    font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
    text-decoration: none !important;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-soft { background: var(--accent-soft); color: var(--accent-text); }
.btn-soft:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn-xs { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent;
    background: transparent; color: var(--text-2); cursor: pointer; font-size: 16px;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 16px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.label, .form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.hint { display: block; font-size: 12px; color: var(--text-3); margin-top: 5px; }
.input, .form-control {
    width: 100%; height: 40px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
textarea.input, textarea.form-control { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
select.input, select.form-control {
    appearance: none; cursor: pointer; padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238189a3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input:focus, .form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-3); }

/* Interruptor (switch) */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
    position: relative; width: 36px; height: 20px; flex: none; border-radius: 999px;
    background: var(--border-strong); transition: background .15s;
}
.switch .track::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }
.switch input:disabled + .track { opacity: .4; }
.switch.sm .track { width: 30px; height: 17px; }
.switch.sm .track::after { width: 13px; height: 13px; }
.switch.sm input:checked + .track::after { transform: translateX(13px); }

/* ---------- Tarjetas, badges ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px 22px; }
.badge {
    display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
    border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
    background: var(--bg-soft); color: var(--text-2);
}
.badge-accent, .badge-info { background: var(--accent-soft); color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; z-index: 100; display: none;
    align-items: flex-start; justify-content: center; padding: 6vh 16px 16px;
    background: rgba(12, 15, 30, .45); backdrop-filter: blur(3px); overflow-y: auto;
}
.modal.active { display: flex; animation: fade .15s ease-out; }
.modal-content {
    width: 100%; max-width: 640px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop .18s ease-out;
}
.modal-content.wide { max-width: 820px; }
.modal-content.narrow { max-width: 460px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.close-modal { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); font-size: 22px; cursor: pointer; }
.close-modal:hover { background: var(--bg-soft); color: var(--text); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast {
    display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 380px;
    padding: 12px 16px; border-radius: var(--radius); background: var(--text); color: var(--bg);
    box-shadow: var(--shadow-lg); font-weight: 500; font-size: 13.5px; pointer-events: auto;
    animation: toast-in .2s ease-out;
}
.toast.success::before { content: '✓'; color: #4ade80; font-weight: 800; }
.toast.danger::before { content: '!'; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-weight: 800; font-size: 12px; }
.toast.hide { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Estados vacíos / carga ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--text-3); }
.empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 4px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--bg-soft) 25%, var(--surface-2) 50%, var(--bg-soft) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Texto enriquecido (descripciones) ---------- */
.rich { color: var(--text-2); font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich p { margin: 0 0 .5em; }
.rich h1, .rich h2, .rich h3, .rich h4 { color: var(--text); margin: .8em 0 .35em; font-size: 1.08em; }
.rich h1 { font-size: 1.2em; }
.rich ul, .rich ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.rich li { margin: .15em 0; }
.rich blockquote { margin: .5em 0; padding: 4px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; color: var(--text); }
.rich pre, .rich code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.rich pre { background: var(--bg-soft); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; white-space: pre-wrap; }
.rich code { background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; }
.rich a { text-decoration: underline; }
.rich .ql-align-center { text-align: center; }
.rich .ql-align-right { text-align: right; }
.rich .ql-align-justify { text-align: justify; }
.rich .ql-indent-1 { padding-left: 1.5em; }
.rich .ql-indent-2 { padding-left: 3em; }
.rich .ql-indent-3 { padding-left: 4.5em; }

/* ---------- Editor de texto (Quill) ---------- */
.editor { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor .ql-toolbar.ql-snow { border: 0; border-bottom: 1px solid var(--border); padding: 6px 8px; background: var(--surface-2); border-radius: var(--radius-sm) var(--radius-sm) 0 0; display: flex; flex-wrap: wrap; gap: 2px; }
.editor .ql-toolbar.ql-snow .ql-formats { margin-right: 6px; padding-right: 6px; border-right: 1px solid var(--border); }
.editor .ql-toolbar.ql-snow .ql-formats:last-child { border-right: 0; }
.editor .ql-container.ql-snow { border: 0; font-family: var(--font); font-size: 14px; }
.editor .ql-editor { min-height: 130px; max-height: 360px; overflow-y: auto; color: var(--text); line-height: 1.55; }
.editor .ql-editor.ql-blank::before { color: var(--text-3); font-style: normal; }
.editor .ql-snow .ql-stroke { stroke: var(--text-2); }
.editor .ql-snow .ql-fill { fill: var(--text-2); }
.editor .ql-snow .ql-picker { color: var(--text-2); }
.editor .ql-snow button:hover .ql-stroke, .editor .ql-snow button.ql-active .ql-stroke,
.editor .ql-snow .ql-picker-label:hover .ql-stroke, .editor .ql-snow .ql-picker-label.ql-active .ql-stroke { stroke: var(--accent); }
.editor .ql-snow button:hover .ql-fill, .editor .ql-snow button.ql-active .ql-fill { fill: var(--accent); }
.editor .ql-snow button { border-radius: 5px; }
.editor .ql-snow button.ql-active, .editor .ql-snow button:hover { background: var(--accent-soft); }
.editor .ql-snow .ql-picker-options { background: var(--surface); border-color: var(--border) !important; border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.editor .ql-snow .ql-tooltip { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 5; }
.editor .ql-snow .ql-tooltip input[type=text] { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 6px; height: 30px; }
.editor .ql-editor blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-2); }
.editor .ql-editor pre.ql-syntax { background: var(--bg-soft); color: var(--text); border-radius: 6px; }
.editor-footer { display: flex; justify-content: flex-end; font-size: 11.5px; color: var(--text-3); padding: 4px 10px 6px; border-top: 1px dashed var(--border); }

/* ---------- Login ---------- */
.login-view {
    min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
    background:
        radial-gradient(1000px 500px at 10% -10%, var(--accent-soft), transparent 60%),
        radial-gradient(800px 400px at 110% 110%, var(--accent-soft), transparent 60%),
        var(--bg);
}
.login-card { width: 100%; max-width: 400px; padding: 34px 30px 28px; }
.login-card .brand { display: flex; justify-content: center; margin-bottom: 6px; font-size: 20px; }
.login-card .sub { text-align: center; color: var(--text-3); margin: 0 0 26px; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px; }

/* ---------- Marca ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; color: var(--text); text-decoration: none !important; letter-spacing: -0.02em; }
.brand-mark {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; font-size: 15px; font-weight: 800;
    box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}

/* ==========================================================================
   Layout de aplicación (sidebar + topbar) común a Hub y Admin
   ========================================================================== */
.app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--topbar-h) 1fr; }
.topbar {
    grid-column: 1 / -1; position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 16px; padding: 0 20px;
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar .brand { width: calc(var(--sidebar-w) - 36px); flex: none; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; border: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--text-2); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.user-chip small { color: var(--text-3); font-weight: 500; }

.sidebar {
    position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface);
}
.nav-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 10px 6px; }
.nav-item, .nav-link {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; margin-bottom: 2px;
    border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2);
    font-weight: 500; font-size: 13.5px; text-align: left; cursor: pointer; text-decoration: none !important;
    transition: background .12s, color .12s;
}
.nav-item:hover, .nav-link:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.active, .nav-link.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .nav-ico, .nav-link .nav-ico { width: 22px; text-align: center; flex: none; font-size: 15px; }
.nav-item .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 11.5px; font-weight: 600; color: var(--text-3); background: var(--bg-soft); border-radius: 999px; padding: 1px 7px; }
.nav-item.active .count { background: var(--surface); color: var(--accent-text); }

.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--text-3); }

.menu-toggle { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .topbar { padding: 0 12px; gap: 10px; }
    .topbar .brand { width: auto; }
    .topbar .brand span:last-child { display: none; }
    .menu-toggle { display: inline-flex; }
    .sidebar {
        position: fixed; top: var(--topbar-h); left: 0; bottom: 0; height: auto; width: min(300px, 86vw); z-index: 40;
        transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: none; }
    .scrim.open { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(12, 15, 30, .4); z-index: 35; }
    .main { padding: 20px 16px 50px; }
    .user-chip span:not(.avatar) { display: none; }
    .topbar-actions { gap: 4px; }
    .topbar-actions .btn span { display: none; }
    .topbar-actions .btn { padding: 0 9px; }
    .page-head h1 { font-size: 21px; }
    .user-chip { padding: 2px; }
    .field-row { grid-template-columns: 1fr; }
}
