:root {
    --primary: #0047FF;
    --primary-dark: #0033CC;
    --primary-light: #3B82F6;
    --sidebar-bg: #07102B;
    --sidebar-hover: #0D1F4A;
    --sidebar-active: #0047FF;
    --surface: #FFFFFF;
    --surface-2: #F5F7FF;
    --surface-3: #EEF2FF;
    --border: #E2E8F0;
    --text: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    --radius: 4px;
    --radius-sm: 2px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 10px 40px rgba(0,0,0,.1);
    --transition: .2s cubic-bezier(.4,0,.2,1);
    --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--surface-2);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

.icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Toasts */
.toast-wrap {
    position: fixed; top: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 9999; pointer-events: none;
}
.toast {
    background: var(--surface); color: var(--text);
    border-radius: var(--radius); border: 1px solid var(--border);
    border-left: 4px solid var(--primary); padding: 14px 20px;
    box-shadow: var(--shadow-md); font-size: .85rem; font-weight: 600;
    min-width: 300px; max-width: 460px; pointer-events: auto;
    transform: translateY(-20px); opacity: 0;
    animation: slideIn var(--transition) forwards;
    transition: opacity var(--transition);
}
.toast-success { border-left-color: var(--success); }
.toast-danger { border-left-color: var(--danger); }
@keyframes slideIn { to { transform: translateY(0); opacity: 1; } }

/* Botones */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 20px; border-radius: var(--radius);
    font-size: .875rem; font-weight: 600; cursor: pointer; font-family: inherit;
    border: none; transition: var(--transition); text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-3); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { filter: brightness(.96); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.9); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-icon { padding: 6px; }

/* Tarjetas */
.card {
    background: var(--surface); border-radius: var(--radius);
    border: 1px solid var(--border); padding: 24px;
    box-shadow: var(--shadow); margin-bottom: 24px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.card-sub { font-size: .8rem; color: var(--text-muted); }

/* Login */
.login-screen { min-height: 100vh; display: flex; align-items: stretch; background: var(--surface); }
.login-left {
    flex: 1; background: var(--sidebar-bg);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px; position: relative; overflow: hidden;
}
.login-left::before {
    content: ''; position: absolute; width: 600px; height: 600px;
    background: radial-gradient(circle, rgba(0,71,255,.25) 0%, transparent 70%);
    top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none;
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 20px; text-align: center; position: relative; z-index: 1; }
.login-brand h1 { color: #fff; font-size: 2.2rem; font-weight: 800; letter-spacing: -0.5px; }
.login-brand h1 span { color: var(--primary-light); }
.login-tagline { color: rgba(255,255,255,.55); font-size: .95rem; max-width: 400px; line-height: 1.6; margin-top: 6px; }
.login-channels { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; justify-content: center; }
.login-channel-chip {
    padding: 8px 18px; border-radius: 99px;
    background: rgba(255,255,255,.07); color: rgba(255,255,255,.7);
    font-size: .8rem; font-weight: 500; border: 1px solid rgba(255,255,255,.1);
}
.login-right {
    width: 480px; flex-shrink: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px 56px; background: var(--surface);
}
.login-form-wrap { width: 100%; }
.login-form-wrap h2 { font-size: 1.55rem; font-weight: 800; margin-bottom: 6px; }
.login-form-wrap p { color: var(--text-muted); font-size: .875rem; margin-bottom: 32px; }

/* Formularios */
.input-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.input-group label { font-size: .72rem; font-weight: 700; color: var(--text-secondary); letter-spacing: .5px; text-transform: uppercase; }
.input-group .help { font-size: .75rem; color: var(--text-muted); }
.input-group.checkbox { flex-direction: row; align-items: center; gap: 10px; }
.input-group.checkbox label { text-transform: none; letter-spacing: 0; font-size: .875rem; font-weight: 500; color: var(--text); }
.input, select.input, textarea.input {
    padding: 10px 12px; border: 1.5px solid var(--border);
    border-radius: var(--radius-sm); font-size: .9rem; color: var(--text); font-family: inherit;
    background: var(--surface); transition: var(--transition); outline: none; width: 100%;
}
textarea.input { min-height: 90px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,71,255,.1); }
.input.mono { font-family: var(--mono); font-size: .85rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA; border-radius: var(--radius); padding: 10px 12px; font-size: .82rem; margin-bottom: 14px; }
.form-section { grid-column: 1 / -1; font-size: .78rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; margin: 6px 0 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.password-wrap { position: relative; width: 100%; }
.password-wrap .input { padding-right: 44px; }
.password-toggle {
    position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-muted);
    transition: var(--transition);
}
.password-toggle:hover { color: var(--primary); background: var(--surface-3); }
.password-toggle .icon { width: 18px; height: 18px; }

.kv-editor { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: grid; grid-template-columns: 1fr 1.6fr auto; gap: 8px; }

/* Layout */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--sidebar-bg); display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-logo {
    padding: 20px 24px; border-bottom: 1px solid rgba(255,255,255,.07); flex-shrink: 0;
    font-size: 1.15rem; font-weight: 800; color: #fff;
}
.sidebar-logo span { color: var(--primary-light); }
.sidebar-logo small { display: block; font-size: .7rem; font-weight: 500; color: rgba(255,255,255,.45); letter-spacing: .3px; }
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-label { font-size: .65rem; font-weight: 700; color: rgba(255,255,255,.35); text-transform: uppercase; letter-spacing: 1px; padding: 14px 14px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.7); text-decoration: none; background: none; border: none; font-family: inherit; text-align: left;
    font-size: .85rem; font-weight: 500; cursor: pointer; transition: var(--transition);
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item .count { margin-left: auto; background: var(--danger); color: #fff; font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.nav-item-logout { margin-top: auto; color: #ff6b6b; }
.nav-item-logout:hover { background: rgba(255,80,80,.15); color: #ff6b6b; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--surface-2); min-width: 0; }
.header {
    height: 64px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 32px; flex-shrink: 0; gap: 12px;
}
.header-title { font-size: 1.2rem; font-weight: 700; }
.header-user { display: flex; align-items: center; gap: 10px; font-size: .82rem; color: var(--text-secondary); }
.content-area { flex: 1; overflow-y: auto; padding: 28px 32px; }

/* Encabezado de página y barras */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { font-size: 1.35rem; font-weight: 800; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-muted); font-size: .85rem; margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 600; margin-bottom: 10px; color: var(--text-secondary); cursor: pointer; background: none; border: none; font-family: inherit; }
.back-link:hover { color: var(--primary); }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { width: auto; min-width: 180px; padding: 8px 12px; font-size: .85rem; }
.toolbar .search { flex: 1; min-width: 220px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.badge-blue { background: #EEF2FF; color: var(--primary); }
.badge-green { background: #ECFDF5; color: #059669; }
.badge-red { background: #FEF2F2; color: #DC2626; }
.badge-yellow { background: #FFFBEB; color: #B45309; }
.badge-gray { background: #F1F5F9; color: #64748B; }
.badge-purple { background: #F5F3FF; color: #7C3AED; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.plat-facebook { background: #EBF2FF; color: #1877F2; }
.plat-instagram { background: #FDF0F6; color: #C13584; }
.plat-whatsapp { background: #E9FBF0; color: #128C4B; }
.plat-desconocido { background: #F1F5F9; color: #64748B; }

/* Tablas */
.table-container { border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; background: var(--surface); }
.table { width: 100%; border-collapse: collapse; text-align: left; }
.table th { background: #F8FAFC; padding: 12px 16px; font-size: .75rem; font-weight: 700; color: var(--text-secondary); border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.table td { padding: 12px 16px; font-size: .85rem; color: var(--text); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #F8FAFF; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn + .btn { margin-left: 6px; }
.table .empty { text-align: center; color: var(--text-muted); padding: 28px; }
.cell-title { font-weight: 600; color: var(--primary); }
.cell-sub { font-size: .75rem; color: var(--text-muted); }
.mono { font-family: var(--mono); font-size: .8rem; }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }

/* Resumen */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow); cursor: pointer; transition: var(--transition); text-align: left; font-family: inherit;
}
.stat:hover { border-color: var(--primary-light); }
.stat .label { font-size: .75rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 1.9rem; font-weight: 800; color: var(--text); margin-top: 4px; }
.stat.warn .value { color: var(--warning); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 0 24px; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.list-item:last-child { border-bottom: none; }
.list-empty { color: var(--text-muted); font-size: .85rem; padding: 6px 0; }

/* Fichas */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px 24px; }
.kv-grid dt { font-size: .72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.kv-grid dd { font-size: .9rem; margin-top: 2px; word-break: break-word; }
.notes { white-space: pre-wrap; font-size: .88rem; color: var(--text-secondary); }
.config-table td:first-child { font-family: var(--mono); font-size: .8rem; color: var(--text-secondary); width: 35%; }
.config-table td:last-child { font-family: var(--mono); font-size: .8rem; word-break: break-all; }

/* Credenciales */
.cred { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cred:last-child { border-bottom: none; }
.cred-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-3); color: var(--primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cred-main { flex: 1; min-width: 0; }
.cred-label { font-weight: 600; font-size: .9rem; }
.cred-meta { font-size: .78rem; color: var(--text-muted); word-break: break-all; }
.cred-actions { display: flex; gap: 6px; flex-shrink: 0; }
.secret-box { display: flex; gap: 8px; align-items: stretch; }
.secret-box .input { font-family: var(--mono); }
.secret-timer { font-size: .78rem; color: var(--text-muted); margin-top: 8px; }
.vault-warning { background: #FFFBEB; border: 1px solid #FDE68A; color: #92400E; padding: 10px 14px; border-radius: var(--radius); font-size: .82rem; margin-bottom: 14px; }

/* Consola */
.console {
    background: #0F172A; color: #38BDF8; font-family: 'Courier New', Courier, monospace;
    padding: 16px; border-radius: var(--radius); overflow-y: auto; height: 520px;
    font-size: .82rem; line-height: 1.4; border: 1.5px solid #1E293B;
}
.console-line { margin-bottom: 4px; border-bottom: 1px solid #1E293B; padding-bottom: 4px; white-space: pre-wrap; word-break: break-all; }
.console-line:last-child { border-bottom: none; margin-bottom: 0; }
.log-get { color: #38BDF8; }
.log-post { color: #34D399; }
.log-error { color: #F87171; }
.log-auth { color: #FBBF24; }
.log-timestamp { color: #94A3B8; font-size: .75rem; }

/* Modales */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center;
    padding: 5vh 20px; z-index: 100; overflow-y: auto;
}
.modal {
    background: var(--surface); border-radius: var(--radius);
    width: 100%; max-width: 520px; box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}
.modal.modal-lg { max-width: 760px; }
.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1.05rem; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.4rem; line-height: 1; color: var(--text-muted); }
.modal-body { padding: 22px 24px; }
.modal-footer { padding: 14px 24px; border-top: 1px solid var(--border); background: #F8FAFC; display: flex; justify-content: flex-end; gap: 10px; }

.loading { color: var(--text-muted); padding: 40px; text-align: center; font-size: .9rem; }

@media (max-width: 900px) {
    .login-left { display: none; }
    .login-right { width: 100%; padding: 40px 24px; }
    .app-shell { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }
    .sidebar { width: 100%; }
    .sidebar-nav { flex-direction: row; overflow-x: auto; padding: 8px; }
    .nav-label { display: none; }
    .nav-item-logout { margin-top: 0; }
    .main-content { overflow: visible; }
    .content-area { padding: 20px 16px; overflow: visible; }
    .header { padding: 0 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
}
