/* =====================================================================
   Sistema de Necesidades — estilos base (mobile-first)
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    color: #1f2937;
    background: #f4f6fa;
}

a { color: #1565c0; text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0; }

.subtitle { color: #6b7280; margin: 0 0 .75rem; font-size: .95rem; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 6rem;
}

/* ============================ Topbar / nav ============================ */
.topbar {
    background: #102a43;
    color: #fff;
    padding: .65rem 1rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    text-decoration: none;
}
.topbar .nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .25rem .9rem;
    margin-left: auto;
    font-size: .95rem;
}
.topbar .nav a {
    color: #cfe1f5;
    padding: .25rem 0;
}
.topbar .nav a:hover { color: #fff; }
.topbar .nav .logout {
    background: #ef4444;
    color: #fff;
    padding: .35rem .75rem;
    border-radius: 6px;
}
.topbar .nav .logout:hover { background: #dc2626; text-decoration: none; }
.topbar .user-chip {
    background: rgba(255,255,255,.12);
    padding: .25rem .65rem;
    border-radius: 999px;
    font-size: .85rem;
}

/* ============================ Footer ============================ */
.footer {
    text-align: center;
    color: #94a3b8;
    padding: 1rem;
    font-size: .85rem;
}

/* ============================ Flash ============================ */
.flash {
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: .95rem;
}
.flash-ok    { background: #e8f5e9; color: #1b5e20; border: 1px solid #c8e6c9; }
.flash-error { background: #ffebee; color: #b71c1c; border: 1px solid #ffcdd2; }
.flash-warn  { background: #fff8e1; color: #6d4c00; border: 1px solid #ffe082; }

/* ============================ Page header ============================ */
.page-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1rem;
}
.page-header h1 { flex: 1 1 auto; }
.inline-form {
    display: flex;
    align-items: end;
    gap: .5rem;
    flex-wrap: wrap;
}
.inline-form label {
    display: flex;
    flex-direction: column;
    font-size: .8rem;
    color: #6b7280;
}

/* ============================ Cards ============================ */
.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}

/* ============================ Forms ============================ */
label {
    display: block;
    margin: .5rem 0 .25rem;
    font-weight: 500;
    color: #374151;
    font-size: .95rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: .6rem .75rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    color: #111;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid #1565c0;
    outline-offset: 1px;
    border-color: #1565c0;
}
.num-input { max-width: 100px; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: .5rem .75rem;
    align-items: end;
}
.form-grid > button { margin-top: .5rem; }
@media (min-width: 700px) {
    .form-grid {
        grid-template-columns: repeat(4, 1fr) auto;
    }
}

.hidden-form { display: none; }

.form-stack {
    display: flex;
    flex-direction: column;
    gap: .25rem .5rem;
    max-width: 480px;
}
.form-stack .separator {
    border: 0;
    border-top: 1px solid #e5e7eb;
    margin: 1rem 0 .25rem;
}
.form-stack .hint {
    color: #6b7280;
    font-size: .9rem;
    margin: 0 0 .25rem;
}
.form-actions { margin-top: .75rem; }

/* ====== Admin: form de carga (tabla 3 columnas) ====== */
.admin-cargar-table input {
    width: 100%;
    text-align: right;
    padding: .4rem .5rem;
    font-size: .95rem;
    font-weight: 600;
}
.admin-cargar-table td.num { min-width: 100px; }
.admin-cargar-table .row-cargado td:first-child { border-left: 3px solid #66bb6a; }
.admin-cargar-table small.muted { color: #94a3b8; }
.form-cargar .hint {
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: .65rem .8rem;
    font-size: .9rem;
    color: #475569;
    margin: 0 0 1rem;
}
.form-cargar .hint code {
    background: #e5e7eb;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: .85em;
}

/* ====== Dashboard: botón copiar pedido ====== */
.card-header-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}
.btn-copy {
    background: #0d47a1;
    color: #fff;
}
.btn-copy:hover { background: #093374; }
.btn-copy-ok {
    background: #2e7d32 !important;
    color: #fff !important;
}
.btn-copy-err {
    background: #c62828 !important;
    color: #fff !important;
}

/* ============================ Buttons ============================ */
.btn {
    display: inline-block;
    padding: .65rem 1rem;
    background: #e5e7eb;
    color: #111;
    border: 0;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}
.btn:hover { background: #d1d5db; text-decoration: none; }
.btn-primary { background: #1565c0; color: #fff; }
.btn-primary:hover { background: #0d47a1; }
.btn-secondary { background: #64748b; color: #fff; }
.btn-secondary:hover { background: #475569; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-small { padding: .4rem .65rem; font-size: .85rem; }
.btn-block { display: block; width: 100%; text-align: center; }

.actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* ============================ Tables ============================ */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}
.data-table th, .data-table td {
    padding: .55rem .5rem;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: middle;
    text-align: left;
}
.data-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
}
.data-table .num { text-align: right; }
.data-table tfoot td { background: #fafbfc; font-weight: 600; }
.data-table input[type="text"],
.data-table input[type="email"],
.data-table input[type="number"],
.data-table select {
    padding: .35rem .5rem;
    font-size: .9rem;
}
.row-pending td { background: #fff8e1; }
.empty { padding: 1rem; text-align: center; color: #94a3b8; }

/* ============================ Chips / estados ============================ */
.resumen {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.chip {
    padding: .35rem .75rem;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 600;
    background: #e5e7eb;
    color: #111;
}
.chip-ok   { background: #c8e6c9; color: #1b5e20; }
.chip-warn { background: #ffe082; color: #6d4c00; }
.chip-err  { background: #ffcdd2; color: #b71c1c; }

.estado {
    padding: .25rem .55rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    white-space: nowrap;
}
.estado-ok    { background: #c8e6c9; color: #1b5e20; }
.estado-warn  { background: #ffe082; color: #6d4c00; }
.estado-err   { background: #ffcdd2; color: #b71c1c; }
.estado-neutro{ background: #e5e7eb; color: #475569; }

/* ============================ Checkbox grid (asignaciones) ============================ */
.checkbox-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: .35rem .75rem;
    margin: .5rem 0 1rem;
}
@media (min-width: 600px) {
    .checkbox-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
    .checkbox-grid { grid-template-columns: repeat(3, 1fr); }
}
.check-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .45rem .65rem;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafbfc;
    cursor: pointer;
    font-weight: 500;
    color: #111;
    margin: 0;
}
.check-item input { width: auto; }
.check-item small { color: #94a3b8; font-weight: 400; }

/* ============================ Operador: lista de grupos ============================ */
.grupo-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: .85rem;
}
@media (min-width: 700px) {
    .grupo-list { grid-template-columns: repeat(2, 1fr); }
}
.grupo-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}
.grupo-card header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}
.grupo-desc { color: #475569; margin: 0; font-size: .9rem; }
.grupo-meta { color: #6b7280; font-size: .85rem; }

/* ============================ Operador: form de carga ============================ */
.items-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-bottom: 5rem;
}
.item-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}
.item-row.item-cargado { border-color: #c8e6c9; background: #f6fbf6; }
.item-info {
    flex: 1 1 auto;
    min-width: 0;
}
.item-info label {
    margin: 0;
    font-weight: 600;
    font-size: 1rem;
    color: #111;
}
.item-info .unidad {
    color: #6b7280;
    margin-left: .35rem;
}
.item-info .ultima-carga {
    display: block;
    color: #475569;
    font-size: .8rem;
    margin-top: .15rem;
}
.item-input {
    flex: 0 0 110px;
}
.item-input input {
    text-align: right;
    font-size: 1.1rem;
    font-weight: 600;
    padding: .65rem .5rem;
}
@media (min-width: 600px) {
    .item-input { flex-basis: 140px; }
}

/* Botón fijo abajo en móvil */
.sticky-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: .75rem 1rem;
    z-index: 5;
}

/* ============================ Login ============================ */
.login-body {
    background: #102a43;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 12px;
    padding: 1.75rem 1.5rem;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.login-card h1 {
    text-align: center;
    margin-bottom: .25rem;
    color: #102a43;
}
.login-card .subtitle {
    text-align: center;
    margin-bottom: 1.25rem;
}
.login-card label { margin-top: .85rem; }
.login-card button { margin-top: 1.25rem; }
