/* ===========================
   1. Base & Variables
=========================== */
:root {
    --bg: #f8f9fa;
    --text: #212529;
    --card-bg: #ffffff;
    --card-shadow: 0 2px 8px rgba(0,0,0,.04);
    --border: #eee;
    --muted: #666;
    --input-bg: #fff;
    --input-border: #ced4da;
    --link: #0d6efd;
    --action-expense-bg: rgba(220, 53, 69, 0.05);
    --action-income-bg: rgba(25, 135, 84, 0.05);
    --action-deal-bg: rgba(13, 110, 253, 0.05);
    --action-client-bg: rgba(108, 117, 125, 0.05);
    --keyboard-height: 0px;
}

body.dark {
    --bg: #1a1a2e;
    --text: #e0e0e0;
    --card-bg: #16213e;
    --card-shadow: 0 2px 8px rgba(0,0,0,.3);
    --border: #2a2a4a;
    --muted: #aaa;
    --input-bg: #0f3460;
    --input-border: #2a2a4a;
    --link: #64b5f6;
    --action-expense-bg: rgba(220, 53, 69, 0.1);
    --action-income-bg: rgba(25, 135, 84, 0.1);
    --action-deal-bg: rgba(13, 110, 253, 0.1);
    --action-client-bg: rgba(108, 117, 125, 0.1);
}

html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    transition: background 0.3s, color 0.3s;
}

html, body {
    height: 100%;
    overflow-y: auto;
}

.app-root {
    min-height: 100vh;
}

/* ===========================
   2. Layout & Structure
=========================== */
.app-topbar {
    height: 56px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}

.app-title {
    font-weight: 600;
    font-size: 18px;
    color: var(--text);
}

.app-content {
    padding: 12px;
    padding-bottom: calc(80px + var(--keyboard-height));
    transition: padding-bottom 0.2s ease-out;
}

@media (min-width: 768px) {
    .app-content {
        padding: 20px 32px;
        padding-bottom: calc(40px + var(--keyboard-height));
    }
}

/* PWA Keyboard Fallback */
body.keyboard-open .app-content {
    padding-bottom: calc(80px + max(var(--keyboard-height), 180px));
}

@media (min-width: 768px) {
    body.keyboard-open .app-content {
        padding-bottom: calc(40px + max(var(--keyboard-height), 180px));
    }
}

/* ===========================
   3. Bottom Navigation
=========================== */
.app-bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 64px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 0 10px;
    display: flex;
    align-items: center;
    z-index: 1000;
}

    .app-bottomnav .nav-item {
        flex: 1;
        color: var(--text);
        text-decoration: none;
        font-size: 12px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 64px;
    }

.nav-icon {
    font-size: 20px;
    line-height: 1;
}

.nav-label {
    margin-top: 3px;
    font-size: 11px;
    opacity: .9;
}

/* ===========================
   4. Center FAB Button
=========================== */
.nav-item-center {
    width: 84px;
    height: 64px;
}

.fab-btn-wrap {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 84px;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    z-index: 1200;
    pointer-events: none;
}

.nav-fab {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #1976d2;
    color: white;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(25,118,210,.28);
    cursor: pointer;
    padding: 0;
    margin-top: -10px;
    transition: transform .3s ease, box-shadow .15s ease, background .3s ease;
    pointer-events: auto;
}

    .nav-fab:hover {
        box-shadow: 0 8px 20px rgba(25,118,210,.35);
    }

    .nav-fab:active {
        transform: scale(.94);
    }

    .nav-fab.active {
        transform: rotate(45deg);
        background: #e53935;
    }

/* ===========================
   5. Overlays
=========================== */
.sidebar-overlay,
.fab-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.sidebar-overlay {
    z-index: 1999;
}

.fab-overlay {
    z-index: 1099;
}

    .sidebar-overlay.active,
    .fab-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

/* ===========================
   6. Sidebar
=========================== */
.sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100%;
    background: var(--card-bg);
    box-shadow: none;
    z-index: 2000;
    transition: left 0.35s cubic-bezier(0.25,0.46,0.45,0.94);
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

    .sidebar.open {
        left: 0;
        box-shadow: 4px 0 20px rgba(0,0,0,0.1);
    }

body.dark .sidebar.open {
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
}

/* Профиль */
.sidebar-profile {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 24px 20px 20px;
    background: linear-gradient(135deg, #1976d2, #0d6efd);
    color: #fff;
    text-decoration: none;
    transition: background 0.2s;
    cursor: pointer;
}

    .sidebar-profile:hover {
        background: linear-gradient(135deg, #0d47a1, #0b5ed7);
        color: #fff;
    }

.sidebar-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.sidebar-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
}

.sidebar-avatar-edit {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1976d2;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.sidebar-profile-info {
    min-width: 0;
    flex: 1;
}

.sidebar-fullname {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-login {
    font-size: 12px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.sidebar-role-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 2px 8px;
    background: rgba(255,255,255,0.25);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

/* Секции */
.sidebar-section {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    padding: 8px 8px 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s;
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

    .sidebar-link:hover {
        background: var(--bg);
        color: var(--text);
    }

.sidebar-link-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.sidebar-link-danger {
    color: #dc3545 !important;
}

    .sidebar-link-danger:hover {
        background: rgba(220, 53, 69, 0.08) !important;
    }

body.dark .sidebar-link-danger {
    color: #e57373 !important;
}

    body.dark .sidebar-link-danger:hover {
        background: rgba(229, 115, 115, 0.12) !important;
    }

/* Футер */
.sidebar-footer {
    margin-top: auto;
    padding: 16px 12px;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
}

.sidebar-footer-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px 8px;
}

.sidebar-version {
    color: var(--muted);
    text-decoration: none;
    font-size: 11px;
    padding: 4px 0;
}

    .sidebar-version:hover {
        color: var(--link);
    }

.sidebar-copyright {
    font-size: 10px;
    color: var(--muted);
    opacity: 0.8;
}

/* ===========================
   7. FAB Menu (Radial)
=========================== */
.fab-menu-radial {
    position: fixed;
    left: 50%;
    bottom: 80px;
    transform: translateX(-50%);
    z-index: 1100;
    pointer-events: none;
}

.fab-menu-item-radial {
    position: absolute;
    left: 0;
    top: 0;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--card-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2);
    transition: transform 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.25s ease;
}

    .fab-menu-item-radial:hover {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    }

.fab-icon {
    font-size: 20px;
    line-height: 1;
}

.fab-label {
    font-size: 9px;
    margin-top: 2px;
    font-weight: 500;
}

.fab-menu-radial.open .fab-menu-item-radial {
    opacity: 1;
    pointer-events: auto;
}

/* Позиции кнопок (2/3/4) */
.fab-menu-radial[data-count="2"].open .fab-menu-item-radial:nth-child(1) {
    transform: translate(-50%, -50%) translate(-70px, -85px) scale(1);
    transition-delay: 0.05s;
}

.fab-menu-radial[data-count="2"].open .fab-menu-item-radial:nth-child(2) {
    transform: translate(-50%, -50%) translate(70px, -85px) scale(1);
    transition-delay: 0.1s;
}

.fab-menu-radial[data-count="3"].open .fab-menu-item-radial:nth-child(1) {
    transform: translate(-50%, -50%) translate(-90px, -70px) scale(1);
    transition-delay: 0.05s;
}

.fab-menu-radial[data-count="3"].open .fab-menu-item-radial:nth-child(2) {
    transform: translate(-50%, -50%) translate(0, -105px) scale(1);
    transition-delay: 0.1s;
}

.fab-menu-radial[data-count="3"].open .fab-menu-item-radial:nth-child(3) {
    transform: translate(-50%, -50%) translate(90px, -70px) scale(1);
    transition-delay: 0.15s;
}

.fab-menu-radial[data-count="4"].open .fab-menu-item-radial:nth-child(1) {
    transform: translate(-50%, -50%) translate(-105px, -40px) scale(1);
    transition-delay: 0.05s;
}

.fab-menu-radial[data-count="4"].open .fab-menu-item-radial:nth-child(2) {
    transform: translate(-50%, -50%) translate(-60px, -95px) scale(1);
    transition-delay: 0.1s;
}

.fab-menu-radial[data-count="4"].open .fab-menu-item-radial:nth-child(3) {
    transform: translate(-50%, -50%) translate(60px, -95px) scale(1);
    transition-delay: 0.15s;
}

.fab-menu-radial[data-count="4"].open .fab-menu-item-radial:nth-child(4) {
    transform: translate(-50%, -50%) translate(105px, -40px) scale(1);
    transition-delay: 0.2s;
}

/* ===========================
   8. Cards
=========================== */
.contract-card, .expense-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--card-shadow);
    margin-bottom: 12px;
}

.contract-meta {
    color: var(--muted);
    font-size: 13px;
}

.contract-title {
    font-weight: 700;
    font-size: 16px;
    margin-top: 6px;
    color: var(--text);
}

.contract-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.contract-footer {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

    .contract-footer span {
        color: var(--muted);
        font-size: 12px;
    }

    .contract-footer b {
        display: block;
        font-size: 15px;
    }

.card-divider {
    height: 1px;
    background: var(--border);
    margin: 10px 0;
}

.card-deal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.card-deal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-right: 12px;
    word-break: break-word;
}

.card-deal-amount {
    font-size: 16px;
    font-weight: 700;
    color: var(--link);
    white-space: nowrap;
}

.card-deal-details {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    font-size: 13px;
    color: var(--muted);
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--muted);
    margin-bottom: 2px;
}

.detail-value {
    font-weight: 500;
    color: var(--text);
}

.stats-row .contract-card {
    margin-bottom: 0;
}

.stats-row + .contract-card {
    margin-top: 4px;
}

/* Расходы в Contracts/Details (легаси-страницы) */
.expense-amount {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

.expense-meta {
    color: var(--muted);
    font-size: 12px;
}

/* ===========================
   9. Links & Actions
=========================== */
a.card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

/* ===========================
   10. Useful Links (Main Page)
=========================== */
.useful-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.useful-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    text-decoration: none;
    color: var(--text);
    font-size: 11px;
    font-weight: 500;
    text-align: center;
    padding: 6px;
    transition: transform 0.15s ease;
}

    .useful-link:hover {
        transform: scale(1.05);
    }

.useful-link-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.useful-link-label {
    line-height: 1.2;
    word-break: break-word;
}

/* ===========================
   11. Inline Edit Mode & DnD
=========================== */
.useful-link-wrapper {
    position: relative;
    width: 72px;
}

.edit-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(2px);
}

body.dark .edit-overlay {
    background: rgba(22, 33, 62, 0.85);
}

.drag-handle {
    display: none;
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    cursor: grab;
    color: var(--muted);
    font-size: 16px;
    background: var(--card-bg);
    padding: 0 6px;
    border-radius: 6px;
    border: 1px solid var(--border);
    line-height: 1;
}

#linksSection.is-editing .edit-overlay {
    display: flex;
}

#linksSection.is-editing .drag-handle {
    display: block;
}

#linksSection.is-editing .useful-link-wrapper {
    cursor: grab;
}

#linksSection.is-editing .view-trigger {
    pointer-events: none;
    opacity: 0.6;
}

.useful-link-wrapper.dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

.useful-link-placeholder {
    width: 72px;
    height: 72px;
    background: var(--border);
    border-radius: 12px;
    border: 2px dashed var(--muted);
}

/* ===========================
   12. Form Controls
=========================== */
.amount-input {
    height: 64px;
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    letter-spacing: -0.5px;
}

.toggle-more {
    display: block;
    width: 100%;
    margin: 8px auto 12px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    font-weight: 600;
    color: var(--text);
}

/* Вложенный блок форм (налог, чек) — корректен в обеих темах */
.inner-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
}

/* PWA Keyboard Fix: Reserve space for scroll */
input,
textarea,
select {
    scroll-margin-bottom: calc(var(--keyboard-height, 0px) + 120px);
}

/* Распорка под клавиатуру (Clients/Create) */
.keyboard-spacer {
    height: calc(var(--keyboard-height, 0px));
    position: relative;
}

.spacer-label {
    display: none;
}

/* ===========================
   13. Dark Mode Overrides
=========================== */
body.dark {
    color-scheme: dark;
}

    body.dark .form-control,
    body.dark .form-select {
        background: var(--input-bg);
        border-color: var(--input-border);
        color: var(--text);
    }

    body.dark .btn-light {
        background: #2a2a4a;
        color: #e0e0e0;
        border-color: #3a3a5a;
    }

    body.dark .modal-content {
        background: var(--card-bg);
        color: var(--text);
    }

    body.dark .modal-header {
        border-bottom: 1px solid var(--border);
    }

    body.dark .nav-tabs .nav-link.active {
        background: var(--card-bg);
        color: var(--text);
        border-color: var(--border);
    }

    body.dark .badge.bg-light {
        background: #2a2a4a !important;
        color: #e0e0e0 !important;
    }

    body.dark .contract-card .fw-bold,
    body.dark .card-deal-title,
    body.dark .detail-value,
    body.dark .recent-action-text,
    body.dark .nav-link,
    body.dark .badge {
        color: var(--text) !important;
    }

    body.dark .text-muted {
        color: var(--muted) !important;
    }

    body.dark .badge.bg-warning,
    body.dark .badge.bg-info {
        color: #212529 !important;
    }

    body.dark .text-success {
        color: #81c784 !important;
    }

    body.dark .text-danger {
        color: #e57373 !important;
    }

    body.dark .btn-outline-secondary {
        color: #e0e0e0;
        border-color: #5a5a7a;
    }

    body.dark .btn-outline-danger {
        color: #e57373;
        border-color: #e57373;
    }

    body.dark .btn-outline-success {
        color: #81c784;
        border-color: #81c784;
    }

    body.dark .dropdown-menu {
        background: var(--card-bg);
        border-color: var(--border);
    }

    body.dark .dropdown-item {
        color: var(--text);
    }

        body.dark .dropdown-item:hover {
            background: var(--bg);
        }

        body.dark .dropdown-item.text-danger {
            color: #e57373 !important;
        }

/* ===========================
   14. Responsive
=========================== */
@media (max-width: 576px) {
    .nav-tabs .nav-link {
        padding: 6px 10px;
        font-size: 13px;
    }
}

/* ===========================
   15. Shop Links
=========================== */
.shop-link {
    color: var(--link);
    text-decoration: none;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

    .shop-link:hover {
        text-decoration: underline;
        color: var(--link);
    }

.shop-link-inline {
    text-decoration: none;
    color: var(--link) !important;
}

    .shop-link-inline:hover {
        text-decoration: underline;
    }

/* ===========================
   16. Deal Notes Preview
=========================== */
.note-items-preview {
    position: relative;
    max-height: 90px;
    overflow: hidden;
}

    .note-items-preview.has-more::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 28px;
        background: linear-gradient(to bottom, transparent, var(--card-bg));
        pointer-events: none;
    }

.note-item-preview {
    font-size: 13px;
    line-height: 1.5;
    padding: 2px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.note-item-checkbox {
    font-size: 14px;
    opacity: 0.7;
}

/* ===========================
   17. Settings Cards
=========================== */
.settings-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    text-decoration: none;
    color: var(--text);
    height: 100%;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

    .settings-card:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 14px rgba(0,0,0,.08);
        color: var(--text);
    }

body.dark .settings-card:hover {
    box-shadow: 0 4px 14px rgba(0,0,0,.4);
}

.settings-icon {
    font-size: 26px;
    flex-shrink: 0;
    width: 42px;
    text-align: center;
}

.settings-body {
    flex-grow: 1;
    min-width: 0;
}

.settings-title {
    font-weight: 600;
    font-size: 14.5px;
    margin-bottom: 2px;
}

.settings-desc {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.3;
}

.settings-arrow {
    color: var(--muted);
    font-size: 22px;
    opacity: 0.5;
    flex-shrink: 0;
}

/* ===========================
   18. Avatar Upload/Delete
=========================== */
.avatar-upload-wrap {
    position: relative;
    display: inline-block;
}

.avatar-upload-btn {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 28px;
    height: 28px;
    background: var(--link);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-size: 14px;
    transition: transform 0.15s;
    margin-bottom: 0;
}

    .avatar-upload-btn:hover {
        transform: scale(1.1);
    }

.avatar-delete-btn {
    position: absolute;
    bottom: -2px;
    left: -2px;
    width: 28px;
    height: 28px;
    background: #dc3545;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    font-size: 13px;
    transition: transform 0.15s;
    margin-bottom: 0;
    border: none;
    padding: 0;
    z-index: 2;
}

    .avatar-delete-btn:hover {
        transform: scale(1.1);
    }

/* ===========================
   19. 3D Edge Shadows
=========================== */
body::before,
body::after {
    content: '';
    position: fixed;
    top: 0;
    bottom: 0;
    width: 20px;
    pointer-events: none;
    z-index: 3000;
}

body::before {
    left: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.1);
}

body::after {
    right: 0;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}

body.dark::before {
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
}

body.dark::after {
    box-shadow: -4px 0 20px rgba(0,0,0,0.5);
}

@media (max-width: 768px) {
    body::before,
    body::after {
        width: 8px;
    }
}

/* ===========================
   20. Profile Page
=========================== */
.profile-field {
    margin-bottom: 16px;
}

.profile-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 4px;
}

.profile-value {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

/* ===========================
   21. Deal Detail Card
=========================== */
.deal-detail-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 18px;
    box-shadow: var(--card-shadow);
}

.deal-status-badge {
    display: inline-block;
    padding: 3px 12px;
    background: rgba(108, 117, 125, 0.10);
    border: 1px solid rgba(108, 117, 125, 0.25);
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.85;
}

.deal-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.deal-detail-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.deal-detail-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
}

.deal-detail-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.deal-detail-money .deal-detail-value {
    font-size: 19px;
    font-weight: 700;
    color: var(--link);
}

.deal-detail-profit {
    grid-column: 1 / -1;
    padding: 12px;
    border-radius: 10px;
    margin-top: 2px;
    text-align: center;
}

    .deal-detail-profit.profit-positive {
        background: linear-gradient(135deg, rgba(25, 135, 84, 0.12), rgba(25, 135, 84, 0.04));
        border: 1px solid rgba(25, 135, 84, 0.2);
    }

    .deal-detail-profit.profit-negative {
        background: linear-gradient(135deg, rgba(220, 53, 69, 0.12), rgba(220, 53, 69, 0.04));
        border: 1px solid rgba(220, 53, 69, 0.2);
    }

.deal-profit-amount {
    font-size: 22px !important;
    font-weight: 700 !important;
}

.profit-positive .deal-profit-amount {
    color: #16a34a !important;
}

.profit-negative .deal-profit-amount {
    color: #dc3545 !important;
}

body.dark .profit-positive .deal-profit-amount {
    color: #81c784 !important;
}

body.dark .profit-negative .deal-profit-amount {
    color: #e57373 !important;
}

.deal-profit-percent {
    font-size: 13px;
    font-weight: 600;
    opacity: 0.8;
}

.profit-positive .deal-profit-percent {
    color: #198754;
}

.profit-negative .deal-profit-percent {
    color: #dc3545;
}

body.dark .profit-positive .deal-profit-percent {
    color: #81c784;
}

body.dark .profit-negative .deal-profit-percent {
    color: #e57373;
}

.deal-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 12px;
    margin-top: 14px;
    border-top: 1px solid var(--border);
}

.deal-actions-buttons {
    display: flex;
    gap: 6px;
}

.deal-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    padding: 0;
}

    .deal-action-btn:hover {
        background: var(--card-bg);
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        transform: translateY(-1px);
    }

/* ===========================
   22. Transaction Cards
=========================== */
.tx-card {
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: transform 0.12s ease;
}

    .tx-card:active {
        transform: scale(0.98);
    }

    .tx-card.expense {
        background: var(--action-expense-bg);
        border-left-color: rgba(220, 53, 69, 0.5);
    }

    .tx-card.income {
        background: var(--action-income-bg);
        border-left-color: rgba(25, 135, 84, 0.5);
    }

.tx-top {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.tx-amount {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    min-width: 86px;
}

.tx-card.expense .tx-amount {
    color: #dc3545;
}

.tx-card.income .tx-amount {
    color: #198754;
}

body.dark .tx-card.expense .tx-amount {
    color: #e57373;
}

body.dark .tx-card.income .tx-amount {
    color: #81c784;
}

.tx-main {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.tx-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tx-side {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.tx-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 11px;
    color: var(--muted);
}

/* Описание — вторая строка, прижато к левому краю */
.tx-sub {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===========================
   23. Group Cards (личные расходы / займы / налоги)
=========================== */
.tx-group-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--card-shadow);
}

.tx-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.tx-group-total {
    flex-shrink: 0;
    white-space: nowrap;
    color: var(--link);
}

.tx-group-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 7px 0;
    cursor: pointer;
}

    .tx-group-row + .tx-group-row {
        border-top: 1px dashed var(--border);
    }

.tx-group-desc {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: var(--text);
}

.tx-group-amount {
    flex-shrink: 0;
    white-space: nowrap;
    font-weight: 600;
    font-size: 14px;
}

.tx-group-card .tx-group-amount {
    color: #dc3545;
}

body.dark .tx-group-card .tx-group-amount {
    color: #e57373;
}

/* ===========================
   24. Transaction Detail Card
=========================== */
.tx-detail-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--card-shadow);
}

.tx-detail-amount {
    font-size: 28px;
    font-weight: 800;
    text-align: center;
    margin-bottom: 6px;
}

    .tx-detail-amount.expense {
        color: #dc3545;
    }

    .tx-detail-amount.income {
        color: #198754;
    }

body.dark .tx-detail-amount.expense {
    color: #e57373;
}

body.dark .tx-detail-amount.income {
    color: #81c784;
}

.tx-detail-desc {
    text-align: center;
    color: var(--muted);
    font-size: 14px;
    margin-bottom: 16px;
    white-space: pre-wrap;
}

.tx-detail-loan-badge {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(13, 110, 253, 0.1);
    border: 1px solid rgba(13, 110, 253, 0.25);
    border-radius: 16px;
    font-size: 12px;
    color: var(--link);
}

.tx-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.tx-detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tx-detail-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.tx-detail-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ===========================
   25. Loan expenses
=========================== */
.tx-card.loan {
    border: 1px solid rgba(13, 110, 253, 0.35);
    box-shadow: var(--card-shadow), 0 0 0 3px rgba(13, 110, 253, 0.08);
}

.tx-loan-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(13, 110, 253, 0.12);
    color: var(--link);
    font-weight: 600;
    white-space: nowrap;
}

/* ===========================
   26. Home Page
=========================== */
.home-greeting-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.home-greeting-date {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

.home-section-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
}

.home-budget-card {
    background: linear-gradient(135deg, #1976d2, #0d6efd);
    border-radius: 16px;
    padding: 18px 20px;
    color: #fff;
    margin-bottom: 10px;
    box-shadow: 0 6px 16px rgba(13, 110, 253, 0.25);
}

body.dark .home-budget-card {
    background: linear-gradient(135deg, #0f3460, #1a1a6e);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.home-budget-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    opacity: 0.85;
    margin-bottom: 4px;
}

.home-budget-value {
    font-size: 28px;
    font-weight: 800;
    line-height: 1.1;
}

.home-stat-card {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 14px 10px;
    text-align: center;
    box-shadow: var(--card-shadow);
    height: 100%;
}

.home-stat-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.home-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.home-stat-profit {
    color: #16a34a;
}

body.dark .home-stat-profit {
    color: #81c784;
}

.home-stat-label {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

/* Последние действия */
.recent-action {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--card-shadow);
    transition: transform 0.12s ease;
}

    .recent-action:active {
        transform: scale(0.98);
    }

.recent-action-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.recent-action-body {
    flex: 1;
    min-width: 0;
}

.recent-action-text {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-action-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
}

/* ===========================
   27. Modal Z-Index & Fixes
=========================== */
.modal {
    z-index: 2500 !important;
}

.modal-backdrop {
    z-index: 2499 !important;
}

/* Скрываем FAB при открытом модальном окне */
.modal.show ~ .fab-btn-wrap,
.modal.show ~ .fab-menu-radial {
    display: none !important;
}

/* Выпадающий список пользователей */
.user-profile-item:hover {
    background: var(--bg) !important;
}

.user-profile-item.selected {
    background: rgba(13, 110, 253, 0.08) !important;
}

    .user-profile-item.selected .check-icon {
        display: block !important;
    }

/* Автодополнение магазинов */
.shop-suggestion-item {
    cursor: pointer;
    font-size: 14px;
    padding: 10px 14px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    width: 100%;
    text-align: left;
}

    .shop-suggestion-item:hover {
        background: var(--bg);
    }

/* ===========================
   28. User Profile Component
=========================== */
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    transition: background 0.15s;
    cursor: pointer;
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    color: var(--text);
    text-decoration: none;
}

    .user-profile:hover {
        background: var(--bg);
        color: var(--text);
    }

.user-profile-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--border);
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.user-profile-info {
    flex: 1;
    min-width: 0;
}

.user-profile-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-profile-role {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-menu .user-profile {
    padding: 8px 12px;
    border-radius: 0;
}

    .dropdown-menu .user-profile:hover {
        background: var(--bg);
    }

.user-profile-compact {
    padding: 6px 10px;
}

    .user-profile-compact .user-profile-avatar {
        width: 32px;
        height: 32px;
    }

    .user-profile-compact .user-profile-name {
        font-size: 13px;
    }

    .user-profile-compact .user-profile-role {
        font-size: 10px;
    }

/* ===========================
   29. Avatar Cropper Customization
=========================== */
#avatarCropModal .cropper-view-box,
#avatarCropModal .cropper-face {
    border-radius: 50%;
}

#avatarCropModal .cropper-view-box {
    outline: 2px solid var(--link);
    outline-color: rgba(13, 110, 253, 0.75);
}

#avatarCropModal .cropper-face {
    background: transparent;
}

#avatarCropModal .cropper-modal {
    background: rgba(0, 0, 0, 0.6);
}

.cropper-circle-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

    .cropper-circle-overlay::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        border-radius: 50%;
        border: 3px dashed rgba(255, 255, 255, 0.5);
        width: var(--circle-size, 80%);
        height: var(--circle-size, 80%);
    }

/* ===========================
   30. Гашение 3D-теней при открытых модалках
=========================== */
body.modal-open::before,
body.modal-open::after {
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* ===========================
   31. Deal Notes Items + List-Group Dark Fix
=========================== */
body.dark .list-group-item {
    background: var(--card-bg);
    border-color: var(--border);
    color: var(--text);
}

.dealnote-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    color: var(--text);
    box-shadow: var(--card-shadow);
}

    .dealnote-item .dealnote-text {
        flex: 1;
        min-width: 0;
        font-size: 14px;
    }

    .dealnote-item.done {
        opacity: 0.55;
    }

        .dealnote-item.done .dealnote-text {
            text-decoration: line-through;
            color: var(--muted);
        }

.dealnote-check {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border: 1.5px solid var(--input-border);
    border-radius: 5px;
    background: transparent;
    color: #fff;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.dealnote-item.done .dealnote-check {
    background: var(--link);
    border-color: var(--link);
}

/* ===========================
   32. Deal Notes Cards (редизайн карточек заметок)
=========================== */
.dealnote-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

    .dealnote-card:active {
        transform: scale(0.98);
    }

.dealnote-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.dealnote-card-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--action-deal-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.dealnote-card-title {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    font-size: 14.5px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dealnote-card-count {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 12px;
    background: var(--action-client-bg);
    color: var(--muted);
    border: 1px solid var(--border);
}

    .dealnote-card-count.done {
        background: rgba(25, 135, 84, 0.12);
        border-color: rgba(25, 135, 84, 0.3);
        color: #198754;
    }

body.dark .dealnote-card-count.done {
    color: #81c784;
}

.dealnote-card-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
    margin-bottom: 10px;
}

.dealnote-card-progress-bar {
    height: 100%;
    background: var(--link);
    border-radius: 2px;
    transition: width 0.3s ease;
}

    .dealnote-card-progress-bar.done {
        background: #198754;
    }

body.dark .dealnote-card-progress-bar.done {
    background: #81c784;
}

/* Превью пунктов */
.note-preview {
    position: relative;
}

.note-preview-item {
    height: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
}

    .note-preview-item.done {
        color: var(--muted);
    }

        .note-preview-item.done .note-preview-text {
            text-decoration: line-through;
        }

.note-preview-check {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    border: 1.5px solid var(--input-border);
    border-radius: 4px;
    font-size: 10px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.note-preview-item.done .note-preview-check {
    background: var(--link);
    border-color: var(--link);
}

.note-preview-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* >= 4 пунктов: три целиком + четвёртый наполовину, с засветом от границы */
.note-preview.has-more {
    height: 110px; /* 3 * 30 + половина четвёртого (15) */
    overflow: hidden;
}

    .note-preview.has-more::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 18px;
        background: linear-gradient(to bottom, transparent, var(--card-bg) 98%);
        box-shadow: 0 8px 10px -4px var(--card-bg);
        pointer-events: none;
    }

/* ===========================
   33. Page Exit Animation (назад / свайпы)
=========================== */
.app-content {
    transition: transform 0.22s ease, opacity 0.22s ease, padding-bottom 0.2s ease-out;
}

body.page-exit-back .app-content {
    transform: translateX(55%);
    opacity: 0;
}