/* ============================================================
   Novedades de Producción — Granipack
   Sistema de diseño moderno con tema claro / oscuro
   ============================================================ */

:root {
    /* Marca */
    --brand: #1f8a4c;
    --brand-dark: #15623a;
    --brand-soft: #e8f5ee;
    --accent: #f4c430;

    /* Superficies y texto (tema claro) */
    --bg: #eceff3;
    --surface: #ffffff;
    --surface-2: #f6f8fa;
    --text: #1c2530;
    --text-soft: #64727f;
    --border: #e2e8ee;

    /* Estados */
    --danger: #c0392b;
    --danger-soft: #fbe4e1;
    --warn: #9a6b00;
    --warn-soft: #fdf3dc;
    --ok: #1f8a4c;
    --ok-soft: #e3f4ea;

    /* Efectos */
    --shadow: 0 4px 18px rgba(20, 30, 45, 0.06);
    --shadow-lg: 0 14px 44px rgba(20, 30, 45, 0.12);
    --radius: 14px;
    --radius-sm: 9px;
}

[data-theme="dark"] {
    --brand: #2ea865;
    --brand-dark: #1f8a4c;
    --brand-soft: #14352a;
    --accent: #f4c430;

    --bg: #0d1520;
    --surface: #16212e;
    --surface-2: #1e2b3a;
    --text: #e7edf3;
    --text-soft: #9aa8b6;
    --border: #2a3947;

    --danger: #ef6a5c;
    --danger-soft: #3a1f1c;
    --warn: #e8b64c;
    --warn-soft: #3a2f14;
    --ok: #2ea865;
    --ok-soft: #14352a;

    --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 14px 44px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background .25s, color .25s;
}

a { color: var(--brand-dark); }

/* ---------- Cabecera ---------- */
.cabecera {
    background: linear-gradient(100deg, var(--brand-dark), var(--brand));
    color: #fff;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 50;
}
.cabecera__contenido {
    max-width: 1240px;
    margin: 0 auto;
    padding: 0.7rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.6rem;
}
.cabecera__marca {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: #fff;
    text-decoration: none;
}
.cabecera__marca small { display: block; opacity: 0.82; font-size: 0.72rem; }
.cabecera__marca strong { font-size: 1rem; letter-spacing: .2px; }
.cabecera__wordmark { font-weight: 800; font-size: 1.05rem; letter-spacing: .5px; color: #fff; }
.cabecera__wordmark span { font-weight: 500; opacity: .8; letter-spacing: 0; }
.cabecera__nav { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
.cabecera__nav a {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.45rem 0.7rem;
    border-radius: 8px;
    transition: background .15s;
}
.cabecera__nav a:hover { background: rgba(255,255,255,0.16); }
.cabecera__usuario { font-size: 0.85rem; opacity: 0.92; padding: 0 0.3rem; }
.cabecera__salir { margin: 0; }
.cabecera__salir button {
    background: rgba(255,255,255,0.16);
    color: #fff;
    border: none;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background .15s;
}
.cabecera__salir button:hover { background: rgba(255,255,255,0.3); }

/* Botón de tema claro/oscuro (píldora con ícono + texto) */
.tema-toggle {
    background: rgba(255,255,255,0.16);
    border: none;
    color: #fff;
    height: 34px;
    padding: 0 0.8rem;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background .15s;
}
.tema-toggle:hover { background: rgba(255,255,255,0.3); }
.tema-toggle svg { width: 15px; height: 15px; vertical-align: -2px; margin-right: 0.35rem; }
.tema-toggle__claro, .tema-toggle__oscuro { display: inline-flex; align-items: center; }
.tema-toggle__oscuro { display: none; }
[data-theme="dark"] .tema-toggle__claro { display: none; }
[data-theme="dark"] .tema-toggle__oscuro { display: inline-flex; }

/* ---------- Contenido ---------- */
.contenido {
    max-width: 1240px;
    margin: 0 auto;
    padding: 1.6rem 1.2rem 3.5rem;
}
.seccion__encabezado { margin-bottom: 1.2rem; }
.seccion__encabezado h1, .seccion h1 { margin: 0 0 0.2rem; font-size: 1.55rem; letter-spacing: -.3px; }
.seccion__sub { margin: 0 0 1.2rem; color: var(--text-soft); }
.seccion--angosta { max-width: 580px; }
.resumen { color: var(--text-soft); margin: 0 0 0.9rem; }
.migaja { color: var(--text-soft); font-size: 0.85rem; margin: 0 0 0.5rem; }
.migaja a { color: var(--brand); text-decoration: none; font-weight: 600; }
.migaja a:hover { text-decoration: underline; }
.seccion__encabezado--fila {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; flex-wrap: wrap;
}

/* ---------- Avisos y mensajes ---------- */
.aviso {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.1rem;
    color: var(--text-soft);
    box-shadow: var(--shadow);
}
.aviso--error { border-left: 4px solid var(--danger); color: var(--text); }
.aviso--error strong { color: var(--danger); }
.aviso p { margin: 0.4rem 0 0; word-break: break-word; }

.mensajes { margin-bottom: 1.1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.mensaje {
    padding: 0.75rem 1rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    box-shadow: var(--shadow);
}
.mensaje--success { border-left: 4px solid var(--ok); }
.mensaje--error { border-left: 4px solid var(--danger); color: var(--danger); }

/* ---------- Botones ---------- */
.boton {
    background: var(--brand);
    color: #fff;
    border: none;
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.98rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-block;
    text-align: center;
    text-decoration: none;
    transition: background .15s, transform .05s, box-shadow .15s;
    box-shadow: 0 2px 8px rgba(31,138,76,.25);
}
.boton:hover { background: var(--brand-dark); }
.boton:active { transform: translateY(1px); }
.boton--compacto { padding: 0.55rem 0.9rem; font-size: 0.9rem; }
.boton--grande { padding: 1.1rem 1rem; font-size: 1.05rem; }
.boton--secundario {
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); box-shadow: none;
}
.boton--secundario:hover { background: var(--border); }
.boton--peligro { background: var(--danger); box-shadow: 0 2px 8px rgba(192,57,43,.25); }
.boton--peligro:hover { background: #9a291c; }
.boton:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tarjetas (inicio admin) ---------- */
.tarjetas {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1rem;
}
.tarjeta {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    box-shadow: var(--shadow);
    transition: box-shadow .18s, transform .18s, border-color .18s;
}
.tarjeta:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
    border-color: var(--brand);
}
.tarjeta--destacada { border-color: var(--brand); background: var(--brand-soft); }
.tarjeta__nombre { font-weight: 700; font-size: 1.06rem; }
.tarjeta__total { color: var(--text-soft); font-size: 0.85rem; }

/* ---------- Detalle de orden ---------- */
.detalle {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem;
    margin-bottom: 1.4rem;
    box-shadow: var(--shadow);
}
.detalle__dato { display: flex; flex-direction: column; gap: 0.15rem; }
.detalle__dato span { color: var(--text-soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: .04em; }
.detalle__dato strong { font-size: 1rem; }
.botonera { display: flex; gap: 1rem; flex-wrap: wrap; }
.boton--grande { flex: 1 1 220px; }

.enlace-orden { color: var(--brand-dark); font-weight: 700; text-decoration: none; }
.enlace-orden:hover { text-decoration: underline; }

/* ---------- Tablas ---------- */
.tabla-envoltura {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.tabla { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tabla thead th {
    background: var(--brand-dark);
    color: #fff;
    text-align: left;
    padding: 0.75rem 0.85rem;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.85rem;
}
.tabla tbody td { padding: 0.68rem 0.85rem; border-top: 1px solid var(--border); }
.tabla tbody tr:nth-child(even) { background: var(--surface-2); }
.tabla .num { text-align: right; }
.acciones a { margin-right: 0.7rem; text-decoration: none; color: var(--brand-dark); font-weight: 600; }
.acciones a.enlace-peligro { color: var(--danger); }
.fila-subtipo td { font-weight: 500; background: var(--surface-2) !important; color: var(--text-soft); }
.fila-subtotal td { font-weight: 700; background: var(--brand-soft) !important; }
.fila-total td { font-weight: 700; background: var(--brand) !important; color: #fff; }

/* Etiquetas de estado */
.etiqueta { display: inline-block; padding: 0.18rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.etiqueta--liberada { background: var(--ok-soft); color: var(--ok); }
.etiqueta--planificada { background: var(--warn-soft); color: var(--warn); }
.etiqueta--cerrada { background: var(--surface-2); color: var(--text-soft); }
.etiqueta--cancelada { background: var(--danger-soft); color: var(--danger); }

/* ---------- Formularios ---------- */
.formulario {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}
.campo { display: flex; flex-direction: column; margin-bottom: 1.15rem; }
.campo > label { font-weight: 600; margin-bottom: 0.4rem; font-size: 0.92rem; }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="time"], input[type="datetime-local"],
select, textarea, .formulario input {
    padding: 0.62rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(31,138,76,.18);
}

/* Select pulido con flecha propia */
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364727f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    padding-right: 2.2rem;
    cursor: pointer;
}

/* Casillas y radios modernos */
input[type="checkbox"], input[type="radio"] {
    width: 18px; height: 18px; accent-color: var(--brand);
    cursor: pointer; vertical-align: middle;
}

/* Grupos de casillas múltiples (máquinas, operarios, etc.) como chips */
.campo > div { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.campo > div > div { margin: 0; }
.campo > div > div label {
    display: inline-flex; align-items: center; gap: 0.45rem;
    background: var(--surface-2); border: 1px solid var(--border);
    padding: 0.45rem 0.75rem; border-radius: 999px; cursor: pointer;
    font-size: 0.9rem; font-weight: 500; transition: border-color .15s, background .15s;
}
.campo > div > div label:hover { border-color: var(--brand); }

.campo .ayuda { color: var(--text-soft); font-size: 0.8rem; margin-top: 0.3rem; }
.campo .error, .error { color: var(--danger); font-size: 0.82rem; margin-top: 0.3rem; }
.formulario__acciones { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }

/* ---------- Login ---------- */
.cuerpo-login {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1rem;
    background:
        radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent),
        var(--bg);
}
.login-tarjeta {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 2rem 1.9rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}
.login-marca { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; margin-bottom: 1.3rem; text-align: center; }
.login-marca__wordmark { font-weight: 800; font-size: 1.5rem; letter-spacing: 1px; color: var(--brand); }
.login-marca small { display: block; color: var(--text-soft); font-size: 0.82rem; }
.login-titulo { margin: 0 0 1.1rem; font-size: 1.3rem; text-align: center; }
.login-form { display: flex; flex-direction: column; }
.login-form label { font-weight: 600; margin: 0.6rem 0 0.3rem; font-size: 0.9rem; }
.login-form .boton { margin-top: 1.3rem; width: 100%; }
.login-credito { text-align: center; color: var(--text-soft); font-size: 0.78rem; margin: 1.2rem 0 0; }

/* ---------- Buscador ---------- */
.buscador { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.buscador input { flex: 1; min-width: 220px; }

/* ---------- Paginación ---------- */
.paginacion { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; justify-content: center; }
.paginacion__info { color: var(--text-soft); font-size: 0.9rem; }

/* ---------- Informe / Dashboard ---------- */
.acciones-informe {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 1rem; flex-wrap: wrap; margin-bottom: 1.3rem;
}
.filtros { display: flex; gap: 0.7rem; align-items: flex-end; flex-wrap: wrap; }
.filtros__campo { display: flex; flex-direction: column; gap: 0.25rem; }
.filtros__campo label { font-size: 0.78rem; font-weight: 600; color: var(--text-soft); }
.filtros__campo input, .filtros__campo select { width: auto; min-width: 150px; }
.acciones-informe__export { display: flex; gap: 0.5rem; }

.informe {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    max-width: 960px;
    margin: 0 auto;
    overflow: hidden;
}
.informe__cabecera {
    background: linear-gradient(100deg, var(--brand-dark), var(--brand));
    color: #fff;
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; flex-wrap: wrap;
    padding: 1.4rem 1.8rem;
}
.informe__marca { display: flex; align-items: center; gap: 0.8rem; }
.informe__marca img { height: 50px; width: auto; border-radius: 10px; background: #fff; padding: 3px; }
.informe__marca strong { font-size: 1.1rem; }
.informe__marca small { display: block; opacity: 0.85; font-size: 0.75rem; }
.informe__meta { text-align: right; font-size: 0.8rem; opacity: 0.92; line-height: 1.7; }
.informe__titulo { font-size: 1.5rem; margin: 1.4rem 1.8rem 0.4rem; letter-spacing: -.3px; }
.informe > .aviso { margin: 1.4rem 1.8rem; }
.informe__seccion { font-size: 1.08rem; margin: 1.8rem 1.8rem 0.9rem; color: var(--brand-dark); }
[data-theme="dark"] .informe__seccion { color: var(--brand); }

.kpis {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.9rem; padding: 1.4rem 1.8rem 0;
}
.kpi {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.1rem;
    display: flex; flex-direction: column; gap: 0.25rem;
}
.kpi:last-child { background: var(--warn-soft); border-color: transparent; }
.kpi__num { font-size: 1.7rem; font-weight: 800; color: var(--brand-dark); line-height: 1.1; }
[data-theme="dark"] .kpi__num { color: var(--brand); }
.kpi:last-child .kpi__num { font-size: 1.2rem; color: var(--warn); }
.kpi__lbl { font-size: 0.8rem; color: var(--text-soft); }

.grafico { padding: 0 1.8rem; display: flex; flex-direction: column; gap: 0.7rem; }
.barra-fila { display: flex; align-items: center; gap: 0.8rem; }
.barra-fila__etq { flex: 0 0 120px; font-weight: 600; font-size: 0.9rem; }
.barra-fila__pista { flex: 1; background: var(--surface-2); border-radius: 999px; height: 20px; overflow: hidden; border: 1px solid var(--border); }
.barra-fila__valor { background: linear-gradient(90deg, var(--brand), var(--brand-dark)); height: 100%; border-radius: 999px; min-width: 3px; }
.barra-fila__num { flex: 0 0 72px; text-align: right; font-size: 0.85rem; color: var(--text-soft); }

.tabla--informe { width: 100%; border-collapse: collapse; margin: 0.3rem 0 1.8rem; }
.tabla--informe th { background: var(--brand-dark); color: #fff; text-align: left; padding: 0.6rem 1.8rem; font-size: 0.85rem; }
.tabla--informe th.num, .tabla--informe td.num { text-align: right; }
.tabla--informe td { padding: 0.55rem 1.8rem; border-top: 1px solid var(--border); font-size: 0.9rem; }
.tabla--informe tbody tr:nth-child(even) { background: var(--surface-2); }

@media (max-width: 760px) {
    .barra-fila__etq { flex-basis: 88px; }
}

/* ---------- Responsive: tablas -> tarjetas en celular ---------- */
@media (max-width: 760px) {
    .tabla-envoltura { border: none; background: transparent; box-shadow: none; }
    .tabla thead { display: none; }
    .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
    .tabla tr {
        background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); margin-bottom: 0.8rem; padding: 0.3rem 0.2rem;
        box-shadow: var(--shadow);
    }
    .tabla tbody tr:nth-child(even) { background: var(--surface); }
    .tabla td { border: none; display: flex; justify-content: space-between; gap: 1rem; padding: 0.5rem 0.9rem; text-align: right; }
    .tabla td::before { content: attr(data-etq); font-weight: 600; color: var(--text-soft); text-align: left; }
    .tabla .num { text-align: right; }
}

/* ---------- Pie ---------- */
.pie { text-align: center; color: var(--text-soft); padding: 1.5rem 1rem 2rem; font-size: 0.85rem; }

/* ---------- Impresión / PDF ---------- */
@media print {
    .cabecera, .pie, .no-imprimir { display: none !important; }
    body { background: #fff; }
    .contenido { padding: 0; max-width: none; }
    .informe { border: none; box-shadow: none; border-radius: 0; max-width: none; }
    .tabla--informe { font-size: 0.8rem; }
    table, tr, .kpi { break-inside: avoid; }
}
