:root {
    --color-primary: #1d4ed8;
    --color-primary-dark: #1e3a8a;
    --color-bg: #f3f4f6;
    --color-surface: #ffffff;
    --color-text: #1f2937;
    --color-muted: #6b7280;
    --color-border: #e5e7eb;
    --color-error-bg: #fef2f2;
    --color-error-text: #b91c1c;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
}

a {
    color: var(--color-primary);
}

/* ---- Login ---- */

.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 16px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 32px 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.login-logo {
    display: block;
    width: 150px;
    height: auto;
    margin: 0 auto 18px;
}

.login-card h1 {
    font-size: 1.25rem;
    margin: 0 0 24px;
    text-align: center;
    color: var(--color-primary-dark);
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.login-card label {
    font-size: 0.875rem;
    font-weight: 600;
    margin-top: 12px;
}

.login-card input {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1rem;
}

.login-card button {
    margin-top: 24px;
    padding: 12px;
    border: none;
    border-radius: var(--radius);
    background: var(--color-primary);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

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

.alert {
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.alert-error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
}

/* ---- App shell ---- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--color-primary-dark);
    color: #fff;
}

.app-header-logo {
    height: 30px;
    width: auto;
    display: block;
}

.app-header-title {
    font-weight: 600;
    flex: 1;
}

.app-header-user {
    font-size: 0.875rem;
    opacity: 0.9;
}

.app-header-bell {
    position: relative;
    color: #fff;
    text-decoration: none;
    font-size: 1.1rem;
    line-height: 1;
}

.bell-count {
    position: absolute;
    top: -8px;
    right: -10px;
    background: #dc2626;
    color: #fff;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    line-height: 1.3;
}

.nav-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.25rem;
    cursor: pointer;
    display: block;
}

.app-nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.app-nav.open {
    max-height: 400px;
}

.app-nav ul {
    list-style: none;
    margin: 0;
    padding: 8px 0;
}

.app-nav li {
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
}

.app-nav li:last-child {
    border-bottom: none;
}

.app-nav a {
    text-decoration: none;
    color: var(--color-text);
    display: block;
}

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

.nav-disabled small {
    display: block;
    font-size: 0.75rem;
}

.app-nav li.nav-group {
    padding: 0;
}

.nav-group-label {
    display: block;
    padding: 10px 16px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
}

.nav-group ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-group ul li {
    padding: 0;
    border-bottom: 1px solid var(--color-border);
}

.nav-group ul li:last-child {
    border-bottom: none;
}

.nav-group ul a {
    padding-left: 28px;
}

/* ---- Admin: tablas, formularios, flash ---- */

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.toolbar h1 {
    margin: 0;
    font-size: 1.25rem;
}

.table-wrap {
    overflow-x: auto;
    margin-bottom: 32px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border-radius: var(--radius);
    overflow: hidden;
}

.admin-table th,
.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    font-size: 0.9rem;
    white-space: nowrap;
}

.admin-table th {
    background: #f9fafb;
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-ok {
    background: #dcfce7;
    color: #166534;
}

.badge-off {
    background: #fee2e2;
    color: #991b1b;
}

.form-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 480px;
}

.form-card h2 {
    margin-top: 0;
    font-size: 1.1rem;
}

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-grid label {
    font-size: 0.875rem;
    font-weight: 600;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.95rem;
    width: 100%;
    font-family: inherit;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--color-muted);
    margin: -6px 0 0;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: var(--color-primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    font-size: 0.875rem;
}

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

.btn-secondary {
    background: #e5e7eb;
    color: var(--color-text);
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.flash {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.flash-ok {
    background: #dcfce7;
    color: #166534;
}

.flash-error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
}

.role-list {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
}

.role-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

/* ---- Autocompletar de artículos ---- */

.suggest-box {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 240px;
    overflow-y: auto;
    margin-top: 2px;
}

.suggest-group-label {
    padding: 6px 10px 2px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-muted);
}

.suggest-item {
    padding: 8px 10px;
    font-size: 0.9rem;
    cursor: pointer;
}

.suggest-item:hover {
    background: var(--color-bg);
}

/* ---- Tablero kanban ---- */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 16px;
}

.filter-bar .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
}

.filter-bar select,
.filter-bar input {
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 0.85rem;
}

.kanban-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 12px;
}

.kanban-column {
    flex: 0 0 250px;
    background: #eef0f3;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    max-height: 75vh;
}

.kanban-column-header {
    padding: 10px 12px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-muted);
    display: flex;
    justify-content: space-between;
}

.kanban-count {
    background: #d1d5db;
    color: var(--color-text);
    border-radius: 999px;
    padding: 0 8px;
    font-weight: 600;
}

.kanban-col {
    list-style: none;
    margin: 0;
    padding: 0 8px 8px;
    overflow-y: auto;
    flex: 1;
    min-height: 60px;
}

.kanban-card {
    background: var(--color-surface);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    cursor: grab;
    font-size: 0.85rem;
}

.kanban-card-empresa {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--color-primary-dark);
    text-transform: uppercase;
}

.kanban-card-articulo {
    margin: 4px 0;
}

.kanban-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-bottom: 4px;
}

.kanban-card-monto {
    font-size: 0.8rem;
    font-weight: 600;
}

.kanban-card-solicitante {
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-top: 4px;
}

.kanban-card .btn-sm {
    margin-top: 8px;
    display: inline-block;
}

.badge-prioridad-baja { background: #e0f2fe; color: #075985; }
.badge-prioridad-normal { background: #f3f4f6; color: #374151; }
.badge-prioridad-alta { background: #fef3c7; color: #92400e; }
.badge-prioridad-urgente { background: #fee2e2; color: #991b1b; }

.sortable-ghost {
    opacity: 0.4;
}

/* ---- Indicadores ---- */

.kpi-summary {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.kpi-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 0;
}

.kpi-card h2 {
    margin-top: 0;
    font-size: 1.1rem;
}

.kpi-grid canvas {
    max-height: 260px;
}

/* ---- Panel principal: resumen ---- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--color-border);
}

.stat-card:hover {
    border-color: var(--color-primary);
}

.stat-card-alerta {
    border-color: var(--color-error-text);
    background: var(--color-error-bg);
}

.stat-number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--color-primary-dark);
}

.stat-card-alerta .stat-number {
    color: var(--color-error-text);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--color-muted);
}

.app-content {
    padding: 20px 16px;
    max-width: 960px;
    margin: 0 auto;
}

/* ---- Desktop: nav lateral fija en vez de hamburguesa ---- */

@media (min-width: 768px) {
    .nav-toggle {
        display: none;
    }

    .app-shell {
        display: grid;
        grid-template-columns: 220px 1fr;
        grid-template-rows: auto 1fr;
    }

    .app-header {
        grid-column: 1 / -1;
    }

    .app-nav {
        max-height: none;
        border-bottom: none;
        border-right: 1px solid var(--color-border);
    }

    .app-content {
        max-width: none;
        margin: 0;
        padding: 24px 32px;
    }
}

/* ---- Ayuda contextual ---- */

.btn-ayuda {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-left: 8px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
}

.btn-ayuda:hover,
.btn-ayuda:focus-visible {
    background: var(--color-primary-dark);
}

.modal-ayuda {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
}

.modal-ayuda[hidden] {
    display: none;
}

.modal-ayuda-panel {
    background: var(--color-surface);
    border-radius: var(--radius);
    max-width: 480px;
    width: 100%;
    max-height: min(80vh, 560px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.modal-ayuda-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.modal-ayuda-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--color-primary-dark);
}

.modal-ayuda-cerrar {
    border: none;
    background: transparent;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    color: var(--color-muted);
    padding: 4px;
}

.modal-ayuda-cerrar:hover {
    color: var(--color-text);
}

.modal-ayuda-body {
    padding: 16px 20px 20px;
    overflow-y: auto;
    font-size: 0.92rem;
    line-height: 1.5;
}

.modal-ayuda-body p {
    margin: 0 0 12px;
}

.modal-ayuda-body p:last-child {
    margin-bottom: 0;
}

.modal-ayuda-body strong {
    color: var(--color-text);
}

body.modal-ayuda-open {
    overflow: hidden;
}

/* ---- Pie de página ---- */

.app-footer {
    text-align: center;
    padding: 16px;
    font-size: 0.8rem;
    color: var(--color-muted);
}

.app-footer a {
    color: var(--color-muted);
    font-weight: 600;
    text-decoration: underline;
}

.app-footer a:hover {
    color: var(--color-primary);
}
