: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;
}

/* ============ 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);
}
.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;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    position: relative;
}
.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.has-data::after {
    content: '';
    position: absolute;
    bottom: 3px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ubiot-primary);
}
.cal-day.selected.has-data::after {
    background: 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);
}

/* ============ 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;
    }
}
