/* ============================================================
   IAnalitics Admin — identidad de marca
   Paleta tomada del logo: azul marino, índigo, azul y cian.
   ============================================================ */
:root {
    --navy: #12126b;
    --navy-deep: #0a002f;
    --indigo: #2626b8;
    --blue: #2f6be0;
    --cyan: #23b5e8;
    --cyan-soft: #d9f3fb;
    --bg: #f3f6fc;
    --surface: #ffffff;
    --border: #e2e8f5;
    --text: #1e293b;
    --muted: #64748b;
    --ok: #16a34a;
    --ok-soft: #dcfce7;
    --warn: #d97706;
    --warn-soft: #fef3c7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(18, 18, 107, 0.08);
}

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

html, body { height: 100%; }

body {
    font-family: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.45;
}

a { color: var(--blue); text-decoration: none; }

/* ---------- Layout con barra lateral ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--navy-deep) 0%, var(--navy) 60%, var(--indigo) 100%);
    color: #e8eeff;
    display: flex;
    flex-direction: column;
    padding: 26px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 6px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    margin-bottom: 18px;
}

.sidebar .brand img { height: 40px; width: 40px; object-fit: contain; filter: drop-shadow(0 0 12px rgba(35, 181, 232, 0.5)); }

.sidebar .brand .name { font-family: 'Syne', 'DM Sans', sans-serif; font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; }
.sidebar .brand .sub { font-size: .7rem; color: rgba(200, 220, 255, 0.6); letter-spacing: .12em; text-transform: uppercase; }

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    color: rgba(232, 238, 255, 0.82);
    font-weight: 500;
    transition: background .15s, color .15s;
}

.sidebar nav a:hover, .sidebar nav a.active { background: rgba(35, 181, 232, 0.16); color: #fff; }
.sidebar nav a svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

.sidebar .foot { margin-top: auto; font-size: .75rem; color: rgba(200, 220, 255, 0.5); padding: 0 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar h1 { font-family: 'Syne', 'DM Sans', sans-serif; font-size: 1.3rem; font-weight: 700; color: var(--navy); letter-spacing: -.02em; }

.topbar .user { display: flex; align-items: center; gap: 14px; font-size: .88rem; color: var(--muted); }
.topbar .user b { color: var(--text); }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
    color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
}

.content { padding: 20px 24px; }

/* ---------- Tarjetas KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 15px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.kpi::after {
    content: '';
    position: absolute; right: -20px; top: -20px;
    width: 80px; height: 80px; border-radius: 50%;
    background: radial-gradient(circle, rgba(35, 181, 232, 0.18), transparent 70%);
}

.kpi .label { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi .value { font-family: 'DM Sans', sans-serif; font-size: 1.3rem; font-weight: 700; color: var(--navy); margin-top: 4px; line-height: 1.2; letter-spacing: -.01em; }
.kpi .hint { font-size: .72rem; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.kpi .planes { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.kpi .planes .fila { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .9rem; font-weight: 700; color: var(--navy); }
.kpi .planes .badge { font-size: .66rem; padding: 2px 8px; }
.kpi.accent .value { color: var(--blue); }
.kpi.warn .value { color: var(--warn); }
.kpi.danger .value { color: var(--danger); }

/* ---------- Paneles y tablas ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    margin-bottom: 14px;
    scroll-margin-top: 12px;
}

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { font-family: 'Syne', 'DM Sans', sans-serif; font-size: 1rem; font-weight: 700; color: var(--navy); }

.search {
    padding: 6px 10px 6px 32px;
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 240px;
    font: inherit;
    font-size: .84rem;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") 10px center no-repeat;
}
.search:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(35, 181, 232, 0.18); }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .8rem; line-height: 1.3; }

th {
    text-align: left;
    font-size: .64rem;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 7px 8px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: #f8fafe; }
td.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .74rem; color: var(--muted); }
td .sub { display: block; font-size: .7rem; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 18px 10px; }

/* ---------- Etiquetas ---------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .03em;
    white-space: nowrap;
}
.badge.plan-FREE { background: #eef2ff; color: var(--indigo); }
.badge.plan-ADVANCED { background: var(--cyan-soft); color: #0e7490; }
.badge.plan-PERFORMANCE { background: linear-gradient(135deg, var(--navy), var(--blue)); color: #fff; }
.badge.plan-otro { background: var(--warn-soft); color: var(--warn); }
.badge.estado-vigente { background: var(--ok-soft); color: var(--ok); }
.badge.estado-por_vencer { background: var(--warn-soft); color: var(--warn); }
.badge.estado-vencido { background: var(--danger-soft); color: var(--danger); }
.badge.estado-ilimitado { background: #e0f2fe; color: #0369a1; }
.badge.estado-sin_fecha { background: #f1f5f9; color: var(--muted); }
.badge.nueva { background: linear-gradient(135deg, var(--cyan), var(--blue)); color: #fff; }

/* Barra de uso */
.uso { min-width: 120px; }
.uso .bar { height: 6px; border-radius: 6px; background: #e9eef8; overflow: hidden; margin-top: 4px; }
.uso .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--blue)); }
.uso .bar i.alto { background: linear-gradient(90deg, var(--warn), var(--danger)); }
.uso small { color: var(--muted); font-size: .76rem; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border-radius: 9px;
    border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: .85rem;
    cursor: pointer;
    transition: transform .12s, box-shadow .15s, background .15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: linear-gradient(135deg, var(--blue), var(--indigo)); color: #fff; box-shadow: 0 6px 16px rgba(47, 107, 224, 0.3); }
.btn-primary:hover { box-shadow: 0 8px 22px rgba(47, 107, 224, 0.4); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--navy); }
.btn-ghost:hover { background: #f4f7fd; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: .76rem; border-radius: 7px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 10px; }
.field label { display: block; font-size: .66rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
    width: 100%; padding: 6px 10px; min-height: 32px;
    border: 1px solid var(--border); border-radius: 8px;
    font: inherit; font-size: .84rem; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(35, 181, 232, 0.18); }
.field .hint { font-size: .7rem; color: var(--muted); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; z-index: 100;
    display: none; align-items: center; justify-content: center;
    background: rgba(10, 0, 47, 0.55); backdrop-filter: blur(3px);
    padding: 16px;
}
.modal.is-open { display: flex; }
.modal-panel {
    width: min(520px, 100%);
    background: #fff; border-radius: 16px;
    padding: 26px 26px 22px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
    animation: up .25s ease both;
}
@keyframes up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.modal-panel h3 { font-family: 'Syne', 'DM Sans', sans-serif; color: var(--navy); font-size: 1.1rem; margin-bottom: 4px; }
.modal-panel .sub { color: var(--muted); font-size: .85rem; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Avisos ---------- */
.toast {
    position: fixed; right: 22px; bottom: 22px; z-index: 200;
    padding: 12px 16px; border-radius: 10px;
    background: var(--navy); color: #fff; font-size: .88rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    opacity: 0; transform: translateY(10px); transition: opacity .2s, transform .2s;
    max-width: 380px;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- Detalle de empresa ---------- */
.detalle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px 20px; }
.detalle-grid .item .k { font-size: .64rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.detalle-grid .item .v { font-weight: 600; font-size: .86rem; color: var(--text); margin-top: 1px; word-break: break-word; }
.detalle-grid .item .v .sub { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); }

/* Accesos rápidos a los paneles de la empresa */
.barra-empresa { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.barra-empresa .saltos { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
a.salto {
    font-size: .72rem; font-weight: 600; color: var(--navy);
    padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
a.salto:hover { border-color: var(--cyan); background: var(--cyan-soft); }

/* Panel plegable: el título lo contrae y lo abre */
.plegar {
    display: inline-flex; align-items: center; gap: 8px;
    border: 0; background: none; padding: 0; cursor: pointer;
    font: inherit; color: inherit; text-align: left;
}
.plegar::after {
    content: ''; width: 7px; height: 7px; flex-shrink: 0;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: translateY(-2px) rotate(45deg); transition: transform .15s;
}
.plegar:hover::after { border-color: var(--cyan); }
.plegar:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 4px; }
.panel.plegado .plegar::after { transform: rotate(-45deg); }
.panel.plegado > :not(.panel-head) { display: none !important; }
.panel.plegado > .panel-head { margin-bottom: 0; }
.panel-head .acciones { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* Tablas largas: se desplazan dentro del panel con el encabezado fijo */
.table-wrap.alto { max-height: min(440px, 58vh); overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap.alto thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.table-wrap.alto tbody tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.fecha { white-space: nowrap; font-variant-numeric: tabular-nums; }
td .corto { display: block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.detalle { min-width: 220px; }
td.detalle .sub { word-break: break-all; }

/* Filtros de la bitácora */
.filtros { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 10px; }
.filtros .search { min-width: 0; padding-left: 10px; background-image: none; }
.filtros .botones { display: flex; gap: 6px; align-items: center; }

/* Formulario del certificado: solo aparece para cargar o reemplazar */
[hidden] { display: none !important; }
.form-cert { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 14px; margin-top: 12px; }
.field.botones { display: flex; align-items: flex-end; gap: 8px; }

/* Textos de ayuda y avisos dentro de un panel */
.nota { font-size: .76rem; color: var(--muted); margin: 0 0 10px; }
.aviso { font-size: .78rem; margin: 10px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--warn-soft); color: #92400e; }
.aviso.error { background: var(--danger-soft); color: #991b1b; }
.aviso.ok { background: var(--ok-soft); color: #166534; }

/* ---------- Login ---------- */
body.login {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1200px 600px at 10% -10%, rgba(35, 181, 232, 0.25), transparent 60%),
                radial-gradient(900px 500px at 100% 110%, rgba(47, 107, 224, 0.3), transparent 60%),
                linear-gradient(160deg, var(--navy-deep), var(--navy) 55%, var(--indigo));
    padding: 20px;
}

.login-card {
    width: min(420px, 100%);
    background: rgba(255, 255, 255, 0.97);
    border-radius: 20px;
    padding: 38px 36px 30px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    animation: up .4s ease both;
}
.login-card .brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 22px; }
.login-card .brand img { height: 64px; object-fit: contain; }
.login-card .brand .sub { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.login-card h2 { font-family: 'Syne', 'DM Sans', sans-serif; text-align: center; color: var(--navy); font-size: 1.35rem; margin-bottom: 4px; }
.login-card .lead { text-align: center; color: var(--muted); font-size: .86rem; margin-bottom: 22px; }
.login-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: .95rem; margin-top: 6px; }
.login-card .error { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; padding: 10px 12px; border-radius: 9px; font-size: .85rem; margin-bottom: 14px; display: none; }
.login-card .error.show { display: block; }
.login-card .foot { text-align: center; font-size: .72rem; color: var(--muted); margin-top: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 16px; }
    .sidebar .brand { border: none; padding: 0; margin: 0 16px 0 0; }
    .sidebar nav { display: flex; gap: 4px; }
    .sidebar .foot { display: none; }
    .topbar, .content { padding-left: 16px; padding-right: 16px; }
    .grid-2 { grid-template-columns: 1fr; }
    .filtros { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .barra-empresa .saltos { margin-left: 0; }
}
