/* style.css — тёмная тема + улучшенная адаптивность */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #121212;
    min-height: 100vh;
    padding: 15px;
    color: #e0e0e0;
    line-height: 1.6;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    background: #1e1e1e;
    border-radius: 24px;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #181818, #676669);
    color: white;
    padding: 40px 20px;
    text-align: center;
}

header h1 {
    font-size: 2.2rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Секции */
section {
    padding: 35px 20px;
    border-bottom: 1px solid #333;
}

h2 {
    font-size: 1.85rem;
    margin-bottom: 20px;
    color: #e0e0e0;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

h3 {
    font-size: 1.35rem;
    margin-bottom: 15px;
}

/* Поля ввода */
.input-group {
    display: grid;
    grid-template-columns: 2fr 1fr auto 1fr;
    gap: 12px;
    align-items: end;
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .input-group {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .convert-arrow {
        font-size: 2.2rem;
        padding: 5px 0;
        justify-self: center;
    }
}

input, select {
    padding: 14px 16px;
    border: 2px solid #444;
    border-radius: 12px;
    font-size: 1.05rem;
    background: #2d2d2d;
    color: #f0f0f0;
    width: 100%;
    transition: all 0.3s;
}

input:focus, select:focus {
    border-color: #6366f1;
    background: #333;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.25);
    outline: none;
}

.convert-arrow {
    font-size: 2rem;
    color: #8a8aff;
    text-align: center;
    padding-bottom: 8px;
}

/* Кнопки */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s;
    width: 100%;
    justify-content: center;
    margin: 8px 0;
}

@media (min-width: 769px) {
    .btn {
        width: auto;
        margin: 0 8px 0 0;
    }
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.btn.primary   { background: #6366f1; color: white; }
.btn.secondary { background: #64748b; color: white; }
.btn.danger    { background: #ef4444; color: white; }

/* Результат */
.result-box {
    background: #2d2d2d;
    border: 2px solid #6366f1;
    border-radius: 16px;
    padding: 24px;
    font-size: 1.65rem;
    font-weight: 700;
    text-align: center;
    margin: 20px 0;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #bbd0ff;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}

@media (max-width: 480px) {
    .result-box {
        font-size: 1.4rem;
        padding: 20px;
    }
}

/* ========== АДАПТИВНАЯ ТАБЛИЦА ДЛЯ BUDGET ========== */

/* Контейнер для таблицы с горизонтальной прокруткой */
#budget {
    overflow-x: hidden;
}

#budget h3:first-of-type {
    margin-top: 20px;
}

/* Адаптивная обертка для таблицы */
.table-wrapper {
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #252525;
    border-radius: 12px;
    overflow: hidden;
    min-width: 500px;
}

@media (max-width: 640px) {
    table {
        min-width: 480px;
    }
    
    .table-wrapper {
        margin: 20px -15px;
        padding: 0 15px;
        width: calc(100% + 30px);
    }
}

th, td {
    padding: 14px 10px;
    text-align: left;
    border-bottom: 1px solid #333;
    font-size: 0.95rem;
}

th {
    background: #333;
    font-weight: 600;
    color: #a0a0ff;
    text-transform: uppercase;
    font-size: 0.85rem;
}

/* Компактные ячейки на мобильных */
@media (max-width: 640px) {
    th, td {
        padding: 12px 8px;
        font-size: 0.85rem;
    }
    
    th:first-child, td:first-child {
        padding-left: 12px;
    }
    
    th:last-child, td:last-child {
        padding-right: 12px;
    }
}

/* Кнопка удалить в таблице */
td button, button[onclick*="deleteExpense"] {
    background-color: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
    transition: all 0.2s;
}

td button:hover, button[onclick*="deleteExpense"]:hover {
    background-color: #dc2626;
    transform: scale(1.02);
}

/* ========== АДАПТИВНАЯ ФОРМА ДОБАВЛЕНИЯ РАСХОДА ========== */

/* Специальные стили для формы бюджета */
#budget .input-group {
    grid-template-columns: 2fr 1fr 1fr 1.4fr;
    gap: 12px;
}

@media (max-width: 768px) {
    #budget .input-group {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    #budget .input-group input,
    #budget .input-group select {
        width: 100%;
    }
}

/* Стили для итоговой строки */
tfoot tr {
    background: #3d3d3d;
}

tfoot td {
    font-weight: bold;
    font-size: 1rem;
}

@media (max-width: 640px) {
    tfoot td {
        font-size: 0.9rem;
    }
}

#total-rub {
    color: #4ade80;
    font-weight: bold;
    font-size: 1.05rem;
}

/* Кнопки управления бюджетом */
#budget > div:last-of-type {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 30px 0;
}

@media (max-width: 480px) {
    #budget > div:last-of-type {
        flex-direction: column;
    }
    
    #budget > div:last-of-type .btn {
        width: 100%;
        margin: 0;
    }
}

/* Адаптация заголовков секции */
@media (max-width: 480px) {
    #budget h3 {
        font-size: 1.2rem;
    }
    
    #budget h3 i {
        font-size: 1rem;
    }
}

/* Улучшение читаемости на очень маленьких экранах */
@media (max-width: 380px) {
    th, td {
        padding: 10px 6px;
        font-size: 0.8rem;
    }
    
    td button {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}

footer {
    background: #1a1a1a;
    padding: 25px 20px;
    text-align: center;
    color: #888;
    font-size: 0.95rem;
    border-top: 1px solid #333;
}

footer p {
    margin: 6px 0;
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.9rem;
    }
    
    section {
        padding: 28px 15px;
    }
    
    .input-group {
        gap: 14px;
    }
}