/* ========================================
   Vietnamese Lunar Calendar - Design System
   Modern, Premium UI with Glassmorphism
   OPTIMIZED: Better fonts, colors & mobile
   ======================================== */

/* ===== CSS Variables - Design Tokens ===== */
:root {
    /* Dark Theme (Default) - HIGH CONTRAST */
    --bg-primary: #0a0a1a;
    --bg-secondary: #141428;
    --bg-tertiary: #1e1e3a;
    --bg-card: rgba(20, 20, 40, 0.95);
    --bg-glass: rgba(255, 255, 255, 0.08);

    /* Text - HIGHER CONTRAST */
    --text-primary: #ffffff;
    --text-secondary: #c8c8d8;
    --text-muted: #9090a8;

    /* Accent - VIVID COLORS */
    --accent-primary: #ff4d6d;
    --accent-secondary: #ffe066;
    --accent-tertiary: #5ce1e6;
    --accent-gradient: linear-gradient(135deg, #ff4d6d 0%, #ff8a80 100%);

    --border-color: rgba(255, 255, 255, 0.15);
    --shadow-color: rgba(0, 0, 0, 0.4);

    --success: #5eff7e;
    --warning: #ffc942;
    --error: #ff6b6b;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Typography - SYSTEM FONTS FIRST */
    --font-display: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-base: 16px;
    --font-size-sm: 14px;
    --font-size-xs: 12px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-2xl: 32px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
}

/* Light Theme - HIGH CONTRAST */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e4e6eb;
    --bg-card: rgba(255, 255, 255, 0.98);
    --bg-glass: rgba(0, 0, 0, 0.04);

    --text-primary: #1a1a1a;
    --text-secondary: #3a3a4a;
    --text-muted: #666680;

    --accent-primary: #d6336c;
    --accent-secondary: #e6a700;
    --accent-tertiary: #0ca678;

    --border-color: rgba(0, 0, 0, 0.12);
    --shadow-color: rgba(0, 0, 0, 0.15);
}

/* ===== Base Styles ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--font-size-base);
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* iOS Safari fixes */
    -webkit-tap-highlight-color: transparent;
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    min-height: 100dvh;
    /* Dynamic viewport height for mobile */
    overflow-x: hidden;
    font-weight: 400;
    letter-spacing: 0.01em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(233, 69, 96, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(78, 205, 196, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* ===== Header ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-md) var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.logo-icon {
    font-size: 1.75rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.header-date .solar-date {
    font-weight: 500;
    color: var(--text-primary);
}

.header-date .lunar-date {
    font-size: 0.875rem;
    color: var(--accent-secondary);
}

.header-actions {
    display: flex;
    gap: var(--space-sm);
}

.btn-icon {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

/* ===== Main Layout ===== */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-lg);
    display: grid;
    grid-template-columns: auto 1fr 350px;
    gap: var(--space-lg);
    min-height: calc(100vh - 80px);
}

/* ===== Sidebar ===== */
.sidebar {
    width: 80px;
}

.sidebar-nav {
    position: sticky;
    top: 100px;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.sidebar-btn {
    width: 64px;
    height: 64px;
    border: none;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    transition: var(--transition-base);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 1px solid var(--border-color);
    /* Mobile touch fix */
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(255, 77, 109, 0.3);
    user-select: none;
    -webkit-user-select: none;
}

.sidebar-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--shadow-color);
}

.btn-icon-inner {
    font-size: 1.5rem;
}

.btn-label {
    font-size: 0.625rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.mobile-only {
    display: none;
}

/* ===== Calendar Section ===== */
.calendar-section {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    border: 1px solid var(--border-color);
}

.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.month-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
}

.btn-nav {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-nav:hover {
    background: var(--accent-primary);
    color: white;
}

/* Calendar Grid */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--space-xs);
}

.calendar-header-cell {
    text-align: center;
    padding: var(--space-sm);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.calendar-day {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
    background: var(--bg-glass);
    border: 1px solid transparent;
}

.calendar-day:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

.calendar-day .solar-day {
    font-size: var(--font-size-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.calendar-day .lunar-day {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-weight: 500;
}

/* Calendar Day States */
.calendar-day.other-month {
    opacity: 0.3;
}

.calendar-day.today {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.calendar-day.today .lunar-day {
    color: rgba(255, 255, 255, 0.8);
}

.calendar-day.selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.3);
}

.calendar-day.holiday {
    background: rgba(255, 217, 61, 0.15);
}

.calendar-day.holiday .solar-day {
    color: var(--accent-secondary);
}

.calendar-day.day-off .solar-day {
    color: var(--accent-primary);
}

.calendar-day.special-lunar .lunar-day {
    color: var(--accent-tertiary);
    font-weight: 600;
}

.calendar-day.sunday .solar-day {
    color: var(--accent-primary);
}

/* Calendar Legend */
.calendar-legend {
    display: flex;
    justify-content: center;
    gap: var(--space-lg);
    margin-top: var(--space-lg);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
}

.legend-dot.today {
    background: var(--accent-gradient);
}

.legend-dot.holiday {
    background: var(--accent-secondary);
}

.legend-dot.special-lunar {
    background: var(--accent-tertiary);
}

/* ===== Details Panel ===== */
.details-panel {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    border: 1px solid var(--border-color);
    overflow-y: auto;
    max-height: calc(100vh - 120px);
    position: sticky;
    top: 100px;
}

.details-header {
    text-align: center;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.details-header h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    color: var(--accent-primary);
    margin-bottom: var(--space-sm);
}

.date-display .solar-big {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-display);
}

.date-display .lunar-big {
    font-size: 0.875rem;
    color: var(--accent-secondary);
}

.details-section {
    margin-bottom: var(--space-lg);
}

.details-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: var(--space-md);
    color: var(--text-secondary);
}

/* Can Chi Grid */
.canchi-grid {
    display: grid;
    gap: var(--space-sm);
}

.canchi-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-glass);
    border-radius: var(--radius-md);
}

.canchi-item .label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.canchi-item .value {
    font-weight: 600;
    color: var(--accent-secondary);
}

.canchi-item .zodiac {
    font-size: 0.75rem;
    color: var(--accent-tertiary);
}

/* Holiday List */
.holiday-list {
    list-style: none;
}

.holiday-list li {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xs);
    font-size: 0.875rem;
}

.holiday-list li.day-off {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent-primary);
}

/* Gio Grid */
.gio-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.gio-item {
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    text-align: center;
}

.gio-item.hoang-dao {
    background: rgba(78, 205, 196, 0.15);
}

.gio-item.hac-dao {
    background: rgba(248, 113, 113, 0.1);
}

.gio-name {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
}

.gio-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Action Buttons */
.details-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-lg);
}

.btn-action {
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.btn-action:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-base);
    /* iOS Safari fixes */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overscroll-behavior: contain;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    max-height: 85dvh;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateY(20px) scale(0.95);
    transition: var(--transition-base);
    border: 1px solid var(--border-color);
    /* iOS Safari scroll fix */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
}

.btn-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition-fast);
    line-height: 1;
}

.btn-close:hover {
    background: var(--accent-primary);
    color: white;
}

.modal-body {
    padding: var(--space-lg);
}

/* Converter Styles */
.converter-section {
    margin-bottom: var(--space-lg);
}

.converter-section h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.input-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    align-items: flex-end;
}

.input-group {
    flex: 1;
    min-width: 80px;
}

.input-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.input-group input[type="number"] {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition-fast);
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.2);
}

.checkbox-group {
    display: flex;
    align-items: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.btn-convert {
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent-gradient);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-base);
    white-space: nowrap;
}

.btn-convert:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.divider {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin: var(--space-lg) 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.converter-result {
    margin-top: var(--space-lg);
}

.result-card {
    background: var(--bg-glass);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    text-align: center;
    border: 1px solid var(--border-color);
}

.result-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.result-value {
    font-size: 2rem;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--accent-secondary);
}

.result-year {
    font-size: 0.875rem;
    color: var(--accent-tertiary);
    margin-top: var(--space-xs);
}

.result-error {
    color: var(--error);
    text-align: center;
    padding: var(--space-md);
}

/* Reminders List */
.reminders-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.reminder-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.reminder-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reminder-title {
    font-weight: 500;
}

.reminder-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.btn-delete {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-delete:hover {
    background: rgba(248, 113, 113, 0.2);
}

.empty-message {
    text-align: center;
    color: var(--text-muted);
    padding: var(--space-xl);
}

/* Age Result */
.age-result {
    margin-top: var(--space-lg);
}

.age-card {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.age-item {
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    text-align: center;
    border: 1px solid var(--border-color);
}

.age-item .label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.age-item .value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-secondary);
}

/* ===== Month List View (Mobile) - iOS FIXED ===== */
.mobile-only {
    display: none;
}

.month-view-content {
    width: 100%;
    max-width: 600px;
    height: 85vh;
    height: 85dvh;
    /* Dynamic viewport for iOS */
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    position: relative;
    /* iOS fix: prevent flex items from growing beyond container */
    min-height: 0;
}

.month-view-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
    /* iOS fix: prevent header from shrinking */
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
}

.month-view-header h2 {
    flex: 1;
    text-align: center;
    font-size: 1.1rem;
    margin: 0;
}

.month-view-header .btn-close {
    margin-left: auto;
    position: relative;
}

.month-view-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-md);
    /* iOS Safari scroll fix */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    /* iOS fix: allow content to scroll */
    min-height: 0;
}

.month-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    /* iOS fix: ensure content renders */
    transform: translateZ(0);
}

.month-list-item {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition-fast);
}

.month-list-item:hover {
    background: var(--bg-tertiary);
    transform: translateX(4px);
}

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

.month-list-item.today {
    background: var(--accent-gradient);
    border-color: transparent;
}

.month-list-item.today .list-weekday,
.month-list-item.today .list-lunar-day,
.month-list-item.today .list-canchi {
    color: rgba(255, 255, 255, 0.85);
}

.month-list-item.sunday .list-solar-day,
.month-list-item.sunday .list-weekday {
    color: var(--accent-primary);
}

.month-list-item.today.sunday .list-solar-day,
.month-list-item.today.sunday .list-weekday {
    color: #fff;
}

.month-list-item.holiday {
    border-left: 3px solid var(--accent-secondary);
}

.month-list-item.special-lunar .list-lunar-day {
    color: var(--accent-tertiary);
    font-weight: 600;
}

.list-date {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.list-solar-day {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font-display);
    line-height: 1;
}

.list-weekday {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.list-lunar {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.list-lunar-day {
    font-size: 0.9rem;
    font-weight: 500;
}

.list-canchi {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.list-holiday {
    font-size: 0.7rem;
    color: var(--accent-secondary);
    background: rgba(255, 224, 102, 0.15);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

/* ===== Responsive - ENHANCED MOBILE ===== */
@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: auto 1fr;
    }

    .details-panel {
        position: fixed;
        top: 0;
        right: -400px;
        width: 350px;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        border-radius: var(--radius-xl) 0 0 var(--radius-xl);
        z-index: 200;
        transition: var(--transition-base);
    }

    .details-panel.active {
        right: 0;
    }
}

@media (max-width: 768px) {
    :root {
        --font-size-base: 15px;
        --font-size-lg: 17px;
        --space-lg: 20px;
    }

    /* Show mobile-only elements */
    .mobile-only {
        display: flex;
    }

    .main-container {
        grid-template-columns: 1fr;
        padding: var(--space-md);
        padding-bottom: 90px;
        gap: var(--space-md);
    }

    .sidebar {
        width: 100%;
        order: 2;
    }

    .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-card);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        padding: var(--space-sm) var(--space-md);
        padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-color);
        z-index: 100;
        gap: var(--space-xs);
    }

    .sidebar-btn {
        width: 60px;
        height: 54px;
        flex: 1;
        max-width: 80px;
    }

    .btn-icon-inner {
        font-size: 1.25rem;
    }

    .btn-label {
        font-size: 0.65rem;
    }

    .calendar-section {
        margin-bottom: 0;
        padding: var(--space-md);
        order: 1;
    }

    .calendar-grid {
        gap: 3px;
    }

    .calendar-day {
        min-height: 44px;
        padding: var(--space-xs);
        border-radius: var(--radius-sm);
    }

    .calendar-day .solar-day {
        font-size: var(--font-size-base);
        font-weight: 600;
    }

    .calendar-day .lunar-day {
        display: block;
        font-size: 10px;
        opacity: 0.8;
    }

    .calendar-header {
        margin-bottom: var(--space-md);
    }

    .month-title {
        font-size: 1.25rem;
    }

    .btn-nav {
        width: 44px;
        height: 44px;
    }

    .header-date {
        display: none;
    }

    .header-content {
        padding: var(--space-sm) var(--space-md);
    }

    .logo-text {
        font-size: 1.1rem;
    }

    .calendar-legend {
        gap: var(--space-md);
        flex-wrap: wrap;
    }

    .details-panel {
        position: fixed;
        width: 100%;
        height: auto;
        max-height: 70vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        right: 0;
        left: 0;
        top: auto;
        bottom: -100%;
        padding: var(--space-md);
        padding-bottom: calc(var(--space-lg) + 70px + env(safe-area-inset-bottom));
        transition: bottom 0.3s ease;
    }

    .details-panel.active {
        bottom: 0;
    }

    .details-header h2 {
        font-size: 1.1rem;
    }

    .date-display .solar-big {
        font-size: 1.75rem;
    }

    .gio-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-xs);
    }

    .gio-item {
        padding: var(--space-xs);
    }

    .gio-name {
        font-size: 0.8rem;
    }

    .gio-time {
        font-size: 0.65rem;
    }

    .details-actions {
        flex-direction: row;
        flex-wrap: wrap;
        gap: var(--space-xs);
    }

    .btn-action {
        flex: 1;
        min-width: calc(50% - var(--space-xs));
        padding: var(--space-sm);
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    :root {
        --font-size-base: 14px;
        --font-size-lg: 16px;
    }

    .calendar-day {
        padding: 2px;
        min-height: 40px;
    }

    .calendar-day .solar-day {
        font-size: var(--font-size-sm);
    }

    .calendar-day .lunar-day {
        font-size: 9px;
    }

    .calendar-header-cell {
        font-size: 0.65rem;
        padding: var(--space-xs);
    }

    .month-title {
        font-size: 1.1rem;
    }

    .btn-nav {
        width: 36px;
        height: 36px;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 90vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .modal-header {
        padding: var(--space-md);
    }

    .modal-body {
        padding: var(--space-md);
    }

    .input-row {
        flex-direction: column;
        gap: var(--space-md);
    }

    .input-group {
        width: 100%;
    }

    .input-group input[type="number"] {
        padding: var(--space-md);
        font-size: var(--font-size-base);
    }

    .btn-convert {
        width: 100%;
        padding: var(--space-md);
        font-size: var(--font-size-base);
    }

    .age-card {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-sm);
    }

    .sidebar-btn {
        width: 52px;
        height: 50px;
    }

    .canchi-grid {
        gap: var(--space-xs);
    }

    .canchi-item {
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.85rem;
    }
}

/* ===== iPhone 7 and smaller (375px and below) ===== */
@media (max-width: 375px) {
    :root {
        --font-size-base: 15px;
        --font-size-sm: 13px;
        --font-size-lg: 17px;
    }

    /* Bottom navigation - compact for 5 buttons */
    .sidebar-nav {
        padding: 6px 8px;
        padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    .sidebar-btn {
        width: 56px;
        min-width: 56px;
        height: 48px;
        padding: 4px 2px;
        flex: 0 0 auto;
    }

    .btn-icon-inner {
        font-size: 1.2rem;
    }

    .btn-label {
        font-size: 9px;
        line-height: 1.1;
        margin-top: 2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 52px;
    }

    /* Main container */
    .main-container {
        padding: 8px;
        padding-bottom: 70px;
    }

    /* Header */
    .header-content {
        padding: 8px 12px;
    }

    .logo-text {
        font-size: 1rem;
    }

    /* Calendar */
    .calendar-section {
        padding: 8px;
    }

    .calendar-grid {
        gap: 2px;
    }

    .calendar-day {
        min-height: 38px;
        padding: 2px;
    }

    .calendar-day .solar-day {
        font-size: 14px;
        font-weight: 600;
    }

    .calendar-day .lunar-day {
        font-size: 8px;
    }

    .calendar-header-cell {
        font-size: 10px;
        padding: 4px 2px;
    }

    .month-title {
        font-size: 1rem;
    }

    .btn-nav {
        width: 32px;
        height: 32px;
    }

    /* Details panel */
    .details-panel {
        max-height: 65vh;
        padding: 12px;
    }

    .details-header h2 {
        font-size: 1rem;
    }

    .date-display .solar-big {
        font-size: 1.5rem;
    }

    .date-display .lunar-big {
        font-size: 0.85rem;
    }

    /* Can Chi grid */
    .canchi-grid {
        gap: 4px;
    }

    .canchi-item {
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    .canchi-item .label {
        font-size: 10px;
    }

    /* Gio grid */
    .gio-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }

    .gio-item {
        padding: 4px;
    }

    .gio-name {
        font-size: 0.75rem;
    }

    .gio-time {
        font-size: 10px;
    }

    /* Actions */
    .details-actions {
        gap: 4px;
    }

    .btn-action {
        padding: 8px;
        font-size: 0.75rem;
        flex: 1 1 calc(50% - 4px);
    }

    /* Modal */
    .modal-content {
        max-height: 85vh;
    }

    .modal-header h2 {
        font-size: 1rem;
    }

    /* Month list view */
    .month-view-content {
        height: 80vh;
    }

    .month-list-item {
        grid-template-columns: 60px 1fr auto;
        padding: 10px;
        gap: 8px;
    }

    .list-solar-day {
        font-size: 1.25rem;
    }

    .list-weekday {
        font-size: 10px;
    }

    .list-lunar-day {
        font-size: 0.8rem;
    }

    .list-canchi {
        font-size: 10px;
    }

    .list-holiday {
        font-size: 9px;
        padding: 2px 6px;
        max-width: 80px;
    }

    /* Calendar legend */
    .calendar-legend {
        gap: 8px;
        font-size: 10px;
    }

    .legend-dot {
        width: 8px;
        height: 8px;
    }
}

/* ===== Animations ===== */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calendar-day {
    animation: slideIn 0.3s ease forwards;
}

.calendar-day:nth-child(1) {
    animation-delay: 0.02s;
}

.calendar-day:nth-child(7) {
    animation-delay: 0.04s;
}

.calendar-day:nth-child(14) {
    animation-delay: 0.06s;
}

.calendar-day:nth-child(21) {
    animation-delay: 0.08s;
}

.calendar-day:nth-child(28) {
    animation-delay: 0.1s;
}

.calendar-day:nth-child(35) {
    animation-delay: 0.12s;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-glass);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Focus Styles */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Selection */
::selection {
    background: rgba(233, 69, 96, 0.3);
    color: var(--text-primary);
}