:root {
    --ubiot-primary: #D32F2F;
    --ubiot-primary-dark: #B71C1C;
    --ubiot-primary-light: #FFEBEE;
    --ubiot-bg: #ffffff;
    --ubiot-bg-secondary: #f5f5f5;
    --ubiot-text: #212121;
    --ubiot-text-hint: #757575;
    --ubiot-accent: #D32F2F;
    --ubiot-button-text: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--ubiot-bg-secondary);
    color: var(--ubiot-text);
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ============ LOGIN ============ */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--ubiot-primary-dark) 0%, var(--ubiot-primary) 100%);
    padding: 20px;
}
.login-container {
    background: white;
    border-radius: 16px;
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    text-align: center;
}
.login-logo {
    margin-bottom: 8px;
}
.logo-ub {
    font-size: 48px;
    font-weight: 800;
    color: var(--ubiot-primary-dark);
}
.logo-iot {
    font-size: 48px;
    font-weight: 800;
    color: var(--ubiot-primary);
}
.login-subtitle {
    color: var(--ubiot-text-hint);
    font-size: 14px;
    margin-bottom: 32px;
}
.login-form {
    text-align: left;
}
.form-group {
    margin-bottom: 18px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ubiot-text-hint);
    margin-bottom: 6px;
}
.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus {
    border-color: var(--ubiot-primary);
}
.login-error {
    background: var(--ubiot-primary-light);
    color: var(--ubiot-primary-dark);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}
.login-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--ubiot-primary);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.login-btn:hover {
    background: var(--ubiot-primary-dark);
}
.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.login-link-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    color: #6b7280;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}
.login-link-btn:hover {
    background: #f9fafb;
}
.login-hint {
    margin-top: 14px;
    font-size: 12px;
    color: #6b7280;
    text-align: center;
    line-height: 1.5;
}
.login-hint strong {
    color: #374151;
}

/* ============ HEADER ============ */
.ubiot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--ubiot-primary-dark);
    color: white;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 101;
}
.header-logo {
    display: flex;
    align-items: baseline;
}
.logo-ub-sm {
    font-size: 20px;
    font-weight: 800;
    color: white;
}
.logo-iot-sm {
    font-size: 20px;
    font-weight: 800;
    color: var(--ubiot-primary-light);
}
.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.logout-btn {
    padding: 6px 14px;
    border: 1.5px solid rgba(255,255,255,0.5);
    border-radius: 6px;
    background: transparent;
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.logout-btn:hover {
    background: rgba(255,255,255,0.15);
}

/* ============ LOADING ============ */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
}
.loading.hidden { display: none; }
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #ddd;
    border-top-color: var(--ubiot-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ CARDS ============ */
.card {
    background: var(--ubiot-bg);
    border-radius: 12px;
    padding: 16px;
    margin: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* ============ TABS ============ */
.tab-panel { display: none; padding-bottom: 70px; }
.tab-panel.active { display: block; }

.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--ubiot-bg);
    border-top: 1px solid #e0e0e0;
    padding: 6px 0;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 1000;
}
.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    border: none;
    background: transparent;
    color: var(--ubiot-text-hint);
    font-size: 11px;
    cursor: pointer;
    transition: color 0.2s;
}
.tab-btn.active {
    color: var(--ubiot-primary);
}
.tab-btn svg {
    display: block;
}

/* ============ STATUS TAB ============ */
.status-card {
    text-align: center;
    padding: 32px 16px;
    margin-top: 20px;
}
.status-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.status-dot {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.3s;
}
.status-dot.open {
    background: #34c759;
    box-shadow: 0 0 20px rgba(52, 199, 89, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}
.status-dot.open::before {
    content: "";
    display: block;
    width: 18px;
    height: 34px;
    border: solid #fff;
    border-width: 0 6px 6px 0;
    transform: rotate(45deg);
    margin-bottom: 6px;
}
.status-dot.closed {
    background: #8e8e93;
}
.status-label {
    font-size: 20px;
    font-weight: 600;
}
.status-details {
    margin-top: 20px;
    font-size: 15px;
    line-height: 1.8;
}
.status-details .detail-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}
.status-details .detail-label {
    color: var(--ubiot-text-hint);
}
.status-details .detail-value {
    font-weight: 500;
}
.duration-live {
    font-size: 28px;
    font-weight: 700;
    color: var(--ubiot-primary);
    margin-top: 8px;
}

/* ============ HISTORY TAB ============ */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.cal-title {
    font-weight: 600;
    font-size: 16px;
    text-transform: capitalize;
}
.cal-nav {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--ubiot-bg-secondary);
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    color: var(--ubiot-text);
}
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
}
.cal-day-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--ubiot-text-hint);
    padding: 6px 0;
}
.cal-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
}
.cal-day-num {
    line-height: 1;
}
.cal-day-hours {
    font-size: 10px;
    font-weight: 600;
    color: #1b5e20;
    line-height: 1;
    white-space: nowrap;
}
.cal-day.selected .cal-day-hours {
    color: #fff;
}
.cal-day.other-month .cal-day-hours {
    display: none;
}
.cal-day:hover {
    background: var(--ubiot-bg-secondary);
}
.cal-day.today {
    font-weight: 700;
    color: var(--ubiot-primary);
}
.cal-day.selected {
    background: var(--ubiot-primary);
    color: white;
}
.cal-day.other-month {
    color: #ccc;
}

.history-list {
    padding: 0 12px 12px;
}
.history-item {
    background: var(--ubiot-bg);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.history-item .center-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
}
.history-item .time-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--ubiot-text-hint);
}
.history-item .time-row .time {
    color: var(--ubiot-text);
    font-weight: 500;
}
.history-item .duration-badge {
    display: inline-block;
    background: var(--ubiot-bg-secondary);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    margin-top: 4px;
    font-weight: 500;
}
.history-empty {
    text-align: center;
    padding: 24px;
    color: var(--ubiot-text-hint);
    font-size: 14px;
}

/* ============ MAP TAB ============ */
#tab-map {
    padding-bottom: 0;
}
.map-container {
    height: calc(100vh - 48px - 56px - env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    margin: 0;
}

/* ============ STATS TAB ============ */
.stats-period-btns {
    display: flex;
    gap: 8px;
    padding: 12px;
}
.period-btn {
    flex: 1;
    padding: 8px;
    border: 1.5px solid var(--ubiot-primary);
    background: transparent;
    color: var(--ubiot-primary);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.period-btn.active {
    background: var(--ubiot-primary);
    color: white;
}
.stats-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 0 12px;
}
.stat-card {
    text-align: center;
    padding: 14px 8px;
    margin: 0;
}
.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--ubiot-primary);
}
.stat-label {
    font-size: 11px;
    color: var(--ubiot-text-hint);
    margin-top: 4px;
}
.chart-card {
    margin-top: 8px;
    padding: 12px;
}

/* ============ FICHAJE BUTTON ============ */
.fichaje-btn {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 20px auto 0;
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    color: #fff;
}
.fichaje-btn:active {
    transform: scale(0.97);
}
.fichaje-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.fichaje-btn.entrada {
    background: #34c759;
    box-shadow: 0 4px 12px rgba(52, 199, 89, 0.3);
}
.fichaje-btn.salida {
    background: #ff3b30;
    box-shadow: 0 4px 12px rgba(255, 59, 48, 0.3);
}

/* ============ CENTER SELECTOR (fallback sin GPS) ============ */
.center-selector {
    margin-top: 20px;
    text-align: left;
}
.center-selector-header {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #FFF3E0;
    color: #E65100;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
}
.center-selector-icon {
    font-size: 18px;
}
.center-search {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
    margin-bottom: 12px;
    transition: border-color .15s;
}
.center-search:focus {
    border-color: #CF0A2C;
}
.center-selector-subtitle {
    font-size: 14px;
    color: var(--ubiot-text-hint);
    margin-bottom: 10px;
    text-align: center;
}
.center-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.center-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid #e0e0e0;
    border-radius: 10px;
    background: var(--ubiot-bg);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 15px;
}
.center-option:active {
    transform: scale(0.98);
    border-color: var(--ubiot-primary);
    background: var(--ubiot-primary-light);
}
.center-option-name {
    font-weight: 600;
    color: var(--ubiot-text);
}
.center-option-city {
    font-size: 13px;
    color: var(--ubiot-text-hint);
}
.center-option-default {
    border: 1.5px solid #CF0A2C;
    background: #fff5f6;
    margin-top: 8px;
}
.center-option-default .center-option-name {
    color: #CF0A2C;
    font-weight: 700;
}
.center-option-default:active {
    background: #ffe5e7;
}
.center-loading, .center-empty {
    text-align: center;
    padding: 16px;
    color: var(--ubiot-text-hint);
    font-size: 14px;
}
.center-cancel-btn {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: var(--ubiot-bg-secondary);
    color: var(--ubiot-text-hint);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

/* ============ RESPONSIVE DESKTOP ============ */
@media (min-width: 768px) {
    .login-container {
        padding: 48px 40px;
    }
    .tab-panel {
        max-width: 600px;
        margin: 0 auto;
    }
    .tab-bar {
        max-width: 600px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    }
    .ubiot-header {
        max-width: 600px;
        margin: 0 auto;
    }
    .map-container {
        height: calc(100vh - 140px);
        max-width: 600px;
        margin: 0 auto;
    }
}

/* ============ TAB FICHAJES (GESTOR) ============ */
.gestor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.gestor-title { margin: 0; font-size: 16px; color: var(--ubiot-text); }
.gestor-meta { font-size: 12px; color: var(--ubiot-text-hint); }
.gestor-search {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s;
}
.gestor-search:focus { border-color: #CF0A2C; }
.gestor-list { margin-top: 12px; }
.gestor-card {
    padding: 12px 14px;
    margin-bottom: 8px;
}
.gestor-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.gestor-col-main { flex: 1; min-width: 0; }
.gestor-col-side { text-align: right; flex-shrink: 0; }
.gestor-worker { font-weight: 600; color: var(--ubiot-text); font-size: 14px; }
.gestor-centro { font-size: 12px; color: var(--ubiot-text-hint); margin-top: 2px; }
.gestor-horas { font-family: monospace; font-size: 13px; color: #374151; margin-top: 4px; }
.gestor-dur { font-size: 11px; color: var(--ubiot-text-hint); }
.gestor-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 10px;
    letter-spacing: .04em;
}
.gestor-pill-open { background: #dcfce7; color: #166534; }
.gestor-pill-closed { background: #e5e7eb; color: #374151; }
.gestor-tipo {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 700;
    background: #dbeafe;
    color: #1e40af;
    letter-spacing: .05em;
}
.gestor-loading, .gestor-empty {
    text-align: center;
    padding: 24px;
    color: var(--ubiot-text-hint);
    font-style: italic;
}

/* === PWA install button (junto al logo del login) === */
.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.install-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1.5px solid var(--ubiot-primary);
    border-radius: 8px;
    background: #fff;
    color: var(--ubiot-primary);
    cursor: pointer;
    padding: 0;
    transition: background .15s ease, color .15s ease, transform .1s ease;
}
.install-btn:hover { background: var(--ubiot-primary); color: #fff; }
.install-btn:active { transform: scale(0.95); }
.install-btn.hidden { display: none; }

/* Modal iOS "Anadir a pantalla de inicio" */
.ios-install-help {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}
.ios-install-help.hidden { display: none; }
.ios-help-content {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    max-width: 360px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.ios-help-content h3 {
    margin: 0 0 16px;
    color: var(--ubiot-primary-dark);
    font-size: 20px;
    text-align: center;
}
.ios-help-content ol {
    padding-left: 22px;
    margin: 0 0 20px;
    color: var(--ubiot-text);
    line-height: 1.6;
}
.ios-help-content ol li { margin-bottom: 6px; }
.ios-help-content button { margin: 0; }

