:root {
    color-scheme: light;

    /* Paleta corporativa Marsol: única fuente de los colores internos.
       El portal ejecutivo y los correos tienen sus propios estilos. */
    /* Azul marino del logo oficial (marsol-logo.png). --brand-700 es el
       mismo tono (210°) más claro: ítem activo, hover y enlaces. */
    --brand-900: #002e5d;
    --brand-700: #0051a3;
    --accent: #27b5c9;
    --bg: #f4f8fb;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --success: #16a34a;
    --warning: #f59e0b;

    /* Derivados. --text-muted no llega a 4,5:1 sobre --bg (4,46): el texto
       secundario directamente sobre el fondo usa --text-secondary. */
    --on-brand: #ffffff;
    --text-secondary: #475569;
    --focus-ring: var(--brand-700);
    /* --success (3,3:1 con blanco) queda para bordes y puntos; el texto y
       los glifos sobre verde usan --success-strong (5:1). */
    --success-strong: #15803d;

    /* Tintes suaves por categoría (fondo del ícono y su trazo, ≥ 3:1). */
    --tint-brand: #e8f2fa;
    --tint-brand-ink: var(--brand-900);
    --tint-accent: #e3f6f9;
    --tint-accent-ink: #0b7285;
    --tint-warning: #fef3e2;
    --tint-warning-ink: #b45309;
    --tint-success: #e7f6ec;
    --tint-success-ink: #166534;
    --tint-neutral: #eef2f6;
    --tint-neutral-ink: var(--text-secondary);
    --tint-danger: #fdeeee;
    --tint-danger-ink: #9b2c2c;

    /* Nombres heredados que usan las demás hojas, apuntando a la paleta. */
    --color-primary-950: var(--text);
    --color-primary-900: var(--brand-900);
    --color-primary-800: var(--brand-900);
    --color-primary-600: var(--brand-700);
    --color-cyan: var(--accent);
    --color-accent: var(--accent);

    --color-copper: #c97b36;
    --color-warning: var(--warning);
    --color-danger: #b23a3a;
    --color-success: var(--success);

    --color-background: var(--bg);
    --color-surface: var(--surface);
    --color-graphite: #2e3a46;
    --color-text: var(--text);
    --color-muted: var(--text-muted);
    --color-text-muted: var(--text-muted);
    --color-border: var(--border);

    --gradient-brand: linear-gradient(
        135deg,
        var(--brand-900) 0%,
        var(--brand-700) 100%
    );

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --content-width: 1200px;
}

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

/* El atributo hidden oculta siempre, aunque la clase del elemento
   defina su propio display (p. ej. .button { display: inline-flex }). */
[hidden] {
    display: none !important;
}

html {
    min-width: 320px;
    background: var(--color-background);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--color-text);
    background: var(--color-background);
    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

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

img {
    display: block;
    max-width: 100%;
}

/* Encabezado principal */

.app-header {
    position: sticky;
    z-index: 100;
    top: 0;
    color: #ffffff;
    background: var(--gradient-brand);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
}

.app-header__inner {
    display: flex;
    width: min(100%, var(--content-width));
    min-height: 68px;
    margin: 0 auto;
    padding: 12px 16px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    min-width: 0;
    color: #ffffff;
    text-decoration: none;
}

.brand__name {
    display: block;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.brand__tagline {
    display: none;
    margin-top: 1px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.75rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-link,
.header-button {
    display: inline-flex;
    min-height: 44px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
    cursor: pointer;
}

.header-link:hover,
.header-button:hover {
    background: rgba(255, 255, 255, 0.16);
}

.header-label {
    display: none;
}

.logout-form {
    margin: 0;
}

/* Contenido */

.app-main {
    width: min(100%, var(--content-width));
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.page-header {
    margin-bottom: 22px;
}

.page-header__eyebrow {
    margin: 0 0 5px;
    color: var(--color-primary-600);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.page-header h1 {
    margin: 0;
    color: var(--color-primary-950);
    font-size: clamp(1.65rem, 6vw, 2.4rem);
    line-height: 1.15;
}

.page-header p {
    max-width: 700px;
    margin: 8px 0 0;
    color: var(--text-secondary);
}

/* Tarjetas */

.card {
    padding: 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
}

.card--accent {
    border-top: 4px solid var(--color-cyan);
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.action-card {
    display: flex;
    min-height: 170px;
    padding: 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    flex-direction: column;
    color: inherit;
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    transition:
        transform 160ms ease,
        border-color 160ms ease,
        box-shadow 160ms ease;
}

.action-card:hover {
    border-color: var(--color-cyan);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.action-card__title {
    margin: 0 0 8px;
    color: var(--color-primary-800);
    font-size: 1.1rem;
}

.action-card__description {
    margin: 0 0 18px;
    color: var(--color-muted);
}

.action-card__link {
    margin-top: auto;
    color: var(--color-primary-600);
    font-weight: 750;
}

/* Botones */

.button {
    display: inline-flex;
    width: 100%;
    min-height: 46px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--on-brand);
    background: var(--brand-900);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 150ms ease;
}

.button:hover {
    background: var(--brand-700);
}

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

.button--secondary:hover {
    background: var(--tint-brand);
}

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

.button--copper {
    background: var(--color-copper);
}

/* Formularios */

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

.form-group,
form p {
    margin: 0 0 18px;
}

label {
    display: block;
    margin-bottom: 7px;
    color: var(--color-graphite);
    font-size: 0.9rem;
    font-weight: 700;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100%;
    min-height: 48px;
    padding: 11px 13px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    background-color: #ffffff;
    outline: none;
    transition:
        border-color 150ms ease,
        box-shadow 150ms ease;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

/* Fecha y hora. En iOS Safari el control nativo se sale de la tarjeta,
   centra el valor y, vacío, es una caja en blanco: se dibuja como los
   demás campos, alineado a la izquierda, con su ícono a la derecha y una
   pista "dd-mm-aaaa" / "--:--" mientras está vacío (date_inputs.js marca
   .is-empty). El selector nativo sigue funcionando: en iOS al tocar el
   campo y en Chrome con el botón invisible sobre el ícono. */
/* :not([type="checkbox"]) iguala la especificidad de la regla general de
   arriba, que si no ganaría el padding y el fondo. */
input:not([type="checkbox"]):is([type="date"], [type="time"], [type="datetime-local"], [type="month"]) {
    --date-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%231e5a8a' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M16 3v4M8 3v4M3 10h18'/%3E%3C/svg%3E");
    --date-hint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='24'%3E%3Ctext x='0' y='17' font-family='-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif' font-size='16' fill='%238a96a8'%3Edd-mm-aaaa%3C/text%3E%3C/svg%3E");
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    min-height: 48px;
    padding-right: 46px;
    -webkit-appearance: none;
    appearance: none;
    background-color: #ffffff;
    background-image: var(--date-icon);
    background-position: right 13px center;
    background-repeat: no-repeat;
    background-size: 20px 20px;
    font-size: max(16px, 1rem);
    line-height: 1.5;
    text-align: left;
}

input:not([type="checkbox"])[type="time"] {
    --date-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%231e5a8a' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
    --date-hint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='24'%3E%3Ctext x='0' y='17' font-family='-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif' font-size='16' fill='%238a96a8'%3E--:--%3C/text%3E%3C/svg%3E");
}

input:not([type="checkbox"])[type="month"] {
    --date-hint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='24'%3E%3Ctext x='0' y='17' font-family='-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif' font-size='16' fill='%238a96a8'%3Emm-aaaa%3C/text%3E%3C/svg%3E");
}

input:not([type="checkbox"])[type="datetime-local"] {
    --date-hint: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='170' height='24'%3E%3Ctext x='0' y='17' font-family='-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif' font-size='16' fill='%238a96a8'%3Edd-mm-aaaa --:--%3C/text%3E%3C/svg%3E");
}

/* Vacío y sin foco: la pista reemplaza al texto nativo (que iOS no
   muestra y Chrome muestra con otro formato). Con foco vuelve el control
   nativo para escribir o elegir. */
input.is-empty:not(:focus):is([type="date"], [type="time"], [type="datetime-local"], [type="month"]) {
    color: transparent;
    background-image: var(--date-hint), var(--date-icon);
    background-position: left 13px center, right 13px center;
    background-size: auto 24px, 20px 20px;
}

input.is-empty:not(:focus)::-webkit-datetime-edit {
    color: transparent;
}

input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value,
input[type="month"]::-webkit-date-and-time-value {
    min-height: 1.5em;
    margin: 0;
    text-align: left;
}

input[type="date"]::-webkit-datetime-edit,
input[type="time"]::-webkit-datetime-edit,
input[type="datetime-local"]::-webkit-datetime-edit,
input[type="month"]::-webkit-datetime-edit {
    padding: 0;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
    position: absolute;
    top: 0;
    right: 0;
    width: 46px;
    height: 100%;
    margin: 0;
    padding: 0;
    opacity: 0;
    cursor: pointer;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--focus-ring);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-700) 18%, transparent);
}

/* Campo con error (Django marca aria-invalid en los campos con errores).
   Igual especificidad que la regla general de los campos, que va antes. */
input:not([type="checkbox"]):not([type="radio"])[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: var(--color-danger);
}

input:not([type="checkbox"]):not([type="radio"])[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-danger) 20%, transparent);
}

.helptext {
    display: block;
    margin-top: 6px;
    color: var(--color-muted);
    font-size: 0.82rem;
}

.errorlist {
    margin: 6px 0;
    padding-left: 20px;
    color: var(--color-danger);
    font-size: 0.88rem;
}

/* Mensajes */

.messages {
    display: grid;
    margin: 0 0 20px;
    padding: 0;
    gap: 10px;
    list-style: none;
}

.alert {
    padding: 13px 15px;
    border: 1px solid var(--color-border);
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    background: #ffffff;
}

.alert--success {
    border-left-color: var(--color-success);
}

.alert--warning {
    border-left-color: var(--color-warning);
}

.alert--error {
    border-left-color: var(--color-danger);
}

.alert--info {
    border-left-color: var(--color-cyan);
}

/* Tablas */

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

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

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

th {
    color: #ffffff;
    background: var(--color-primary-800);
    font-size: 0.82rem;
    letter-spacing: 0.03em;
}

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

tbody tr:hover {
    background: #f7fafc;
}

/* Estados */

.badge {
    display: inline-flex;
    padding: 4px 9px;
    border-radius: 999px;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 750;
    white-space: nowrap;
}

.badge--info {
    color: #145d68;
    background: #dff5f7;
}

.badge--success {
    color: #236c47;
    background: #e2f3e9;
}

.badge--warning {
    color: #755514;
    background: #fff2ce;
}

.badge--danger {
    color: #8f2e2e;
    background: #f9dfdf;
}

.badge--neutral {
    color: #45525e;
    background: #e9eef2;
}

/* Órdenes de equipos que no están en el contrato del CECO. */
.badge--out-of-contract {
    color: #7a4313;
    background: #fbe9d8;
    box-shadow: inset 0 0 0 1px var(--color-copper);
}

/* Responsive */

@media (min-width: 600px) {
    .brand__tagline,
    .header-label {
        display: inline;
    }

    .button {
        width: auto;
    }

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

    .app-main {
        padding-top: 32px;
    }
}

@media (min-width: 960px) {
    .app-header__inner {
        min-height: 76px;
        padding-inline: 24px;
    }

    .app-main {
        padding-inline: 24px;
    }

    .card-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 20px;
    }

    .card,
    .action-card {
        padding: 24px;
    }
}

/* Accesibilidad y navegación */

.skip-link {
    position: fixed;
    z-index: 200;
    top: 8px;
    left: 8px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: #ffffff;
    background: var(--color-primary-950);
    transform: translateY(-150%);
}

.skip-link:focus {
    transform: translateY(0);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 3px;
}

.app-header a:focus-visible,
.app-header button:focus-visible {
    outline-color: #ffffff;
}

.header-link,
.header-button {
    gap: 8px;
}

.header-actions svg {
    flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}


/* Clasificación de la orden (classification_badge.html). */
.badge--class-fault_report {
    color: #7a5200;
    background: #fff4d6;
}

.badge--class-corrective {
    color: #8a3b12;
    background: #fbe7da;
}

.badge--class-technical_visit {
    color: #145d68;
    background: #dff5f7;
}

.badge--class-preventive {
    color: #236c47;
    background: #e2f3e9;
}
