/* ==========================================================
   Licencias · hoja de estilos
   Paleta: tinta (barra), latón (llaves), papel (fondo)
   ========================================================== */
:root {
    --ink: #18233A;
    --ink-2: #22304D;
    --brass: #C8952E;
    --brass-soft: #FBF4E4;
    --brass-line: #E6CF9E;
    --paper: #F3F5F8;
    --surface: #FFFFFF;
    --line: #DCE1E8;
    --text: #1D2433;
    --muted: #667085;
    --ok: #1F7A55;   --ok-bg: #E6F4EE;
    --warn: #9A5B00; --warn-bg: #FDF1DC;
    --bad: #B42318;  --bad-bg: #FDECEA;
    --info: #2F5C9A; --info-bg: #E8EFF8;
    --radius: 10px;
    --topbar-h: 64px;
    --sidebar-w: 224px;
    --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--paper); }
h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
a { color: var(--info); }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
.muted { color: var(--muted); }
.block { display: block; }
.t-right { text-align: right; }
.inline { display: inline; margin: 0; }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }
.icon { flex: none; vertical-align: middle; }

/* ─── Barra superior (siempre visible) ─── */
.topbar {
    position: fixed; inset: 0 0 auto 0; z-index: 30;
    height: var(--topbar-h);
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 0 20px;
    background: var(--ink); color: #fff;
    border-bottom: 3px solid var(--brass);
}
.topbar__left, .topbar__right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar__menu { display: none; background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; border-radius: 8px; }
.topbar__logout { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand__name { font-size: 1.15rem; font-weight: 650; }

.user-chip {
    display: flex; align-items: center; gap: 10px; min-width: 0;
    padding: 6px 12px 6px 6px; border-radius: 999px;
    color: #fff; text-decoration: none;
}
.user-chip:hover { background: var(--ink-2); }
.user-chip__avatar {
    width: 36px; height: 36px; flex: none; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brass); color: var(--ink); font-weight: 700; font-size: 0.9rem;
}
.user-chip__meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-chip__meta strong { font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip__meta small { color: #B9C2D3; font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Menú lateral ─── */
.sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 20;
    width: var(--sidebar-w); padding: 18px 12px;
    background: var(--surface); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 4px;
}
.sidebar__link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 8px;
    color: var(--text); text-decoration: none; font-weight: 500;
}
.sidebar__link:hover { background: var(--paper); }
.sidebar__link.is-active { background: var(--ink); color: #fff; }
.sidebar__link.is-active .icon { color: var(--brass); }

/* ─── Contenido ─── */
.content {
    margin-left: var(--sidebar-w);
    padding: calc(var(--topbar-h) + 28px) 32px 48px;
    max-width: calc(1320px + var(--sidebar-w));
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.panel h2 { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }

.summary { margin-bottom: 24px; }
.summary__lead { font-size: 1.2rem; margin: 0; max-width: 62ch; color: var(--muted); }
.summary__lead strong { font-size: 2.4rem; color: var(--ink); font-weight: 700; margin-right: 4px; vertical-align: -0.1em; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li > div { display: flex; flex-direction: column; min-width: 0; }
.list .date { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ─── Alertas y aviso flotante ─── */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert ul { margin: 0; padding-left: 18px; }
.alert--ok { background: var(--ok-bg); color: var(--ok); border-color: #BFE3D2; }
.alert--error { background: var(--bad-bg); color: var(--bad); border-color: #F6C9C4; }
.alert--info { background: var(--info-bg); color: var(--info); border-color: #C9D8EE; }

.toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 60;
    transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
    background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
    transition: opacity .18s, transform .18s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ─── Botones ─── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover { background: var(--ink-2); }
.btn--ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn--ghost:hover { border-color: #B8C0CC; }
.btn--ghost-light { background: transparent; color: #fff; border-color: #3A4868; }
.btn--ghost-light:hover { background: var(--ink-2); }
.btn--link { background: none; color: var(--info); padding-inline: 6px; }
.btn--block { width: 100%; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 8px;
    border: 1px solid var(--line); background: var(--surface); color: var(--text);
    cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--ink); }
.icon-btn--danger:hover { border-color: var(--bad); color: var(--bad); }
.actions { white-space: nowrap; }
.actions > * + * { margin-left: 6px; }

/* ─── Formularios ─── */
.form { display: flex; flex-direction: column; gap: 16px; }
.form--narrow { max-width: 680px; }
.form__row { display: grid; gap: 16px; }
.form__row--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field--inline { min-width: 180px; }
.field--grow { flex: 1 1 240px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], select, textarea {
    font: inherit; color: var(--text); width: 100%;
    padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(200, 149, 46, .35); }
.is-readonly, input[readonly], select:disabled { background: var(--paper); color: var(--muted); }
.fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.fieldset legend { font-weight: 650; padding: 0 6px; }
.fieldset p { margin: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }

.rules { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; font-size: 0.86rem; color: var(--muted); }
.rules li::before { content: "○"; margin-right: 8px; }
.rules li.is-ok { color: var(--ok); }
.rules li.is-ok::before { content: "●"; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }

/* Selector segmentado de vigencia */
.segmented { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented__opt { flex: 1; position: relative; cursor: pointer; }
.segmented__opt + .segmented__opt { border-left: 1px solid var(--line); }
.segmented__opt input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented__opt span { display: block; text-align: center; padding: 9px 8px; font-weight: 600; }
.segmented__opt input:checked + span { background: var(--ink); color: #fff; }
.segmented__opt input:focus-visible + span { outline: 3px solid var(--brass); outline-offset: -3px; }
.segmented__opt.is-disabled { cursor: not-allowed; }
.segmented__opt.is-disabled span { color: #B3BAC5; background: var(--paper); text-decoration: line-through; }
.preview { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--paper); color: var(--muted); }
.preview strong { color: var(--text); }

/* ─── Tablas ─── */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: left; vertical-align: middle; border-top: 1px solid var(--line); }
.table thead th { border-top: 0; font-size: 0.82rem; font-weight: 650; color: var(--muted); background: #FAFBFC; white-space: nowrap; }
.table tbody tr:hover { background: #FAFBFD; }
.table td { font-variant-numeric: tabular-nums; }
.table .t-right { text-align: right; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.t-desc { max-width: 240px; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }

.pager { display: flex; gap: 4px; }
.pager a, .pager span {
    min-width: 36px; padding: 6px 10px; border-radius: 8px; text-align: center;
    border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none;
}
.pager a:hover { border-color: var(--ink); }
.pager .is-current { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ─── Estados ─── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 650; white-space: nowrap; }
.badge--activa, .badge--u-activo { background: var(--ok-bg); color: var(--ok); }
.badge--vencida, .badge--u-baja { background: var(--bad-bg); color: var(--bad); }
.badge--suspendida, .badge--u-inactivo { background: var(--warn-bg); color: var(--warn); }
.badge--pendiente { background: var(--info-bg); color: var(--info); }
.badge--plan { background: var(--paper); color: var(--text); border: 1px solid var(--line); margin: 2px 4px 2px 0; }

/* ─── Etiqueta de llave: el elemento distintivo del sistema ─── */
.lic-actions { display: flex; align-items: center; gap: 6px; }
.keytag {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 4px 4px 4px 10px;
    background: var(--brass-soft); border: 1px solid var(--brass-line);
    border-radius: 6px 18px 18px 6px;
    white-space: nowrap;
}
.keytag__hole { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--brass); }
.keytag code { color: #5B4210; font-size: 0.8rem; }
.keytag__copy {
    display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
    border: 0; background: var(--brass); color: var(--ink); cursor: pointer;
}
.keytag__copy:hover { background: #B5831F; }
.keytag__copy.is-done { background: var(--ok); color: #fff; }

/* ─── Aplicaciones ─── */
.app-cell { display: flex; align-items: center; gap: 12px; }
.app-thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }
.app-thumb--lg { width: 72px; height: 72px; }
.app-thumb--empty { display: grid; place-items: center; background: var(--paper); color: var(--muted); }

/* ─── Diálogos ─── */
.dialog { width: min(520px, calc(100vw - 32px)); border: 0; border-radius: 14px; padding: 22px; box-shadow: 0 24px 60px rgba(24, 35, 58, .28); }
.dialog::backdrop { background: rgba(24, 35, 58, .55); }
.dialog__head { display: flex; justify-content: space-between; align-items: center; }
.dialog__foot { display: flex; justify-content: flex-end; gap: 10px; }
.dialog p { margin: 0; }

/* ─── Acceso ─── */
.login-page { background: var(--ink); }
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(340px, 460px) 1fr; }
.login__panel { background: var(--surface); padding: 56px 44px; display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.login__brand h1 { margin-top: 18px; font-size: 1.9rem; }
.login__brand p { margin: 6px 0 0; color: var(--muted); }
.login__art {
    display: grid; place-items: center; padding: 40px;
    background: repeating-linear-gradient(135deg, transparent 0 22px, rgba(200, 149, 46, .07) 22px 23px), var(--ink);
}
.keytag--big {
    flex-direction: column; align-items: flex-start; gap: 10px;
    padding: 28px 44px 28px 64px; position: relative;
    border-radius: 10px 60px 60px 10px; transform: rotate(-6deg);
    box-shadow: 0 30px 60px rgba(0, 0, 0, .35);
}
.keytag--big .keytag__hole { position: absolute; left: 24px; top: 50%; width: 22px; height: 22px; margin-top: -11px; background: var(--ink); box-shadow: inset 0 0 0 3px var(--brass); }
.keytag--big code { font-size: 1.05rem; }
.keytag--big small { color: #8A6A2A; }

/* ─── Responsivo ─── */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
    .topbar__menu { display: inline-grid; place-items: center; }
    .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 8px 0 24px rgba(24, 35, 58, .15); }
    .sidebar.is-open { transform: none; }
    .content { margin-left: 0; padding-inline: 16px; }
    .user-chip__meta small, .topbar__logout span, .brand__name { display: none; }
    .login { grid-template-columns: 1fr; }
    .login__art { display: none; }
    .login__panel { padding: 40px 24px; }
}
@media (max-width: 600px) {
    .form__row--2, .rules { grid-template-columns: 1fr; }
    .user-chip__meta { display: none; }
    .filters .field--inline { min-width: 0; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
