:root {
    --bg-color: #0f111a;
    --card-bg: rgba(255, 255, 255, 0.05);
    --accent-color: #7c4dff;
    --accent-gradient: linear-gradient(135deg, #7c4dff 0%, #448aff 100%);
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --success: #00e676;
    --error: #ff5252;
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: calc(var(--vh, 1vh) * 100);
    height: 100dvh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 450px;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 20px;
}

header {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.user-badge {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 50px;
    border: 1px solid var(--glass-border);
    margin-bottom: 15px;
}

.user-initials {
    width: 32px;
    height: 32px;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    margin-right: 10px;
    font-size: 0.8rem;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 300;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.accent {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Main scrollable area */
#mainContent {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

/* Tabs */
.tab-content {
    display: none;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Glass Card */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Punch Card */
.punch-card {
    text-align: center;
    margin-bottom: 20px;
}

.clock-display {
    font-size: 3.5rem;
    font-weight: 600;
    margin-bottom: 5px;
    font-variant-numeric: tabular-nums;
}

.date-display {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 30px;
    text-transform: capitalize;
}

.punch-btn {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0 auto 30px;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(124, 77, 255, 0.3);
    transition: all 0.3s ease;
}

.punch-btn:active {
    transform: scale(0.95);
    box-shadow: 0 5px 10px rgba(124, 77, 255, 0.2);
}

.punch-btn:disabled {
    background: #333;
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-icon {
    font-size: 2rem;
    margin-bottom: 5px;
}

.status-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background: #555;
    border-radius: 50%;
}

.pulse-dot.success {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.pulse-dot.error {
    background: var(--error);
    box-shadow: 0 0 10px var(--error);
}

/* Info Cards */
.next-action-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.next-action-card .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.next-action-card .value {
    font-weight: 700;
    font-size: 1.1rem;
}

/* History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hi-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hi-type { font-weight: 600; font-size: 0.9rem; }
.hi-date { font-size: 0.75rem; color: var(--text-secondary); }
.hi-time { font-weight: 700; font-size: 1.1rem; color: var(--accent-color); }

/* Setup */
.setup-card {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"] {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px;
    color: white;
    outline: none;
    transition: border 0.3s;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus {
    border-color: var(--accent-color);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 0.85rem;
    cursor: pointer;
}

.location-setup {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 12px;
    margin-top: 8px;
}

.device-name {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Nav */
.bottom-nav {
    position: absolute;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    right: 20px;
    height: 70px;
    background: rgba(25, 27, 38, 0.8);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 20px;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.3s;
    flex: 1;
}

.nav-item.active {
    color: var(--accent-color);
}

.nav-icon {
    font-size: 1.2rem;
    font-weight: 700;
}

.nav-label {
    font-size: 0.7rem;
    font-weight: 400;
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.text-center { text-align: center; }
.mt-15 { margin-top: 15px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.mt-30 { margin-top: 30px; }
.w-100 { width: 100%; }
.flex-1 { flex: 1; }
.row { display: flex; gap: 15px; }

#historyTotalBox {
    padding: 15px;
    border: 1px solid rgba(0, 230, 118, 0.2);
}

select {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px;
    color: white;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
    font-style: italic;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    width: 90%;
    max-width: 320px;
    padding: 30px;
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 10px;
    color: var(--accent-color);
}

.modal-content p {
    font-size: 0.9rem;
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.modal-content input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 12px;
    color: white;
    text-align: center;
    font-size: 1.2rem;
    letter-spacing: 5px;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions button {
    flex: 1;
}

/* ── Toast Notification ── */
#toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--primary-color, #00e676);
    color: #000;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 12px 24px;
    border-radius: 50px;
    box-shadow: 0 4px 20px rgba(0, 230, 118, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
    z-index: 9999;
}

#toast.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Gestione Timbrature ── */
.manage-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.manage-month {
    margin-bottom: 8px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
}

.manage-month-header {
    display: flex;
    align-items: center;
    padding: 11px 12px;
    cursor: pointer;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    user-select: none;
    -webkit-user-select: none;
}

.manage-month-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.88rem;
}

.manage-badge {
    background: var(--accent-gradient);
    color: white;
    font-size: 0.7rem;
    padding: 2px 9px;
    border-radius: 20px;
    font-weight: 700;
    min-width: 26px;
    text-align: center;
}

.manage-arrow {
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    display: inline-block;
}
.manage-arrow.open { transform: rotate(180deg); }

.manage-month-body {
    padding: 6px 10px 10px 10px;
}

.manage-day {
    margin-top: 8px;
}

.manage-day-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    cursor: default;
}

.manage-day-name {
    flex: 1;
    font-size: 0.83rem;
    color: var(--text-secondary);
}

.manage-day-body {
    padding-left: 10px;
    margin-top: 3px;
}

.manage-punch-item {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.manage-punch-item:last-child { border-bottom: none; }

.manage-punch-type {
    font-size: 0.8rem;
    font-weight: 700;
    flex: 1;
    letter-spacing: 0.3px;
}

.manage-punch-time {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.manage-cb {
    width: 17px;
    height: 17px;
    accent-color: var(--accent-color);
    cursor: pointer;
    flex-shrink: 0;
}

.btn-danger {
    background: linear-gradient(135deg, #ff5252 0%, #c62828 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 14px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s;
    letter-spacing: 0.3px;
}
.btn-danger:active { opacity: 0.75; }

/* ── QR Toggle Switch ── */
.qr-toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.12);
    border-radius: 28px;
    cursor: pointer;
    transition: background 0.3s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent-gradient);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* ── QR Scan Button (punch screen) ── */
.btn-qr-scan {
    background: linear-gradient(135deg, #ff9800 0%, #f44336 100%);
    color: white;
    border: none;
    border-radius: 60px;
    padding: 16px 40px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px auto 0 auto;
    box-shadow: 0 6px 24px rgba(255,152,0,0.35);
    transition: opacity 0.2s, transform 0.1s;
    letter-spacing: 0.4px;
}
.btn-qr-scan:active { transform: scale(0.96); opacity: 0.85; }

/* ── QR Scanner Modal ── */
.qr-scanner-content {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    z-index: 200;
}
.qr-scanner-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    background: rgba(0,0,0,0.7);
    z-index: 10;
}
.qr-scanner-title {
    font-size: 1rem;
    font-weight: 600;
    color: white;
}
.qr-close-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qr-viewfinder-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}
#qrVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.qr-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    width: 220px;
    height: 220px;
}
.qr-corner {
    position: absolute;
    width: 36px;
    height: 36px;
    border-color: #ff9800;
    border-style: solid;
}
.qr-corner.tl { top:0; left:0;  border-width: 4px 0 0 4px; border-radius: 6px 0 0 0; }
.qr-corner.tr { top:0; right:0; border-width: 4px 4px 0 0; border-radius: 0 6px 0 0; }
.qr-corner.bl { bottom:0; left:0;  border-width: 0 0 4px 4px; border-radius: 0 0 0 6px; }
.qr-corner.br { bottom:0; right:0; border-width: 0 4px 4px 0; border-radius: 0 0 6px 0; }

.qr-scan-line {
    position: absolute;
    top: 10%;
    left: 5%;
    width: 90%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #ff9800, transparent);
    animation: scanMove 1.8s ease-in-out infinite;
}
@keyframes scanMove {
    0%   { top: 10%; opacity: 1; }
    50%  { top: 85%; opacity: 1; }
    100% { top: 10%; opacity: 1; }
}

.qr-scan-status {
    text-align: center;
    padding: 18px 20px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    color: rgba(255,255,255,0.8);
    font-size: 0.9rem;
    background: rgba(0,0,0,0.8);
}
