/* ============================================================
   Registre de Viatgers v2 — estilos base
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    color: #1e293b;
    line-height: 1.5;
    overflow-x: hidden;   /* safeguard: ningún elemento puede provocar scroll horizontal */
    max-width: 100vw;
}
img, svg, video { max-width: 100%; height: auto; }
a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layouts */
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px; }
.wrap-narrow { max-width: 480px; margin: 60px auto 24px; padding: 0 20px; }
.wrap-form   { max-width: 720px; margin: 0 auto; padding: 24px 20px; }

/* Header */
.app-header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 16px 20px;
}
.app-header .inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.app-header h1 { font-size: 20px; margin: 0; color: #1d4ed8; }
.app-header nav a { margin-left: 16px; color: #64748b; font-size: 14px; }
.app-header nav a:hover { color: #1d4ed8; }

/* Card */
.card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card h2 { font-size: 18px; margin: 0 0 16px; color: #1e293b; }
.card h3 { font-size: 14px; margin: 16px 0 8px; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; }

/* Forms */
.form-group { margin-bottom: 16px; min-width: 0; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    min-width: 0;
}
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #475569;
}
label .req { color: #dc2626; margin-left: 2px; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=time], input[type=tel],
select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
input.error, select.error, textarea.error {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}
.help { font-size: 12px; color: #64748b; margin-top: 4px; }
.err-msg { font-size: 12px; color: #dc2626; margin-top: 4px; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.05s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; text-decoration: none; }
.btn-success { background: #059669; color: white; }
.btn-success:hover { background: #047857; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: #d97706; color: white; }
.btn-warning:hover { background: #b45309; }
.btn-secondary { background: white; color: #1e293b; border-color: #cbd5e1; }
.btn-secondary:hover { background: #f1f5f9; }
.btn-large { padding: 14px 28px; font-size: 16px; }
.btn-block { display: block; width: 100%; text-align: center; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* Tables */
table.data {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 14px;
}
table.data th, table.data td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
}
table.data th {
    background: #f8fafc;
    color: #64748b;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
table.data tr:hover td { background: #f8fafc; }
table.data .actions { white-space: nowrap; }

/* Status tags */
.tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.tag-open       { background: #dbeafe; color: #1e40af; }
.tag-complete   { background: #fef3c7; color: #92400e; }
.tag-generated  { background: #dcfce7; color: #166534; }
.tag-validated  { background: #e0e7ff; color: #3730a3; }
.tag-deleted    { background: #f1f5f9; color: #64748b; }

/* Páginas públicas (huésped): tipografía Inconsolata
   No afecta al admin; se aplica solo si el body tiene .public-page */
body.public-page {
    font-family: 'Inconsolata', 'Courier New', monospace;
}
.public-footer {
    text-align: center;
    padding: 24px 16px;
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.7;
}
.public-footer .hutb { margin-bottom: 4px; }
.public-footer .hutb strong { color: #64748b; letter-spacing: 0.03em; }
.public-footer a { color: #94a3b8; }
body.public-page input,
body.public-page select,
body.public-page textarea,
body.public-page button,
body.public-page .btn {
    font-family: 'Inconsolata', 'Courier New', monospace;
}

/* Language picker (huésped) */
.lang-picker {
    text-align: center;
    margin-top: 60px;
}
.lang-picker .estab-logo {
    display: block;
    max-width: 240px;
    width: 100%;
    height: auto;
    margin: 0 auto 16px;
}
.lang-picker .estab-title {
    font-family: Georgia, 'Times New Roman', 'Source Serif Pro', serif;
    font-weight: 400;
    font-size: 32px;
    margin-bottom: 4px;
    color: #B88A3F;
    letter-spacing: 0.02em;
}
.lang-picker .purpose {
    color: #475569;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 20px;
    letter-spacing: 0.02em;
}
.lang-picker .subtitle {
    color: #64748b;
    margin-bottom: 40px;
}
.lang-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 320px;
    margin: 0 auto;
}
.lang-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}
.lang-btn:hover { border-color: #2563eb; transform: translateY(-2px); text-decoration: none; }
.lang-btn.suggested { border-color: #2563eb; background: #eff6ff; }
.lang-btn .flag { font-size: 24px; }

/* Form helpers */
.section-title {
    background: #eff6ff;
    border-left: 4px solid #2563eb;
    padding: 12px 16px;
    font-weight: 600;
    color: #1d4ed8;
    margin: 24px -24px 16px -24px;
}
.section-title:first-child { margin-top: 0; }
.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
/* Mobile-first responsive (móvil = 99% del uso para huéspedes) */
@media (max-width: 700px) {
    .wrap       { padding: 12px 12px; max-width: 100%; }
    .wrap-form  { padding: 12px 12px; max-width: 100%; }
    .wrap-narrow { margin: 20px auto 16px; padding: 0 12px; }
    .card { padding: 16px; border-radius: 10px; }
    .card h2 { font-size: 17px; }
    .field-row, .form-grid { grid-template-columns: 1fr !important; gap: 12px; }

    /* Inputs táctiles: 16px de fuente para evitar zoom auto en iOS */
    input[type=text], input[type=email], input[type=password],
    input[type=number], input[type=date], input[type=time], input[type=tel],
    select, textarea {
        font-size: 16px;
        padding: 12px 14px;
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    /* CRÍTICO: en iOS/Safari los <input type=date|time> ignoran width:100%
       por su "intrinsic size" del placeholder ("dd/mm/yyyy"). Forzamos
       appearance:none para neutralizar el styling del SO y respetar el
       layout. El picker nativo sigue funcionando. */
    input[type=date], input[type=time] {
        -webkit-appearance: none;
        appearance: none;
        background-color: white;
        line-height: 1.2;
    }
    /* iOS muestra un icono interno que a veces empuja el contenido */
    input[type=date]::-webkit-date-and-time-value,
    input[type=time]::-webkit-date-and-time-value {
        text-align: left;
        min-width: 0;
    }

    label { font-size: 14px; }
    .section-title {
        font-size: 14px;
        padding: 10px 14px;
        margin: 18px -16px 12px -16px;
    }

    /* Sticky actions ocupan ancho completo, stack vertical si hace falta */
    .sticky-actions {
        margin: 20px -16px -16px -16px;
        padding: 12px 14px;
        gap: 8px;
    }
    .sticky-actions .btn { max-width: none; min-height: 48px; }

    /* Botones táctiles min 44x44 px (estándar accesibilidad) */
    .btn { min-height: 44px; padding: 12px 18px; font-size: 15px; }
    .btn-large { padding: 14px 22px; font-size: 16px; }

    /* Selector de idiomas: botones más grandes */
    .lang-picker { margin-top: 30px; }
    .lang-picker .estab-title { font-size: 24px; }
    .lang-picker .estab-logo { max-width: 180px; margin-bottom: 12px; }
    .lang-picker .purpose { font-size: 14px; margin-bottom: 16px; }
    .lang-buttons { padding: 0 8px; }
    .lang-btn { padding: 18px 20px; font-size: 17px; min-height: 64px; }

    /* Tabla: scroll horizontal si no cabe (admin) */
    table.data {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        font-size: 13px;
    }
    table.data th, table.data td { padding: 8px 10px; }

    /* Card de bienvenida del establecimiento */
    .app-header { padding: 12px 14px; }
    .app-header h1 { font-size: 17px; }
    .app-header nav a { margin-left: 10px; font-size: 13px; }
    .app-header .inner { flex-wrap: wrap; gap: 4px; }

    /* kv-list (detalle contrato) en una columna */
    .kv-list { grid-template-columns: 1fr; gap: 4px 0; }
    .kv-list dt { font-weight: 600; margin-top: 8px; }
    .kv-list dd { margin: 0 0 4px; }

    /* Modal centrado, padding mejor */
    #error-modal > div { padding: 20px; max-width: 95%; }
    #error-modal h3 { font-size: 16px; }
}

/* iOS quirks adicionales */
@supports (-webkit-touch-callout: none) {
    /* Inputs en iOS necesitan font-size mínimo 16px para no hacer zoom */
    input, select, textarea { font-size: 16px !important; }
}

/* Admin dashboard — filtros por estado (tabs) */
.status-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 16px;
    padding-bottom: 0;
}
.status-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    color: #64748b;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
}
.status-tab:hover {
    color: #1d4ed8;
    text-decoration: none;
}
.status-tab.active {
    color: #1d4ed8;
    border-bottom-color: #2563eb;
    font-weight: 600;
}
.status-tab-count {
    background: #f1f5f9;
    color: #64748b;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    min-width: 22px;
    text-align: center;
}
.status-tab.active .status-tab-count {
    background: #dbeafe;
    color: #1d4ed8;
}

/* Admin dashboard — fila verde para contratos OPEN */
table.data tr.row-open td {
    background: #f0fdf4;        /* verde claro */
}
table.data tr.row-open:hover td {
    background: #dcfce7;        /* verde un pelín más saturado al hover */
}

/* Admin dashboard — botones de acción por fila */
.row-actions {
    display: inline-flex;
    gap: 6px;
    flex-wrap: nowrap;
}
.btn-row {
    padding: 5px 10px;
    font-size: 12px;
    min-height: 0;
    line-height: 1.4;
}

/* Admin dashboard — paginación */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}
.pagination-info { font-size: 13px; }
.pagination-controls {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Sticky action bar at bottom of form */
.sticky-actions {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 16px;
    margin: 24px -24px -24px -24px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.sticky-actions .btn { flex: 1; max-width: 200px; }

/* Detail page */
.kv-list { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; }
.kv-list dt { color: #64748b; font-size: 13px; }
.kv-list dd { margin: 0; font-weight: 500; }

/* Progress indicator */
.progress-indicator {
    background: #eff6ff;
    border: 1px solid #93c5fd;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    color: #1e40af;
    font-size: 14px;
    text-align: center;
}

/* Misc */
.muted { color: #64748b; }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
hr { border: 0; border-top: 1px solid #e2e8f0; margin: 24px 0; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.share-link-box {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    padding: 16px;
    margin: 16px 0;
}
.share-link-box code {
    word-break: break-all;
    display: block;
    padding: 12px;
    margin: 8px 0;
    background: white;
    border: 1px solid #fcd34d;
}
