/* iOS-specific improvements */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Prevent double-tap zoom on all interactive elements */
button, .btn {
    touch-action: manipulation;
}

body {
    padding-bottom: 80px;
    background-color: #f8f9fa;
}

/* Safe area insets for iPhone X and newer */
@supports (padding: max(0px)) {
    body {
        padding-bottom: max(80px, env(safe-area-inset-bottom));
    }
    .navbar-top {
        padding-top: env(safe-area-inset-top);
    }
    .navbar-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Navigation bars */
.navbar-top {
    position: fixed;
    top: 0;
    width: 100%;
    background-color: white;
    border-bottom: 1px solid #dee2e6;
    padding: 10px 0;
    z-index: 1030;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar-bottom {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: white;
    border-top: 1px solid #dee2e6;
    padding: 12px 0;
    z-index: 1030;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.1);
}

/* Main content area for view page */
body.view-page {
    padding-top: 60px;
    padding-bottom: 100px;
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

@supports (padding: max(0px)) {
    body.view-page {
        padding-top: max(60px, env(safe-area-inset-top));
        padding-bottom: max(100px, env(safe-area-inset-bottom));
    }
}

.main-content {
    position: fixed;
    top: 60px;
    bottom: 100px;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
}

@supports (padding: max(0px)) {
    .main-content {
        top: max(60px, env(safe-area-inset-top));
        bottom: max(100px, env(safe-area-inset-bottom));
    }
}

/* Hours display */
.hours-display {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    text-align: center;
    width: 100%;
    max-width: 90vw;
    min-height: 250px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.date-text {
    font-size: 1.2rem;
    color: #6c757d;
    margin-bottom: 15px;
}

.hours-number {
    font-size: 6rem;
    font-weight: 300;
    color: #212529;
    line-height: 1;
    margin: 15px 0;
    transition: transform 0.2s ease;
}

.hours-label {
    font-size: 1.1rem;
    color: #6c757d;
    margin-top: 15px;
}

/* Buttons */
.btn-modern {
    border-radius: 50px;
    font-weight: 500;
    transition: all 0.3s ease;
    padding: 8px 20px;
    font-size: 0.85rem;
    touch-action: manipulation;
}

.btn-modern:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2) !important;
}

.btn-modern svg {
    width: 18px;
    height: 18px;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 44px;
    border-radius: 8px;
    padding: 6px 12px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    touch-action: manipulation;
}

/* Only scale on devices with a real pointer: on iOS a tap leaves :hover stuck */
@media (hover: hover) {
    .nav-btn:hover {
        transform: scale(1.05);
    }
}

.nav-btn:active {
    transform: scale(0.96);
}

.nav-btn svg {
    flex-shrink: 0;
}

.nav-btn svg {
    width: 16px;
    height: 16px;
}

/* Top bar of secondary pages: back link, centred title, menu */
.page-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
}

.back-link {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    min-height: 44px;
    margin-left: -6px;
    padding: 0 6px;
    border-radius: 8px;
    color: #0d6efd;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    touch-action: manipulation;
}

.back-link:hover {
    color: #0a58ca;
}

.back-link:active {
    opacity: 0.5;
}

.page-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-bar-end {
    justify-self: end;
}

/* Main menu (icon-only toggle) */
.menu-btn {
    min-width: 44px;
    padding: 6px 10px;
}

.menu-btn svg {
    width: 20px;
    height: 20px;
}

.main-menu {
    min-width: 230px;
    padding: 6px 0;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.main-menu .dropdown-header {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.main-menu .dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
}

.main-menu .dropdown-item svg {
    flex-shrink: 0;
    opacity: 0.75;
}

.adjust-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 500;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
    touch-action: manipulation;
}

.adjust-btn:hover {
    transform: scale(1.1);
}

.adjust-btn.primary {
    width: 80px;
    height: 80px;
    font-size: 2rem;
}

/* Tables */
.table-container {
    margin-top: 15px;
    background: white;
    border-radius: 10px;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.table {
    margin-bottom: 0;
}

h1 {
    font-size: 1.25rem;
    margin: 15px 0;
    font-weight: 600;
}

/* Links */
.month-link, .date-link {
    text-decoration: none;
    color: #0d6efd;
    font-weight: 500;
}

.month-link:hover, .date-link:hover {
    text-decoration: underline;
}

/* Special styles */
.weekend-day {
    color: #dc3545 !important;
    font-weight: 600;
}

.total-hours {
    font-size: 1rem;
    font-weight: 600;
    color: #198754;
}

.btn-group-modern {
    gap: 10px;
}

/* Today indicator icon */
.today-indicator {
    color: #0d6efd;
    vertical-align: middle;
}

/* Dark mode support for iOS */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #000000;
        color: #ffffff;
    }
    
    .navbar-top, .navbar-bottom {
        background-color: #1c1c1e;
        border-color: #38383a;
    }
    
    .hours-display {
        background-color: #1c1c1e;
        color: #ffffff;
    }
    
    .table {
        color: #ffffff;
    }
    
    .table td, .table th {
        color: #ffffff;
    }
    
    .table-striped > tbody > tr:nth-of-type(odd) {
        background-color: rgba(255, 255, 255, 0.05);
    }
    
    .table-striped > tbody > tr:nth-of-type(odd) > td {
        color: #ffffff;
    }
    
    .table-striped > tbody > tr:nth-of-type(even) {
        background-color: rgba(255, 255, 255, 0.02);
    }
    
    .table-striped > tbody > tr:nth-of-type(even) > td {
        color: #ffffff;
    }
    
    .table-hover tbody tr:hover {
        background-color: rgba(255, 255, 255, 0.075);
    }
    
    .table-dark {
        background-color: #2c2c2e;
        color: #ffffff;
    }
    
    .table-container {
        background-color: #1c1c1e;
    }
    
    .btn-outline-secondary {
        border-color: #48484a;
        color: #ffffff;
    }
    
    .btn-outline-secondary:hover {
        background-color: #48484a;
        border-color: #48484a;
        color: #ffffff;
    }
    
    .dropdown-menu {
        background-color: #2c2c2e;
        border-color: #38383a;
    }
    
    .dropdown-item {
        color: #ffffff;
    }
    
    .dropdown-item:hover, .dropdown-item:focus {
        background-color: #3a3a3c;
        color: #ffffff;
    }
    
    .dropdown-divider {
        border-color: #38383a;
    }

    .dropdown-header {
        color: #a1a1a6;
    }

    .back-link, .back-link:hover {
        color: #0a84ff;
    }
    
    .today-indicator {
        color: #007aff;
    }
    
    .date-link, .month-link {
        color: #007aff;
    }
    
    .table-light {
        background-color: #2c2c2e;
        color: #ffffff;
    }
    
    .weekend-day {
        color: #ff453a !important;
    }
    
    .total-hours {
        color: #30d158;
    }
}

/* Auth pages (login / register / admin) */
.auth-card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    max-width: 420px;
    margin: 0 auto;
}

.auth-card h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.auth-muted {
    color: #6c757d;
    font-size: 0.9rem;
}

.auth-btn {
    width: 100%;
    border-radius: 12px;
    padding: 12px 16px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
    touch-action: manipulation;
}

.auth-status {
    margin-top: 16px;
    min-height: 1.4em;
    font-size: 0.9rem;
    color: #6c757d;
}

.auth-status.auth-error {
    color: #dc3545;
}

.auth-tabs {
    margin-bottom: 16px;
    padding: 4px;
    border-radius: 10px;
    background-color: #e9ecef;
}

.auth-tabs .nav-link {
    border-radius: 8px;
    min-height: 40px;
    font-weight: 500;
    color: #495057;
}

.auth-tabs .nav-link.active {
    background-color: white;
    color: #0d6efd;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.auth-divider {
    margin: 24px 0 16px 0;
    border-color: rgba(0,0,0,0.1);
}

.auth-card .form-control {
    -webkit-user-select: text;
    user-select: text;
    border-radius: 10px;
}

@media (prefers-color-scheme: dark) {
    .auth-card {
        background-color: #1c1c1e;
        color: #ffffff;
    }
    .auth-card .form-control {
        background-color: #2c2c2e;
        color: #ffffff;
        border-color: #38383a;
    }
    .auth-muted {
        color: #a1a1a6;
    }
    .auth-divider {
        border-color: rgba(255,255,255,0.1);
    }

    .auth-tabs {
        background-color: #2c2c2e;
    }

    .auth-tabs .nav-link {
        color: #c7c7cc;
    }

    .auth-tabs .nav-link.active {
        background-color: #48484a;
        color: #ffffff;
    }
}

/* Passkey admin page */
.passkey-intro {
    font-size: 0.9rem;
    color: #6c757d;
    margin-bottom: 16px;
}

.passkey-list {
    list-style: none;
    margin: 0 0 20px 0;
    padding: 0;
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    overflow: hidden;
}

.passkey-item, .passkey-empty {
    display: flex;
    gap: 14px;
    padding: 16px;
}

.passkey-item + .passkey-item {
    border-top: 1px solid #e9ecef;
}

.passkey-item-pending {
    background-color: #fffbeb;
}

.passkey-empty {
    align-items: center;
    color: #6c757d;
}

.passkey-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background-color: #e7f1ff;
    color: #0d6efd;
}

.passkey-body {
    flex: 1;
    min-width: 0;
}

.passkey-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.passkey-label {
    font-weight: 600;
    font-size: 1rem;
    color: #212529;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.passkey-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
    font-size: 0.8rem;
    color: #6c757d;
}

.passkey-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.passkey-actions form {
    margin: 0;
}

.passkey-current-pill {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 50px;
    background-color: #cfe2ff;
    color: #084298;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.passkey-badge {
    flex-shrink: 0;
    display: inline-block;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background-color: #e9ecef;
    color: #495057;
}

.passkey-badge-approved {
    background-color: #d1e7dd;
    color: #0a3622;
}

.passkey-badge-pending {
    background-color: #fff3cd;
    color: #664d03;
}

.passkey-add {
    text-decoration: none;
}

@media (prefers-color-scheme: dark) {
    .passkey-label {
        color: #ffffff;
    }
    .passkey-meta {
        color: #a1a1a6;
    }
    .passkey-current-pill {
        background-color: rgba(0, 122, 255, 0.2);
        color: #7eb6ff;
    }
    .passkey-badge {
        background-color: rgba(255, 255, 255, 0.08);
        color: #d1d1d6;
    }
    .passkey-badge-approved {
        background-color: rgba(48, 209, 88, 0.18);
        color: #5cd97a;
    }
    .passkey-badge-pending {
        background-color: rgba(255, 204, 0, 0.18);
        color: #ffd770;
    }
    .passkey-intro, .passkey-empty {
        color: #a1a1a6;
    }
    .passkey-list {
        background-color: #1c1c1e;
    }
    .passkey-item + .passkey-item {
        border-top-color: #38383a;
    }
    .passkey-item-pending {
        background-color: rgba(255, 204, 0, 0.06);
    }
    .passkey-icon {
        background-color: rgba(0, 122, 255, 0.2);
        color: #7eb6ff;
    }
}

/* Day navigation: one row with labels on iPhone 17 / Air / Pro Max (402-440px) */
.day-nav {
    gap: 12px;
    flex-wrap: nowrap;
    min-width: 0;
    margin-right: 12px; /* keep the menu button clear of Tomorrow */
}

@media (max-width: 440px) {
    .day-nav {
        gap: 8px;
    }

    .day-nav .btn-primary svg {
        display: none;
    }

    .navbar-top .nav-btn {
        padding: 6px 7px;
        font-size: 0.8rem;
    }
}

/* iPhone 13 mini specific adjustments */
@media (max-width: 390px) {
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .nav-btn, .navbar-top .nav-btn {
        padding: 5px 10px;
        font-size: 0.75rem;
    }
    
    .nav-btn span, .btn-modern span {
        display: none;
    }
    
    .hours-number {
        font-size: 5rem;
    }
    
    .date-text {
        font-size: 1.1rem;
    }
    
    .hours-display {
        padding: 25px 20px;
        min-height: 220px;
    }
    
    .adjust-btn {
        width: 55px;
        height: 55px;
        font-size: 1.3rem;
    }
    
    .adjust-btn.primary {
        width: 70px;
        height: 70px;
        font-size: 1.8rem;
    }
    
    .table {
        font-size: 0.85rem;
    }
    
    .table th, .table td {
        padding: 0.5rem;
    }
    
    h1 {
        font-size: 1.1rem;
    }
    
    .btn-modern {
        padding: 6px 15px;
        font-size: 0.75rem;
    }
    
    .navbar-bottom {
        padding: 10px 0;
    }
}