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

:root {
    --primary: #2196F3;
    --success: #4CAF50;
    --warning: #FFC107;
    --danger: #F44336;
    --purple: #9C27B0;
    --white: #ffffff;
    --light-gray: #f5f5f5;
    --gray: #9e9e9e;
    --dark-gray: #424242;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --border-radius: 8px;
    --transition: all 0.3s ease;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--light-gray) 0%, #e8e8e8 100%);
    background-attachment: fixed;
    min-height: 100vh;
    padding-bottom: 80px;
    color: var(--dark-gray);
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.3) 1px, transparent 0);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: -1;
}

.app-header {
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: var(--white);
    padding: 1rem;
    text-align: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.app-header h1 i {
    margin-right: 0.5rem;
    animation: rotate 2s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.app-main {
    padding: 1rem;
    max-width: 800px;
    margin: 0 auto;
}

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

.section.active {
    display: block;
}

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

.converter-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.category-selector {
    margin-bottom: 1.5rem;
}

.category-selector label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-gray);
}

.category-select, .unit-select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--white);
}

.category-select:focus, .unit-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.conversion-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
    position: relative;
}

.input-group {
    flex: 1;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-gray);
}

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

.unit-input input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

.unit-input input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.unit-input select {
    flex: 1;
    min-width: 120px;
}

.swap-btn {
    align-self: center;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
    margin: 0.5rem 0;
}

.swap-btn:hover {
    background: #1976D2;
    transform: rotate(180deg);
}

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

.btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    justify-content: center;
}

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

.btn.primary:hover {
    background: #1976D2;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.btn.secondary {
    background: var(--gray);
    color: var(--white);
}

.btn.secondary:hover {
    background: #757575;
    transform: translateY(-2px);
}

.btn.danger {
    background: var(--danger);
    color: var(--white);
}

.btn.danger:hover {
    background: #d32f2f;
    transform: translateY(-2px);
}

.batch-converter {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid #e0e0e0;
}

.batch-converter h3 {
    margin-bottom: 1rem;
    color: var(--dark-gray);
}

.batch-converter textarea {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    resize: vertical;
    margin-bottom: 1rem;
    transition: var(--transition);
}

.batch-converter textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.batch-results {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    display: none;
}

.batch-results.show {
    display: block;
}

.batch-result-item {
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: var(--white);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--success);
}

.calculator-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    max-width: 400px;
    margin: 0 auto;
}

.calculator-display {
    margin-bottom: 1rem;
}

.calculator-display input {
    width: 100%;
    padding: 1rem;
    font-size: 1.5rem;
    text-align: right;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    background: var(--light-gray);
}

.calculator-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.calc-btn {
    padding: 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    background: var(--light-gray);
    color: var(--dark-gray);
}

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

.calc-btn.number {
    background: var(--white);
}

.calc-btn.operator {
    background: var(--primary);
    color: var(--white);
}

.calc-btn.equals {
    background: var(--success);
    color: var(--white);
}

.calc-btn.clear {
    background: var(--danger);
    color: var(--white);
}

.calc-btn.span-2 {
    grid-column: span 2;
}

.history-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.history-header h2 {
    color: var(--dark-gray);
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary);
    cursor: pointer;
    transition: var(--transition);
}

.history-item:hover {
    background: #eeeeee;
    transform: translateX(5px);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.history-item-conversion {
    font-weight: 600;
    color: var(--dark-gray);
}

.history-item-date {
    font-size: 0.9rem;
    color: var(--gray);
}

.history-item-details {
    font-size: 0.9rem;
    color: var(--gray);
}

.custom-units-container {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.custom-units-container h2 {
    margin-bottom: 1.5rem;
    color: var(--dark-gray);
}

.custom-form {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid #e0e0e0;
}

.custom-form h3 {
    margin-bottom: 1rem;
    color: var(--dark-gray);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-gray);
}

.form-group input, .form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.custom-units-list {
    max-height: 300px;
    overflow-y: auto;
}

.custom-unit-item {
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: var(--light-gray);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--purple);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-unit-info {
    flex: 1;
}

.custom-unit-name {
    font-weight: 600;
    color: var(--dark-gray);
}

.custom-unit-details {
    font-size: 0.9rem;
    color: var(--gray);
    margin-top: 0.25rem;
}

.delete-custom-unit {
    background: var(--danger);
    color: var(--white);
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    transition: var(--transition);
}

.delete-custom-unit:hover {
    background: #d32f2f;
    transform: scale(1.1);
}

.faq-section {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-top: 2rem;
}

.faq-section h2 {
    margin-bottom: 1.5rem;
    color: var(--dark-gray);
}

.faq-item {
    margin-bottom: 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.faq-question {
    width: 100%;
    padding: 1rem;
    background: var(--light-gray);
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark-gray);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.faq-question:hover {
    background: #eeeeee;
}

.faq-question[aria-expanded="true"] {
    background: var(--primary);
    color: var(--white);
}

.faq-question[aria-expanded="true"] .faq-icon {
    transform: rotate(45deg);
}

.faq-icon {
    font-size: 1.2rem;
    transition: var(--transition);
}

.faq-answer {
    padding: 1rem;
    background: var(--white);
    border-top: 1px solid #e0e0e0;
    animation: slideDown 0.3s ease-out;
}

.faq-answer[hidden] {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    to {
        opacity: 1;
        max-height: 200px;
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
}

.empty-state {
    text-align: center;
    color: var(--gray);
    font-style: italic;
    padding: 2rem;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--gray);
    padding: 0.5rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    min-width: 60px;
}

.nav-item:hover {
    color: var(--primary);
    background: rgba(33, 150, 243, 0.1);
}

.nav-item.active {
    color: var(--primary);
    background: rgba(33, 150, 243, 0.1);
}

.nav-item i {
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
}

.nav-item span {
    font-size: 0.8rem;
    font-weight: 600;
}

footer {
    text-align: center;
    padding: 1rem;
    color: var(--gray);
    font-size: 0.9rem;
    margin-top: 2rem;
}

@media (min-width: 768px) {
    .conversion-panel {
        flex-direction: row;
        align-items: end;
    }
    
    .swap-btn {
        margin: 0 1rem;
        margin-top: 1.5rem;
    }
    
    .action-buttons {
        justify-content: center;
    }
    
    .calculator-container {
        max-width: 500px;
    }
    
    .calculator-buttons {
        gap: 1rem;
    }
    
    .calc-btn {
        padding: 1.5rem;
        font-size: 1.4rem;
    }
}

@media (min-width: 1024px) {
    .app-main {
        padding: 2rem;
    }
    
    .converter-container,
    .history-container,
    .custom-units-container,
    .faq-section {
        padding: 2rem;
    }
}

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    color: var(--white);
    font-weight: 600;
    z-index: 2000;
    animation: slideInRight 0.3s ease-out;
}

.notification.success {
    background: var(--success);
}

.notification.error {
    background: var(--danger);
}

.notification.info {
    background: var(--primary);
}

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

.flip-animation {
    animation: flipY 0.6s ease-in-out;
}

@keyframes flipY {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(90deg); }
    100% { transform: rotateY(0deg); }
}

.pulse-animation {
    animation: pulse 0.3s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}
