/* =========================================================
   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;
    --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;
}

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-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);
}

.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: 8px;
    margin-top: 32px;
}

.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));
}

.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);
}

/* ===================== 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);
}

/* ===================== 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 tr:last-child td {
    border-bottom: 0;
}

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

.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;
}

.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;
}

/* 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;
    }
}
