/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #059669;
    --error-color: #dc2626;
    --warning-color: #d97706;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: all 0.15s ease-in-out;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 2rem 0;
    box-shadow: var(--shadow-md);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.title-section {
    text-align: center;
    flex: 1;
}

.app-title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.app-title i {
    font-size: 2rem;
}

.app-subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 400;
}

/* Theme Toggle */
.theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

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

.theme-icon {
    transition: transform 0.3s ease;
}

.theme-toggle.rotate .theme-icon {
    transform: rotate(180deg);
}

/* Navigation */
.main-nav {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.nav-btn {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.nav-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 0;
}

.tab-content {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.tab-content.active {
    display: block;
}

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

.section-header {
    text-align: center;
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Converter Cards */
.converters-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.converter-card {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.converter-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.converter-card.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
    box-shadow: var(--shadow-lg);
}

.converter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.converter-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    font-size: 1rem;
    transition: var(--transition);
}

.drag-handle:hover {
    color: var(--primary-color);
}

.drag-handle:active {
    cursor: grabbing;
}

.collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: var(--transition);
}

.collapse-btn:hover {
    background: var(--background-color);
    color: var(--primary-color);
}

.collapse-btn i {
    transition: transform 0.3s ease;
}

.collapse-btn[aria-expanded="false"] i {
    transform: rotate(-90deg);
}

.converter-content {
    padding: 1.5rem;
    transition: all 0.3s ease-in-out;
    max-height: 500px;
    overflow: hidden;
}

.converter-content.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.conversion-form {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1.5rem;
    align-items: end;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.input-row {
    display: flex;
    gap: 0.5rem;
}

.input-row input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--surface-color);
    color: var(--text-primary);
}

.input-row input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.input-row input:read-only {
    background: var(--background-color);
    color: var(--text-secondary);
}

.input-row select {
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--surface-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    min-width: 160px;
    max-width: 180px;
}

.input-row select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.swap-section {
    display: flex;
    align-items: center;
    justify-content: center;
}

.swap-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.swap-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.1);
}

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

/* Age Calculator */
.age-calculator-container {
    max-width: 600px;
    margin: 0 auto;
}

.date-inputs {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.date-input-group {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.date-input-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.date-input-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--surface-color);
    color: var(--text-primary);
}

.date-input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.set-current-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.set-current-btn:hover {
    background: var(--text-primary);
    transform: translateY(-1px);
}

.calculate-section {
    text-align: center;
    margin-bottom: 2rem;
}

.calculate-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: var(--radius-lg);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 auto;
    box-shadow: var(--shadow-md);
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.calculate-btn:active {
    transform: translateY(0);
}

.age-results {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    animation: slideUp 0.5s ease-out;
}

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

.result-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.result-card {
    text-align: center;
    padding: 1.5rem 1rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.result-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: white;
}

.result-label {
    font-size: 0.9rem;
    opacity: 0.9;
    font-weight: 500;
}

.detailed-results {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.detailed-results h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.detailed-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-secondary);
    background: var(--background-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary-color);
}

.error-message {
    background: #fef2f2;
    color: var(--error-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid #fecaca;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.hidden {
    display: none;
}

/* Footer */
.footer {
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 2rem 0;
    text-align: center;
    color: var(--text-secondary);
    margin-top: auto;
}

.footer i {
    color: var(--error-color);
    animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Install Prompt */
.install-prompt {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.5s ease-out;
}

.install-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    gap: 1rem;
}

.install-content i {
    color: var(--primary-color);
    font-size: 1.2rem;
}

.install-buttons {
    display: flex;
    gap: 0.5rem;
}

.install-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.install-btn:hover {
    background: var(--primary-dark);
}

.dismiss-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.dismiss-btn:hover {
    background: var(--background-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .title-section {
        order: 1;
    }
    
    .theme-toggle {
        order: 0;
        align-self: flex-end;
    }
    
    .app-title {
        font-size: 2rem;
    }
    
    .nav-buttons {
        flex-direction: column;
    }
    
    .conversion-form {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .swap-section {
        order: 2;
        margin: 0.5rem 0;
    }
    
    .input-row {
        flex-direction: column;
    }
    
    .input-row select {
        min-width: auto;
        max-width: none;
    }
    
    .result-cards {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    }
    
    .result-value {
        font-size: 1.5rem;
    }
    
    .install-content {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }
    
    .date-inputs {
        gap: 1rem;
    }
    
    .date-input-group {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 0.5rem;
    }
    
    .header {
        padding: 1.5rem 0;
    }
    
    .app-title {
        font-size: 1.5rem;
    }
    
    .converter-content {
        padding: 1rem;
    }
    
    .result-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .result-card {
        padding: 1rem 0.5rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
[data-theme="dark"] {
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
}

[data-theme="dark"] .converter-header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

[data-theme="dark"] .theme-icon::before {
    content: "\f185"; /* sun icon */
}

/* Default light mode */
[data-theme="light"] .theme-icon::before {
    content: "\f186"; /* moon icon */
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background-color: #0f172a;
        --surface-color: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
    }
    
    :root:not([data-theme="light"]) .converter-header {
        background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    }
    
    .theme-icon::before {
        content: "\f185"; /* sun icon for dark mode */
    }
}

/* Print styles */
@media print {
    .header, .main-nav, .footer, .install-prompt {
        display: none;
    }
    
    .converter-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .age-results {
        break-inside: avoid;
    }
}
