:root {
    /* Light theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-card: #ffffff;
    --text-primary: #000000;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --accent-blue: #007aff;
    --accent-green: #34c759;
    --accent-red: #ff3b30;
    --dock-bg: rgba(255, 255, 255, 0.95);
    --dock-shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    /* Dark theme */
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-card: #1c1c1e;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --border-color: #38383a;
    --accent-blue: #0a84ff;
    --accent-green: #30d158;
    --accent-red: #ff453a;
    --dock-bg: rgba(28, 28, 30, 0.95);
    --dock-shadow: rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 80px; /* Space for dock */
}

.main-content {
    flex: 1;
    position: relative;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
    padding: 20px;
    padding-bottom: 100px;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

/* Dashboard */
.info-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
    padding-top: 20px;
}

.info-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.info-card:active {
    transform: scale(0.98);
}

.info-card-icon {
    width: 24px;
    height: 24px;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-top: 2px;
}

.info-card-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
}

.info-card-content {
    flex: 1;
    min-width: 0;
}

.info-card-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
    line-height: 1.2;
}

.info-card-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    word-break: break-word;
}

/* Chart Section */
.chart-section {
    margin-top: 24px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.chart-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-title-icon {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    color: var(--text-primary);
}

.period-selector {
    position: relative;
}

.period-selector-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    min-width: 90px;
    justify-content: space-between;
}

.period-selector-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-blue);
}

.period-selector-btn:active {
    transform: scale(0.95);
}

.period-selector.active .period-selector-btn {
    border-color: var(--accent-blue);
    background: var(--bg-secondary);
}

.period-arrow {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    transition: transform 0.2s ease;
}

.period-selector.active .period-arrow {
    transform: rotate(180deg);
}

.period-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--dock-shadow);
    min-width: 120px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 100;
    overflow: hidden;
}

.period-selector.active .period-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.period-option {
    display: block;
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    position: relative;
}

.period-option:hover {
    background: var(--bg-secondary);
}

.period-option:active {
    transform: scale(0.98);
}

.period-option.active {
    background: var(--bg-secondary);
    color: var(--accent-blue);
    font-weight: 600;
}

.period-option.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 16px;
    background: var(--accent-blue);
    border-radius: 0 2px 2px 0;
}

/* Custom Date Range Picker */
.custom-date-range-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: overlayFadeIn 0.2s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Ensure overlay is above dock */
    padding-bottom: max(20px, calc(80px + env(safe-area-inset-bottom)));
}

.custom-date-range-overlay.hidden {
    display: none;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.custom-date-range-modal {
    background: var(--bg-card);
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.date-range-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.date-range-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    flex: 1;
}

.date-range-close {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    margin-left: 12px;
    flex-shrink: 0;
}

.date-range-close:hover,
.date-range-close:active {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.date-range-close svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

/* Body */
.date-range-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.date-range-inputs {
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.date-input-group {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.date-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.date-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.date-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.1);
}

.date-input::-webkit-calendar-picker-indicator {
    opacity: 0.6;
    cursor: pointer;
    filter: invert(var(--calendar-icon-invert, 0));
}

[data-theme="dark"] .date-input::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

/* Footer */
.date-range-footer {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-card);
}

.date-range-btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    position: relative;
}

.date-range-btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.date-range-btn-secondary:hover {
    background: var(--border-color);
}

.date-range-btn-secondary:active {
    transform: scale(0.98);
    background: var(--bg-primary);
}

.date-range-btn-primary {
    background: var(--accent-blue);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(10, 132, 255, 0.3);
}

.date-range-btn-primary:hover {
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(10, 132, 255, 0.4);
}

.date-range-btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 1px 4px rgba(10, 132, 255, 0.3);
}

.chart-container {
    width: 100%;
    height: 300px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

#chartCanvas {
    width: 100%;
    height: 100%;
}

/* Profile */
.page-header {
    margin-bottom: 24px;
    padding-top: 20px;
}

.page-header h2 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-header-icon {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    color: var(--text-primary);
}

.profile-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.profile-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-color);
}

.profile-field:last-child {
    border-bottom: none;
}

.field-label {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

.field-value {
    font-size: 15px;
    color: var(--text-primary);
    font-weight: 600;
    text-align: right;
}

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

.history-item {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.history-item:active {
    transform: scale(0.98);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.history-client-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.history-time {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-left: 12px;
}

.history-email {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    word-break: break-word;
}

.history-date {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Settings */
.settings-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.settings-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
}

.settings-label {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 500;
}

.theme-toggle {
    display: flex;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.theme-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.theme-btn.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 1px 3px var(--dock-shadow);
}

.theme-btn:active {
    transform: scale(0.95);
}

/* Dock Navigation */
.dock {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--dock-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
    z-index: 1000;
    box-shadow: 0 -2px 10px var(--dock-shadow);
}

.dock-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 12px;
    min-width: 60px;
    color: var(--text-secondary);
    font-family: inherit;
}

.dock-item:active {
    transform: scale(0.9);
}

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

.dock-icon {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    transition: transform 0.2s ease;
}

.dock-item.active .dock-icon {
    transform: scale(1.1);
}

.dock-label {
    font-size: 11px;
    font-weight: 500;
    margin-top: 2px;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .page {
        padding: 16px;
    }

    .info-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .info-card {
        padding: 12px;
    }

    .info-card-icon {
        width: 20px;
        height: 20px;
    }

    .info-card-label {
        font-size: 11px;
    }

    .info-card-value {
        font-size: 18px;
    }

    .chart-container {
        height: 250px;
        padding: 16px;
    }

    .chart-title {
        font-size: 18px;
    }

    /* Mobile: Bottom Sheet Style */
    .custom-date-range-overlay {
        align-items: flex-end;
        padding: 0;
        padding-bottom: 0;
    }

    .custom-date-range-modal {
        max-width: 100%;
        width: 100%;
        border-radius: 24px 24px 0 0;
        max-height: 85vh;
        margin: 0;
        animation: bottomSheetSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes bottomSheetSlideUp {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .date-range-header {
        padding: 20px 20px 16px;
    }

    .date-range-title {
        font-size: 18px;
    }

    .date-range-body {
        padding: 20px;
    }

    .date-range-inputs {
        gap: 16px;
        padding: 16px;
    }

    .date-range-footer {
        padding: 16px 20px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .dock-item {
        padding: 6px 12px;
        min-width: 50px;
    }

    .dock-icon {
        width: 22px;
        height: 22px;
    }

    .dock-label {
        font-size: 10px;
    }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
    .dock {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

