/* =========================================================
   Panel de licencias — sistema de diseño compartido
   (admin y vendedor usan exactamente los mismos componentes)
   ========================================================= */

:root {
    --bg: #f4f3f8;
    --surface: #ffffff;
    --surface-2: #f8f7fc;
    --text: #1d1a2b;
    --muted: #6b6680;
    --border: #e6e3ef;
    --border-strong: #d6d1e4;

    --primary: #6d4fd8;
    --primary-dark: #5136b8;
    --primary-soft: #efebfd;
    --ok: #18864b;
    --ok-soft: #e4f6ec;
    --info: #2463d1;
    --info-soft: #e5eefc;
    --warn: #c96a00;
    --warn-soft: #fdf0de;
    --danger: #cf3030;
    --danger-soft: #fde9e9;
    --gray-soft: #eeedf2;

    --sidebar-bg: #17132a;
    --sidebar-text: #b8b2cf;
    --sidebar-active: rgba(255, 255, 255, .09);

    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(23, 19, 42, .04), 0 4px 16px rgba(23, 19, 42, .04);
    --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #100e19;
        --surface: #1a1726;
        --surface-2: #211d30;
        --text: #ece9f6;
        --muted: #9a94b0;
        --border: #2b2640;
        --border-strong: #3a3352;
        --primary: #9479f2;
        --primary-dark: #7c5fe8;
        --primary-soft: #2a2347;
        --ok: #4cc584;
        --ok-soft: #173326;
        --info: #6aa0f5;
        --info-soft: #182a47;
        --warn: #f0a043;
        --warn-soft: #3a2a14;
        --danger: #f06a6a;
        --danger-soft: #3d1c1f;
        --gray-soft: #29253a;
        --sidebar-bg: #0c0a14;
        --shadow: none;
    }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15.5px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; letter-spacing: .3px; }
.icon { width: 18px; height: 18px; flex: none; }

/* ---------- Estructura: sidebar + contenido ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 30;
    display: flex; flex-direction: column; gap: 20px; padding: 20px 14px;
    background: var(--sidebar-bg); color: var(--sidebar-text); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: #fff; font-weight: 700; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--sidebar-text); text-transform: uppercase; letter-spacing: .06em; }
.logo { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #8a6cf0, #5136b8); color: #fff; font-size: 14px; flex: none; }
.area-seller .logo { background: linear-gradient(135deg, #3f8cf0, #3f3bc4); }

.sidenav { display: flex; flex-direction: column; gap: 2px; }
.sidenav-label { margin: 14px 10px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; opacity: .55; }
.sidenav-label:first-child { margin-top: 0; }
.sidenav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--sidebar-text); font-weight: 500; }
.sidenav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.sidenav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #8a6cf0; }
.area-seller .sidenav a.active { box-shadow: inset 3px 0 0 #3f8cf0; }

.side-credits { margin-top: auto; padding: 14px 16px; border-radius: var(--radius-sm); background: rgba(255, 255, 255, .06); }
.side-credits span { display: block; font-size: 12px; }
.side-credits b { font-size: 26px; color: #fff; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
    height: 60px; padding: 0 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; font-weight: 600; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credits-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px; }
.credits-pill .icon { width: 16px; height: 16px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 99px; color: var(--text); }
.user-chip:hover { background: var(--surface); text-decoration: none; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; }
.user-chip-text { display: flex; flex-direction: column; line-height: 1.2; }
.user-chip-text b { font-size: 13.5px; }
.user-chip-text small { font-size: 11.5px; color: var(--muted); }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); cursor: pointer; }
.menu-btn, .sidebar-backdrop { display: none; }

.content { width: 100%; max-width: 1280px; margin: 0 auto; padding: 28px; }

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .45); }
    .main { margin-left: 0; }
    .menu-btn { display: inline-grid; }
    .topbar { padding: 0 16px; }
    .content { padding: 20px 16px; }
    .user-chip-text { display: none; }
}

/* ---------- Encabezados ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-sub { margin-top: 4px; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.back-link .icon { width: 16px; height: 16px; }
.back-link:hover { color: var(--primary); text-decoration: none; }
.section-title { margin: 8px 0 12px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }

/* ---------- Layouts de pagina ---------- */
.layout-split, .layout-half, .layout-thirds, .layout-aside { display: grid; gap: 20px; align-items: start; margin-bottom: 20px; }
.layout-split { grid-template-columns: minmax(0, 1fr) 380px; }
.layout-aside { grid-template-columns: 380px minmax(0, 1fr); }
.layout-half { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.layout-thirds { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.layout-split > .card, .layout-half > .card, .layout-thirds > .card, .layout-aside > .card, .stack > .card, aside > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.sticky { position: sticky; top: 80px; }
@media (max-width: 1180px) { .layout-thirds { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1080px) {
    .layout-split, .layout-aside, .layout-half, .layout-thirds { grid-template-columns: minmax(0, 1fr); }
    .sticky { position: static; }
}

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { flex: 1; min-width: 0; }
.card-title p { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.card-actions { display: flex; gap: 8px; }
.card-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); flex: none; }
.card-icon.danger { background: var(--danger-soft); color: var(--danger); }
.card-body { padding: 20px; }
.card-danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

/* ---------- Formularios (patron unico) ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.form fieldset + fieldset { padding-top: 16px; border-top: 1px dashed var(--border); }
.form legend { padding: 0; margin-bottom: 12px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.optional { margin-left: 4px; font-weight: 500; text-transform: none; letter-spacing: 0; opacity: .8; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text); }
.field-label i { font-style: normal; color: var(--danger); }
.field-help { font-size: 12px; color: var(--muted); }

input, select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
textarea { resize: vertical; min-height: 44px; }
select { cursor: pointer; }

.form-hint { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 12.5px; color: var(--muted); }
.form-hint .icon { width: 16px; height: 16px; margin-top: 1px; color: var(--primary); }
.form-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 16px; border-top: 1px solid var(--border); }
.cost-box > span { display: block; font-size: 12px; color: var(--muted); }
.cost-box b { font-size: 22px; color: var(--primary); }
.cost-box small { font-size: 12.5px; font-weight: 500; color: var(--muted); }

.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.switch small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 38px; height: 22px; flex: none; border-radius: 99px; background: var(--border-strong); transition: background .15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }

/* ---------- Filas de accion (acciones de licencia, zona peligrosa) ---------- */
.action-row { display: flex; align-items: center; justify-content: space-between; gap: 16px 20px; padding: 16px 20px; flex-wrap: wrap; }
.action-list .action-row + .action-row { border-top: 1px solid var(--border); }
.action-info { flex: 1 1 220px; min-width: 0; }
.action-info p { margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.action-info .cost { color: var(--text); }
.action-info .cost b { color: var(--primary); }
.action-control { display: flex; gap: 8px; align-items: center; flex: 0 1 auto; flex-wrap: wrap; }
.action-control select { width: auto; min-width: 150px; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px;
    border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--primary); color: #fff;
    font: inherit; font-weight: 600; font-size: 13.5px; line-height: 1.2; cursor: pointer; white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn .icon { width: 16px; height: 16px; }
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-light:hover { background: var(--surface-2); border-color: var(--primary); color: var(--primary); }
.btn-success { background: var(--ok); }
.btn-success:hover { background: color-mix(in srgb, var(--ok) 85%, #000); }
.btn-warn { background: var(--warn); }
.btn-warn:hover { background: color-mix(in srgb, var(--warn) 85%, #000); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-ghost-danger:hover { background: var(--danger-soft); }
.btn-link { background: none; color: var(--muted); padding-left: 8px; padding-right: 8px; }
.btn-link:hover { background: none; color: var(--primary); }
.btn-small { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- Avisos ---------- */
.flash { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 20px; background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent); font-weight: 500; }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.codes { margin-top: 8px; min-height: 60px; font-family: ui-monospace, Consolas, monospace; font-size: 15px; resize: vertical; }

/* ---------- Tarjetas de estadisticas ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { display: flex; align-items: center; gap: 14px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); transition: border-color .15s, transform .15s; }
a.stat:hover { text-decoration: none; border-color: var(--stat-color); transform: translateY(-1px); }
.stat-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 11px; flex: none; background: var(--stat-soft); color: var(--stat-color); }
.stat-text { display: flex; flex-direction: column; min-width: 0; }
.stat-text b { font-size: 24px; line-height: 1.1; }
.stat-text span { font-size: 12.5px; color: var(--muted); }
.tone-primary { --stat-color: var(--primary); --stat-soft: var(--primary-soft); }
.tone-ok { --stat-color: var(--ok); --stat-soft: var(--ok-soft); }
.tone-info { --stat-color: var(--info); --stat-soft: var(--info-soft); }
.tone-warn { --stat-color: var(--warn); --stat-soft: var(--warn-soft); }
.tone-danger { --stat-color: var(--danger); --stat-soft: var(--danger-soft); }
.tone-muted { --stat-color: var(--muted); --stat-soft: var(--gray-soft); }
.tone-warn .stat-text b { color: var(--warn); }

.credits-card { display: flex; align-items: center; gap: 16px; padding: 18px 20px; background: linear-gradient(135deg, var(--primary-soft), var(--surface) 70%); }
.credits-card .card-icon { width: 48px; height: 48px; }
.credits-card b { font-size: 30px; color: var(--primary); }
.credits-card span { font-weight: 600; }
.credits-card p { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.credits-big { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius); background: var(--primary-soft); color: var(--primary); }
.credits-big b { font-size: 26px; }
.credits-big span { font-weight: 600; }

/* ---------- Toolbar de filtros ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.toolbar select { width: auto; flex: 0 1 165px; min-width: 0; }
.search { position: relative; flex: 1 1 180px; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 34px; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 20px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { padding-top: 10px; padding-bottom: 10px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr[data-href] { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-sub { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; }
.empty-row { padding: 36px 20px; text-align: center; color: var(--muted); }
.amount { font-weight: 700; }
.amount.plus { color: var(--ok); }
.amount.minus { color: var(--danger); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-activa { background: var(--ok-soft); color: var(--ok); }
.badge-nueva { background: var(--info-soft); color: var(--info); }
.badge-vencida { background: var(--warn-soft); color: var(--warn); }
.badge-suspendida { background: var(--danger-soft); color: var(--danger); }
h1 .badge { font-size: 12.5px; }

/* ---------- Ficha de licencia ---------- */
.hero { padding: 22px 24px; }
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.code-big { font-size: 28px; font-weight: 700; letter-spacing: 1px; }
.hero-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.kpi { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.kpi span { display: block; font-size: 12px; color: var(--muted); }
.kpi b { font-size: 19px; }
.kpi b.warn { color: var(--warn); }
.kpi small { font-weight: 500; color: var(--muted); }
@media (max-width: 720px) { .kpis { grid-template-columns: 1fr 1fr; } }

.details { display: flex; flex-wrap: wrap; gap: 10px 32px; margin: 18px 0 0; }
.details dt { font-size: 12px; color: var(--muted); }
.details dd { margin: 0; font-weight: 500; }
.card-body.details { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.details.compact { margin: 0; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); gap: 6px 24px; font-size: 13px; }

/* ---------- Linea de tiempo ---------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; display: flex; gap: 14px; padding: 0 0 16px; }
.timeline li:not(:last-child)::before { content: ""; position: absolute; left: 4px; top: 14px; bottom: 0; width: 2px; background: var(--border); }
.timeline .dot { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; flex: none; background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.timeline-main { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.timeline-meta { font-size: 12px; color: var(--muted); }
.timeline .empty-row { display: block; padding: 20px 0; }
.chip { padding: 1px 8px; border-radius: 6px; background: var(--primary-soft); font-size: 12px; }
.chip:hover { text-decoration: none; background: var(--primary); color: #fff; }

/* ---------- Login ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: radial-gradient(circle at 20% 10%, var(--primary-soft), var(--bg) 55%); }
.auth-box { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px; box-shadow: 0 12px 40px rgba(23, 19, 42, .08); }
.brand.big { justify-content: center; color: var(--text); font-size: 22px; padding: 0; }
.auth-sub { margin: 8px 0 24px; text-align: center; color: var(--muted); }
.auth-box .form { gap: 14px; }
.auth-box .btn-block { margin-top: 6px; padding: 11px; }
