/* ===== Базовые ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
    background-color: #f0f2f5;
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
    color: #263238;
    min-height: 100vh;
    padding-bottom: 72px;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

h1, h2, h3 { font-family: 'Montserrat', sans-serif; color: #1a237e; margin: 0; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { font-size: 16px; line-height: 1.55; color: #455a64; margin: 0 0 12px; }

.app { max-width: 600px; margin: 0 auto; background: #fff; min-height: 100vh; }
.screen { display: none; }
.screen.active { display: block; }

.header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: linear-gradient(135deg, #1a237e, #0d47a1);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.header h2 { color: #fff; font-size: 18px; }
.header .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1a237e;
    font-weight: 700;
    overflow: hidden;
}
.header .avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Экран "Учёба" (презентация) ===== */
.slide-section {
    min-height: calc(100vh - 72px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px 20px;
    border-bottom: 1px solid #eee;
}
.slide-title { font-size: 22px; font-weight: 700; margin-bottom: 24px; border-left: 5px solid #00c853; padding-left: 14px; }
.image-box { width: 100%; border-radius: 15px; overflow: hidden; margin: 16px 0; box-shadow: 0 10px 20px rgba(0,0,0,0.08); }
.image-box img { width: 100%; display: block; }
.card {
    background: #f8f9fa;
    padding: 18px;
    border-radius: 15px;
    margin-bottom: 12px;
    border-bottom: 4px solid #00c853;
}
.timeline-v { position: relative; padding-left: 40px; }
.timeline-v::before { content: ''; position: absolute; left: 15px; top: 0; bottom: 0; width: 2px; background: #00c853; }
.timeline-v-item { position: relative; margin-bottom: 28px; }
.timeline-v-item::after {
    content: ''; position: absolute; left: -32px; top: 5px;
    width: 14px; height: 14px; background: #1a237e;
    border-radius: 50%; border: 3px solid #fff;
    box-shadow: 0 0 0 2px #00c853;
}
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: #1a237e; color: white; padding: 10px; text-align: left; }
td { padding: 10px; border-bottom: 1px solid #eee; }

/* ===== Экран "Копилки" ===== */
.goals-list { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.goal-card {
    background: #fff;
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 4px 18px rgba(26, 35, 126, 0.08);
    border: 1px solid #e8eaf6;
}
.goal-card__head {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}
.goal-card__icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, #1a237e, #00c853);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.goal-card__title { flex: 1; }
.goal-card__title h3 { font-size: 17px; margin-bottom: 2px; }
.goal-card__title .sum { font-size: 13px; color: #78909c; }
.goal-card__edit {
    background: transparent;
    border: none;
    color: #90a4ae;
    font-size: 18px;
    padding: 6px;
}
.progress-bar {
    height: 22px;
    background: #eceff1;
    border-radius: 11px;
    margin: 10px 0 14px;
    overflow: hidden;
    position: relative;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #1a237e, #00c853);
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: white;
    font-size: 11px;
    font-weight: bold;
    transition: width 0.4s ease;
    white-space: nowrap;
}
.goal-card__actions { display: flex; gap: 10px; }
.btn {
    flex: 1;
    padding: 13px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.05s;
}
.btn:active { transform: scale(0.97); }
.btn-plus { background: #00c853; color: #fff; }
.btn-minus { background: #ef5350; color: #fff; }
.btn-primary { background: #1a237e; color: #fff; width: 100%; }
.btn-ghost { background: #eceff1; color: #455a64; }

.goal-card.done .progress-fill { background: #00c853; }
.goal-card.done::before {
    content: '🎉 Готово!';
    display: block;
    background: #00c853;
    color: #fff;
    border-radius: 10px;
    text-align: center;
    padding: 6px;
    margin-bottom: 10px;
    font-weight: 700;
    font-size: 13px;
}

/* ===== Экран "История" ===== */
.history-list { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.history-empty { text-align: center; color: #90a4ae; padding: 40px 20px; }
.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid #eceff1;
}
.history-item__icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    color: #fff;
}
.history-item.plus .history-item__icon { background: #00c853; }
.history-item.minus .history-item__icon { background: #ef5350; }
.history-item__body { flex: 1; min-width: 0; }
.history-item__body .goal-name { font-weight: 600; font-size: 14px; color: #263238; }
.history-item__body .meta { font-size: 12px; color: #90a4ae; margin-top: 2px; }
.history-item__amount { font-weight: 700; font-size: 15px; }
.history-item.plus .history-item__amount { color: #00c853; }
.history-item.minus .history-item__amount { color: #ef5350; }
.history-item__del {
    background: transparent;
    border: none;
    color: #cfd8dc;
    font-size: 14px;
    padding: 6px;
    margin-left: 4px;
}

/* ===== Нижние табы ===== */
.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 68px;
    background: #fff;
    border-top: 1px solid #eceff1;
    display: flex;
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.04);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: #90a4ae;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    transition: color 0.15s;
}
.tabbar__item i { font-size: 20px; }
.tabbar__item.active { color: #1a237e; }

/* ===== Модалка ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(26, 35, 126, 0.5);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    padding: 0;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 24px 20px 32px;
    width: 100%;
    max-width: 600px;
    animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h3 { margin-bottom: 18px; text-align: center; }
.modal label { display: block; font-size: 13px; color: #78909c; margin-bottom: 6px; font-weight: 600; }
.modal input[type="number"], .modal input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 2px solid #eceff1;
    font-size: 17px;
    outline: none;
    transition: border-color 0.15s;
}
.modal input:focus { border-color: #1a237e; }
.modal .row { margin-bottom: 14px; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions button { flex: 1; }

.quick-amounts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick-amounts button {
    flex: 1;
    min-width: 60px;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid #eceff1;
    background: #f8f9fa;
    font-weight: 600;
    font-size: 13px;
}

.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: #263238;
    color: #fff;
    padding: 10px 18px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.error { background: #c62828; }

.summary {
    padding: 16px 20px;
    background: linear-gradient(135deg, #1a237e, #00c853);
    color: #fff;
    border-radius: 0 0 24px 24px;
    margin-bottom: 16px;
}
.summary small { font-size: 12px; opacity: 0.85; }
.summary .big { font-size: 28px; font-weight: 700; margin-top: 2px; font-family: 'Montserrat', sans-serif; }

/* ===== Экран одной копилки ===== */
.header-back, .header-edit {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 18px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 10px;
}
.header-back:active, .header-edit:active { background: rgba(255,255,255,0.15); }

.goal-detail { padding: 0; }
.goal-hero {
    padding: 24px 20px;
    background: linear-gradient(135deg, #1a237e, #00c853);
    color: #fff;
    border-radius: 0 0 24px 24px;
    margin-bottom: 20px;
    text-align: center;
}
.goal-hero__icon {
    width: 72px;
    height: 72px;
    border-radius: 22px;
    background: rgba(255,255,255,0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin-bottom: 12px;
}
.goal-hero h2 { color: #fff; margin-bottom: 6px; font-size: 24px; }
.goal-hero .sum { font-size: 16px; opacity: 0.9; margin-bottom: 14px; }
.goal-hero .progress-bar { background: rgba(255,255,255,0.2); margin: 0; }
.goal-hero .progress-fill { background: #fff; color: #1a237e; }

.goal-actions {
    display: flex;
    gap: 10px;
    padding: 0 20px;
    margin-bottom: 24px;
}

.section-title {
    padding: 0 20px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.section-title h3 { font-size: 16px; color: #1a237e; }
.section-title button {
    background: transparent;
    border: none;
    color: #1a237e;
    font-weight: 600;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 8px;
}
.section-title button:active { background: #eceff1; }

.media-gallery {
    padding: 0 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 8px;
}
.media-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: 14px;
    overflow: hidden;
    background: #eceff1;
    cursor: pointer;
}
.media-card img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.media-card .caption {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: #fff;
    padding: 18px 10px 8px;
    font-size: 12px;
    line-height: 1.3;
}
.media-card .del {
    position: absolute;
    top: 8px; right: 8px;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    width: 28px; height: 28px;
    border-radius: 14px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.video-list {
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 8px;
}
.video-card {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 16 / 9;
}
.video-card iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
.video-card .del {
    position: absolute;
    top: 8px; right: 8px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    border: none;
    width: 30px; height: 30px;
    border-radius: 15px;
    z-index: 2;
    cursor: pointer;
    font-size: 13px;
}
.video-card .caption {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,0.55);
    color: #fff;
    padding: 8px 12px;
    font-size: 13px;
}

.empty-hint {
    margin: 0 20px 16px;
    padding: 18px;
    border: 2px dashed #cfd8dc;
    border-radius: 14px;
    text-align: center;
    color: #78909c;
    font-size: 14px;
}

.detail-history {
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

/* ===== Photo viewer ===== */
.photo-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 400;
}
.photo-viewer.open { display: flex; }
.photo-viewer img {
    max-width: 95%;
    max-height: 90%;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.photo-viewer .close-btn {
    position: absolute;
    top: 16px; right: 16px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: none;
    width: 44px; height: 44px;
    border-radius: 22px;
    font-size: 20px;
    cursor: pointer;
}
