/* =========================================================
   ANUALIDADES — Hoja de estilos única
   Secciones: Variables · Reset · Botones · Layout ·
   Sidebar admin · Navbar · Auth · Cards · Badges ·
   Tablas · Formularios · Dashboard · Responsive
   Tipografía: 5 tamaños (--fs-xs, --fs-sm, --fs-base, --fs-lg, --fs-xl)
   ========================================================= */

/* ===================== Variables ===================== */
:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #1d2733;
    --muted: #667085;
    --line: #d9e0e8;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --success: #067647;
    --success-soft: #ecfdf3;
    --info: #1d4ed8;
    --info-soft: #eff6ff;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);

    /* Escala tipográfica: máximo 5 tamaños */
    --fs-xs: 13px;
    --fs-sm: 14px;
    --fs-base: 15px;
    --fs-lg: 20px;
    --fs-xl: 28px;
}

/* ===================== Reset ===================== */
* {
    box-sizing: border-box;
}

/* El atributo [hidden] siempre debe ocultar, aunque la clase defina display. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: var(--fs-base);
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

h1,
h2,
p {
    margin: 0;
}

.muted {
    color: var(--muted);
}

/* ===================== Botones ===================== */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    font-size: var(--fs-sm);
}

.button:hover {
    border-color: #b7c4d2;
}

.button-primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    border-color: var(--primary-dark);
    background: var(--primary-dark);
}

.button-ghost {
    background: transparent;
}

.button-danger {
    border-color: #f5c2bd;
    color: var(--danger);
}

.button-small {
    min-height: 34px;
    padding: 0 12px;
    font-size: var(--fs-xs);
}

.button-success {
    border-color: var(--success);
    background: var(--success);
    color: #ffffff;
}

.button-success:hover {
    border-color: #05603a;
    background: #05603a;
}

.button-outline-danger {
    border-color: #f5c2bd;
    color: var(--danger);
    background: var(--danger-soft);
}

.button-full {
    width: 100%;
}

/* ===================== Layout ===================== */
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.workspace {
    min-width: 0;
}

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

.topbar h1 {
    font-size: var(--fs-xl);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.sidebar-toggle {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: var(--fs-lg);
    line-height: 1;
}

.sidebar-toggle:hover {
    border-color: #b7c4d2;
    background: var(--surface-soft);
}

/* Menú lateral colapsado */
.app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
}

.app-shell.sidebar-collapsed .sidebar {
    display: none;
}

.content {
    display: grid;
    gap: 24px;
    padding: 32px;
}

/* ===================== Sidebar admin ===================== */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px;
    background: #18212b;
    color: #ffffff;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: var(--fs-lg);
}

.brand-mark {
    display: inline-grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
    font-size: var(--fs-lg);
}

/* ===================== Navbar ===================== */
.nav {
    display: grid;
    gap: 6px;
    margin-top: 28px;
}

.nav-group-title {
    margin: 16px 0 2px;
    padding: 0 14px;
    color: #7d8ba0;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nav-group-title:first-child {
    margin-top: 0;
}

.nav-link {
    padding: 12px 14px;
    border-radius: 8px;
    color: #c8d2df;
    font-weight: 700;
}

.nav-link:hover,
.nav-link.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* ===================== Auth ===================== */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #eaf0f2;
}

.auth-wrap {
    width: min(100%, 420px);
}

.login-panel {
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-intro {
    display: grid;
    gap: 8px;
    margin-bottom: 28px;
}

.login-intro h1 {
    font-size: var(--fs-xl);
}

.login-intro p,
.eyebrow,
.metric-card span {
    color: var(--muted);
    font-size: var(--fs-xs);
}

/* ===================== Cards ===================== */
.panel,
.metric-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    padding: 24px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-header h2,
.section-title {
    margin-top: 4px;
    font-size: var(--fs-lg);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.metrics-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metrics-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Grid de métricas que se ajusta al número de tarjetas */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.metric-card {
    display: grid;
    gap: 8px;
    padding: 22px;
}

.metric-card strong {
    font-size: var(--fs-lg);
}

.metric-line {
    color: var(--muted);
    font-size: var(--fs-xs);
}

.metric-link {
    color: var(--primary);
    font-weight: 700;
    font-size: var(--fs-xs);
}

.alert {
    padding: 14px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.alert-success {
    border-color: #abefc6;
    color: var(--success);
    background: var(--success-soft);
}

.alert-warning {
    border-color: #fde3b3;
    color: #b54708;
    background: #fffaeb;
}

/* ===================== Badges ===================== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: var(--fs-xs);
    font-weight: 700;
}

.badge-success {
    color: var(--success);
    background: var(--success-soft);
}

.badge-muted {
    color: var(--muted);
    background: var(--surface-soft);
}

.badge-danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.badge-info {
    color: var(--info);
    background: var(--info-soft);
}

.badge-stack {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}

/* Marca de registro nuevo: solo una estrella */
.nuevo-star {
    margin-left: 6px;
    color: #f59e0b;
    font-size: var(--fs-sm);
    cursor: default;
}

/* ===================== Tablas ===================== */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.table th,
.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.table th {
    background: var(--surface-soft);
    color: var(--muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
}

.table th.num,
.table td.num {
    text-align: right;
    white-space: nowrap;
}

/* Tabla compacta (filas ~50px) */
.table-compact th,
.table-compact td {
    padding: 7px 16px;
}

.table-compact .estado-select {
    min-height: 34px;
}

/* Estado vacío de un mes (con opción de copiar del año anterior) */
.empty-mes {
    display: grid;
    justify-items: center;
    gap: 14px;
    padding: 26px 16px;
}

/* Fila de totales */
.table tfoot .totales-row td {
    background: var(--surface-soft);
    border-top: 2px solid var(--line);
    font-weight: 800;
    color: var(--text);
}

.table tr:last-child td {
    border-bottom: 0;
}

.table tr.row-danger td {
    background: var(--danger-soft);
}

.table tr.row-success td {
    background: var(--success-soft);
}

/* Select de estado (acciones) */
.estado-select {
    min-height: 36px;
    font-weight: 700;
    font-size: var(--fs-xs);
}

.estado-select.estado-renovado {
    border-color: var(--success);
    color: var(--success);
    background: var(--success-soft);
}

.estado-select.estado-cancelado {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-soft);
}

.estado-select.estado-pendiente {
    color: var(--muted);
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.actions-cell {
    text-align: right;
}

.pagination {
    margin-top: 18px;
}

.pagination nav {
    display: flex;
    gap: 8px;
}

/* ===================== Formularios ===================== */
.form {
    display: grid;
    gap: 18px;
}

.form-panel {
    max-width: 760px;
}

.form-panel-wide {
    max-width: 980px;
}

.context-info {
    margin-bottom: 16px;
    color: var(--muted);
    font-size: var(--fs-sm);
}

.context-info strong {
    color: var(--text);
    font-size: var(--fs-lg);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
    display: grid;
    gap: 8px;
    position: relative;
}

.field-grow {
    flex: 1;
}

.field label,
.check {
    font-weight: 700;
    font-size: var(--fs-sm);
}

.input,
.field input,
.field select {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.input:focus,
.field input:focus,
.field select:focus,
.textarea:focus {
    outline: 3px solid rgba(15, 118, 110, 0.14);
    border-color: var(--primary);
}

.textarea {
    min-height: 120px;
    padding: 12px;
    line-height: 1.5;
    resize: vertical;
}

.field-error {
    color: var(--danger);
    font-size: var(--fs-xs);
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.inline-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.spaced-top {
    margin-top: 20px;
}

/* Barra de herramientas del listado (navegación de mes + acciones) */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-selects {
    margin: 0;
}

/* Barra horizontal de meses */
.month-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
}

.month-tab {
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-weight: 700;
    font-size: var(--fs-sm);
}

.month-tab:hover {
    border-color: #b7c4d2;
    color: var(--text);
}

.month-tab.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.cell-link {
    color: var(--primary);
    font-weight: 700;
}

.cell-link:hover {
    text-decoration: underline;
}

/* Dominio como botón que se ve como enlace */
button.cell-link {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-align: left;
}

.drag-handle {
    display: inline-block;
    margin-right: 8px;
    color: var(--muted);
    cursor: grab;
    user-select: none;
    font-size: var(--fs-sm);
}

.search-field {
    min-width: 260px;
}

.autocomplete-item .ac-mes {
    color: var(--muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    font-weight: 700;
}

/* Etiqueta de mes en resultados de búsqueda */
.mes-tag {
    display: inline-block;
    margin-right: 8px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
}

.drag-handle:active {
    cursor: grabbing;
}

.table tr.dragging td {
    opacity: 0.5;
    background: var(--surface-soft);
}

.dominio-cell {
    cursor: pointer;
}

.dominio-icon {
    display: inline-block;
    margin-right: 6px;
    color: var(--primary);
    font-size: var(--fs-xs);
    transition: transform 0.15s ease;
}

.dominio-cell.is-open .dominio-icon {
    transform: rotate(90deg);
}

/* Acordeón inline de edición */
.accordion-row > td {
    padding: 0;
    background: var(--surface-soft);
}

.inline-edit {
    display: grid;
    gap: 10px;
    padding: 12px 18px 16px;
    border-top: 2px solid var(--primary);
}

.inline-edit-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.inline-edit-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* Formulario compacto (acordeón) */
.form-compact {
    gap: 8px;
}

.inline-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-row .input {
    width: auto;
    min-width: 130px;
}

.form-compact .productos-section {
    gap: 8px;
}

.form-compact .producto-row {
    gap: 8px;
}

.form-compact .input {
    min-height: 38px;
}

/* Botón "+" para agregar producto (chico, a la izquierda) */
.add-producto-btn {
    justify-self: start;
    min-width: 40px;
    padding: 0 12px;
    font-size: var(--fs-lg);
    line-height: 1;
}

/* Select con botón al lado (ej. + Cliente) */
.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-with-btn .input {
    flex: 1;
}

/* Modal / popup */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.5);
}

.modal {
    width: min(100%, 560px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    border-radius: 10px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.modal-body {
    display: grid;
    gap: 16px;
}

.modal-close {
    border: 0;
    background: none;
    cursor: pointer;
    font-size: var(--fs-xl);
    line-height: 1;
    color: var(--muted);
}

/* Autocomplete de clientes */
.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    margin-top: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.autocomplete-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: var(--fs-sm);
}

.autocomplete-item:hover {
    background: var(--surface-soft);
}

/* Filas de producto (form de cuentas) */
.productos-section {
    display: grid;
    gap: 12px;
}

.productos-rows {
    display: grid;
    gap: 10px;
}

.producto-row {
    display: grid;
    grid-template-columns: 1.2fr 2fr 0.6fr 1fr auto;
    gap: 10px;
    align-items: center;
}

/* ===================== Dashboard ===================== */
/* (usa .metrics-grid-4 + .metric-card + .badge; sin reglas extra) */

/* ===================== Responsive ===================== */
@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .topbar,
    .panel-header,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .content,
    .topbar {
        padding: 22px;
    }

    .metrics-grid,
    .metrics-grid-3,
    .metrics-grid-4,
    .form-grid,
    .form-grid-3,
    .form-grid-4 {
        grid-template-columns: 1fr;
    }

    .producto-row {
        grid-template-columns: 1fr 1fr;
    }
}
