/* Страница истории: контент выше футера, футер остаётся видимым */
.history-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 64px;
    width: 100%;
    background: #121212;
    z-index: 1500;
    overflow: hidden;
    flex-direction: column;
}

.history-screen.active {
    display: flex;
}

@media (min-width: 769px) {
    .history-screen {
        left: 50%;
        transform: translateX(-50%);
        max-width: 960px;
        width: 960px;
    }
}

body.history-open {
    overflow: hidden;
}

body.light-theme .history-screen {
    background: #f8fafc;
}

.history-screen-header {
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 1;
    background: #121212;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

body.light-theme .history-screen-header {
    background: #f8fafc;
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.history-screen-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    padding: 0 16px;
}

.history-screen-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #f1f5f9;
}

body.light-theme .history-screen-title {
    color: #1e293b;
}

.history-search-corner {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.history-search-corner-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
}

.history-search-corner-btn:hover {
    color: #e2e8f0;
}

.history-search-corner-btn .material-icons {
    font-size: 20px;
}

.history-search-corner-panel {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 180px;
}

.history-screen-header-row.history-search-open .history-screen-title {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

.history-screen-header-row.history-search-open .history-search-corner {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
}

.history-screen-header-row.history-search-open .history-search-corner-btn {
    display: none;
}

.history-screen-header-row.history-search-open .history-search-corner-panel {
    flex: 1;
    min-width: 0;
    max-width: none;
    width: 100%;
}

.history-search-corner-panel[hidden] {
    display: none !important;
}

.history-search-corner-input {
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 0 10px;
    font-size: 14px;
    line-height: 32px;
    border: none;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    color: #f1f5f9;
    outline: none;
    box-sizing: border-box;
}

.history-search-corner-input::placeholder {
    color: #64748b;
}

.history-search-corner-input:focus {
    border: none;
    background: rgba(255, 255, 255, 0.12);
}

.history-search-corner-close {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
}

.history-search-corner-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

.history-search-corner-close .material-icons {
    font-size: 20px;
}

body.light-theme .history-search-corner-btn {
    color: #64748b;
}

body.light-theme .history-search-corner-btn:hover {
    color: #334155;
}

body.light-theme .history-search-corner-input {
    background: rgba(0, 0, 0, 0.06);
    color: #1e293b;
}

body.light-theme .history-search-corner-input::placeholder {
    color: #94a3b8;
}

body.light-theme .history-search-corner-input:focus {
    background: rgba(0, 0, 0, 0.1);
}

body.light-theme .history-search-corner-close {
    color: #64748b;
}

body.light-theme .history-search-corner-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #334155;
}

.history-screen-phone {
    position: relative;
    flex: 1;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
}

.history-screen-phone-inner {
    padding: 20px;
    padding-bottom: 24px;
    min-height: 100%;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.history-day {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-day-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.history-day-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #e2e8f0;
}

.history-day-sum {
    margin-left: auto;
    margin-right: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #94a3b8;
}

body.light-theme .history-day-title {
    color: #334155;
}

body.light-theme .history-day-sum {
    color: #64748b;
}

.history-day-entries {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-day-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

.history-day-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #94a3b8;
}

.history-day-item-icon .material-icons {
    font-size: 20px;
}

.history-day-item-category {
    flex: 1;
    min-width: 0;
}

.history-day-item-amount {
    flex-shrink: 0;
}

body.light-theme .history-day-item {
    background: rgba(0, 0, 0, 0.04);
}

.history-day-item-category {
    color: #cbd5e1;
}

body.light-theme .history-day-item-category {
    color: #475569;
}

.history-day-item-amount {
    font-weight: 500;
    color: #f1f5f9;
}

body.light-theme .history-day-item-amount {
    color: #1e293b;
}

.history-day-empty {
    padding: 12px;
    font-size: 14px;
    color: #94a3b8;
}

body.light-theme .history-day-empty {
    color: #64748b;
}

/* Оверлей редактирования записи — сплывашка по аналогии с голосовым вводом */
.history-edit-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    justify-content: center;
    align-items: flex-end;
}

.history-edit-overlay.active {
    display: flex;
}

.history-edit-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.history-edit-box {
    position: relative;
    width: 100%;
    max-height: 50vh;
    background: #1f1f1f;
    color: #f2f2f2;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.light-theme .history-edit-box {
    background: #fff;
    color: #1f2937;
    border-color: #d4d9e2;
}

.history-edit-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    padding: 12px 12px 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

body.light-theme .history-edit-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.history-edit-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #f1f5f9;
    flex: 1;
    min-width: 0;
}

body.light-theme .history-edit-title {
    color: #1e293b;
}

.history-edit-close {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
}

.history-edit-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

body.light-theme .history-edit-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #334155;
}

.history-edit-close .material-icons {
    font-size: 24px;
}

.history-edit-content {
    padding: 20px;
    overflow: auto;
}

.history-edit-field {
    margin-bottom: 16px;
}

.history-edit-field:last-of-type {
    margin-bottom: 0;
}

.history-edit-label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

body.light-theme .history-edit-label {
    color: #64748b;
}

.history-edit-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    color: #f1f5f9;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    box-sizing: border-box;
}

.history-edit-input:focus {
    outline: none;
    border-color: #5b8def;
}

body.light-theme .history-edit-input {
    color: #1e293b;
    background: #f1f5f9;
    border-color: rgba(0, 0, 0, 0.12);
}

body.light-theme .history-edit-input:focus {
    border-color: #4f7cff;
}

.history-edit-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 20px;
    padding: 12px 16px;
    font-size: 14px;
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 10px;
    cursor: pointer;
}

.history-edit-delete-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #fecaca;
}

.history-edit-delete-btn .material-icons {
    font-size: 20px;
}

body.light-theme .history-edit-delete-btn {
    color: #b91c1c;
    background: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.25);
}

body.light-theme .history-edit-delete-btn:hover {
    background: rgba(220, 38, 38, 0.18);
    color: #991b1b;
}

/* Подтверждение удаления записи во всплывашке */
.history-edit-delete-confirm {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 15;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.history-edit-delete-confirm.active {
    display: flex;
}

.history-edit-delete-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.history-edit-delete-confirm-box {
    position: relative;
    background: #1f1f1f;
    color: #f1f5f9;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    min-width: 260px;
}

body.light-theme .history-edit-delete-confirm-box {
    background: #fff;
    color: #1e293b;
    border-color: rgba(0, 0, 0, 0.1);
}

.history-edit-delete-confirm-text {
    margin: 0 0 20px;
    font-size: 16px;
}

.history-edit-delete-confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.history-edit-delete-confirm-delete {
    padding: 10px 20px;
    font-size: 14px;
    border: none;
    border-radius: 8px;
    background: #dc2626;
    color: #fff;
    cursor: pointer;
}

.history-edit-delete-confirm-delete:hover {
    background: #b91c1c;
}

.history-edit-delete-confirm-cancel {
    padding: 10px 20px;
    font-size: 14px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    cursor: pointer;
}

.history-edit-delete-confirm-cancel:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #e2e8f0;
}

body.light-theme .history-edit-delete-confirm-cancel {
    background: #f1f5f9;
    color: #64748b;
}

body.light-theme .history-edit-delete-confirm-cancel:hover {
    background: #e2e8f0;
    color: #334155;
}

/* Экран графика (открывается из истории) */
.charts-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 64px;
    width: 100%;
    background: #121212;
    z-index: 1600;
    overflow: hidden;
    flex-direction: column;
}

.charts-screen.active {
    display: flex;
}

@media (min-width: 769px) {
    .charts-screen {
        left: 50%;
        transform: translateX(-50%);
        max-width: 960px;
        width: 960px;
    }
}

body.light-theme .charts-screen {
    background: #f8fafc;
}

.charts-screen-header {
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 1;
    background: #121212;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

body.light-theme .charts-screen-header {
    background: #f8fafc;
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

.charts-screen-header-row {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 0 16px;
    gap: 12px;
}

.charts-screen-back {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
}

.charts-screen-back:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
}

.charts-screen-back .material-icons {
    font-size: 24px;
}

body.light-theme .charts-screen-back:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1e293b;
}

.charts-screen-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #f1f5f9;
}

body.light-theme .charts-screen-title {
    color: #1e293b;
}

.charts-screen-phone {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.charts-screen-phone-inner {
    padding: 16px;
}

.charts-screen-caption {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #94a3b8;
    text-align: center;
}

body.light-theme .charts-screen-caption {
    color: #64748b;
}

.charts-empty {
    text-align: center;
    color: #94a3b8;
    font-size: 15px;
    margin: 2rem 0;
    padding: 0 16px;
}

body.light-theme .charts-empty {
    color: #64748b;
}

.charts-donut-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.charts-donut-canvas {
    display: block;
    flex-shrink: 0;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.charts-donut-canvas:focus {
    outline: none;
}

.charts-legend {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.charts-legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #e2e8f0;
    padding: 6px 10px;
    margin: 0 -10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.charts-legend-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.charts-legend-item.selected {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
}

body.light-theme .charts-legend-item {
    color: #334155;
}

body.light-theme .charts-legend-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .charts-legend-item.selected {
    background: rgba(0, 0, 0, 0.1);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.charts-legend-color {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.charts-legend-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.charts-legend-value {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    color: #94a3b8;
}

body.light-theme .charts-legend-value {
    color: #64748b;
}
