@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #eff4ff;
    --bg-deep: #dbe7ff;
    --ink: #0f1e42;
    --muted: #5a6e99;
    --line: #cfdbf7;
    --line-strong: #bacaf0;

    --primary: #2768f5;
    --primary-700: #1d4ebd;
    --primary-800: #153a90;
    --primary-soft: #eaf1ff;

    --success-soft: #ebf4ff;
    --danger: #cf2f52;
    --danger-soft: #fff1f4;
    --card: #ffffff;

    --radius: 16px;
    --radius-sm: 12px;
    --shadow-soft: 0 10px 30px rgba(20, 45, 110, 0.08);
    --shadow-hover: 0 14px 34px rgba(20, 45, 110, 0.13);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "Manrope", "Trebuchet MS", "Segoe UI", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 8%, #ffffff 0, #edf3ff 36%),
        radial-gradient(circle at 88% 20%, #dce8ff 0, transparent 42%),
        linear-gradient(180deg, var(--bg) 0%, #f7faff 100%);
}

body.modal-open {
    overflow: hidden;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 40;
}

.main-header .brand {
    font-weight: 800;
    letter-spacing: .01em;
    color: var(--primary-800);
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    line-height: 1;
}

.main-header .brand .brand-logo {
    width: 68px;
    height: 68px;
    object-fit: contain;
    border-radius: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
    flex: 0 0 auto;
}

.main-header .brand span {
    display: inline-block;
    transform: translateY(1px);
}

.header-nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-nav a,
.btn-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 700;
    color: var(--primary-700);
    transition: background-color .2s ease, color .2s ease;
}

.header-nav a:hover,
.btn-link:hover {
    background: var(--primary-soft);
    color: var(--primary-800);
}

a {
    color: var(--primary-700);
    text-decoration: none;
}

.hamburger {
    display: none;
    width: 44px;
    height: 44px;
    padding: 8px;
    border-radius: 12px;
    background: var(--primary-soft);
    border: 1px solid var(--line-strong);
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-direction: column;
    box-shadow: 0 4px 10px rgba(39, 104, 245, 0.15);
}

.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--primary-700);
    border-radius: 2px;
    transition: transform .2s ease, opacity .2s ease;
}

.main-header.menu-open .hamburger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.main-header.menu-open .hamburger span:nth-child(2) {
    opacity: 0;
}

.main-header.menu-open .hamburger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.container {
    max-width: 1120px;
    margin: 34px auto;
    padding: 0 16px 34px;
}

.page-head {
    margin-bottom: 14px;
}

h1,
h2 {
    margin-top: 0;
    letter-spacing: -.01em;
}

h1 {
    font-size: clamp(1.4rem, 1.1rem + 1.2vw, 2rem);
}

h2 {
    font-size: clamp(1.06rem, 0.95rem + 0.45vw, 1.32rem);
}

h1 i,
h2 i,
summary i,
button i {
    margin-right: 6px;
}

.muted {
    color: var(--muted);
    text-align: center;
    font-size: 0.8rem;
    margin-top: 0;
}

.card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 5px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.card::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, #7ea8ff 0%, var(--primary) 45%, #6e95ff 100%);
    opacity: 0.9;
}

.card-sm {
    max-width: 520px;
    margin: 56px auto;
}

.flash {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    box-shadow: 0 8px 16px rgba(18, 47, 121, 0.08);
}

.flash.success {
    background: var(--success-soft);
    border-color: #bfd2ff;
    color: var(--primary-800);
}

.flash.error {
    background: var(--danger-soft);
    border-color: #f5c2cf;
    color: #8a1f36;
}

.grid-form {
    display: grid;
    gap: 11px;
}

.inline-grid {
    grid-template-columns: 2fr 1fr 1fr auto;
    align-items: end;
    gap: 12px;
}

.grid-form.compact {
    margin: 10px 0;
}

label {
    font-size: .88rem;
    font-weight: 700;
    color: var(--muted);
}

input,
select,
button {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: .95rem;
    color: var(--ink);
    font-family: inherit;
}

input,
select {
    background: #ffffff;
    box-shadow: inset 0 1px 0 rgba(39, 104, 245, 0.06);
}

input::placeholder {
    color: #8ba0cc;
}

input:focus,
select:focus,
button:focus {
    outline: 2px solid rgba(39, 104, 245, 0.22);
    outline-offset: 1px;
    border-color: var(--primary);
}

button {
    cursor: pointer;
    font-weight: 700;
    transition: transform .16s ease, box-shadow .2s ease, background-color .2s ease;
}

button:hover {
    transform: translateY(-1px);
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #3b7aff 0%, var(--primary) 100%);
    color: #fff;
    border-color: #2b66e6;
    box-shadow: 0 9px 16px rgba(39, 104, 245, 0.3);
}

.card > .btn-primary {
    display: flex;
    margin: 8px auto 0;
}

.btn-primary:hover {
    background: linear-gradient(160deg, #2f70ff 0%, var(--primary-700) 100%);
    box-shadow: 0 12px 20px rgba(39, 104, 245, 0.35);
}

.btn-secondary {
    background: var(--primary-soft);
    color: var(--primary-800);
    border-color: #bfd0ff;
}

.btn-danger {
    background: var(--danger-soft);
    border-color: #f1b8c7;
    color: #9f2240;
}

.btn-link {
    background: transparent;
    border: none;
    padding: 8px 12px;
    color: var(--primary-700);
}

.table-wrap tbody td:first-child .btn-link {
    font-size: 0.86rem;
}

.budget-table {
    table-layout: fixed;
}

.budget-table th:nth-child(1),
.budget-table td:nth-child(1) {
    width: 48%;
}

.budget-table th:nth-child(2),
.budget-table td:nth-child(2) {
    width: 18%;
}

.budget-table th:nth-child(3),
.budget-table td:nth-child(3) {
    width: 34%;
}

.budget-table tbody td:first-child .btn-link {
    width: 100%;
    text-align: left;
    padding: 6px 8px;
    font-size: 0.78rem;
    line-height: 1.2;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    border-radius: var(--radius-sm);
    padding: 14px;
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.stat-card h2 {
    font-size: clamp(0.72rem, 1.8vw, 0.9rem);
    margin-bottom: 8px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-card strong {
    font-size: 1.2rem;
    color: var(--ink);
}

.stat-card.success {
    background: linear-gradient(165deg, #eaf2ff 0%, #f7faff 100%);
}

.stat-card.danger {
    background: linear-gradient(165deg, #fef2f6 0%, #fff8fa 100%);
}

.stat-card.info {
    background: linear-gradient(165deg, #d7f5e3 0%, #ecfff4 100%);
    border-color: #9fdfb8;
    color: #111111;
}

.stat-card.info strong {
    color: #111111;
}

.stat-card.info h2 {
    color: #111111;
}

.stat-card.dark {
    background: linear-gradient(165deg, #dbe8ff 0%, #edf3ff 100%);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
}

.salary-table-wrap {
    overflow-x: auto;
}

.salary-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}

.salary-table th,
.salary-table td {
    white-space: nowrap;
    padding: 9px 8px;
}

.salary-table th:first-child,
.salary-table td:first-child {
    width: 18%;
}

.salary-table tbody td:first-child {
    font-weight: 800;
}

.month-trigger {
    border: 0;
    background: transparent;
    color: var(--primary-800);
    font-weight: 800;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    padding: 0;
    cursor: pointer;
    text-decoration: none;
}

.month-trigger:hover {
    color: var(--primary);
}

.salary-table th:nth-child(2),
.salary-table td:nth-child(2) {
    width: 27%;
}

.salary-table th:nth-child(3),
.salary-table td:nth-child(3) {
    width: 30%;
}

.salary-table th:nth-child(4),
.salary-table td:nth-child(4) {
    width: 25%;
}

.salary-table th:nth-child(n + 2),
.salary-table td:nth-child(n + 2) {
    text-align: center;
}

.fuel-table-wrap {
    overflow-x: auto;
}

.fuel-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}

.fuel-table th,
.fuel-table td {
    white-space: nowrap;
    padding: 9px 8px;
}

.fuel-table th:first-child,
.fuel-table td:first-child {
    width: 22%;
}

.fuel-table tbody td:first-child {
    font-weight: 800;
}

.fuel-date-trigger {
    border: 0;
    background: transparent;
    color: var(--primary-800);
    font-weight: 800;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    padding: 0;
    cursor: pointer;
    text-decoration: none;
}

.fuel-date-trigger:hover {
    color: var(--primary);
}

.fuel-table th:nth-child(2),
.fuel-table td:nth-child(2) {
    width: 20%;
}

.fuel-table th:nth-child(3),
.fuel-table td:nth-child(3) {
    width: 28%;
}

.fuel-table th:nth-child(4),
.fuel-table td:nth-child(4) {
    width: 30%;
}

.fuel-table th:nth-child(n + 2),
.fuel-table td:nth-child(n + 2) {
    text-align: center;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    border-bottom: 1px solid #dde7ff;
    padding: 11px;
    text-align: left;
    vertical-align: top;
}

th:first-child,
td:first-child {
    width: 25%;
}

th:nth-child(3),
td:nth-child(3) {
    width: 10%;
    text-align: center;
}

th:nth-child(2),
td:nth-child(2) {
    width: 10%;
    text-align: center;
}

th {
    color: var(--primary-800);
    background: #f5f9ff;
    font-size: .88rem;
    font-weight: 800;
}

tbody tr:nth-child(even) {
    background: #fbfdff;
}

tbody tr:hover {
    background: #f1f6ff;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: .79rem;
    font-weight: 700;
}

.badge.debit {
    background: #fff0f5;
    color: #9b2440;
}

.badge.credit {
    background: #e7f0ff;
    color: #1c4bb8;
}

details > summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: var(--primary-700);
    margin-bottom: 6px;
}

details > summary::-webkit-details-marker {
    display: none;
}

.row-actions {
    display: inline-flex;
    gap: 8px;
    align-items: flex-start;
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--primary-700);
    padding: 0;
}

.icon-btn i {
    margin-right: 0;
}

.icon-btn.edit-icon {
    background: var(--primary-soft);
    color: var(--primary-800);
    border-color: #bfd0ff;
}

.icon-btn.delete-icon {
    background: var(--danger-soft);
    color: #9f2240;
    border-color: #f1b8c7;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 60;
}

.modal.is-open {
    display: flex;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 20, 40, 0.48);
}

.modal-card {
    position: relative;
    width: min(560px, 100%);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(16, 33, 66, 0.24);
    padding: 16px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.modal-head h3 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--primary-800);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}

.modal-actions-split {
    justify-content: space-between;
    flex-wrap: wrap;
}

.duplicate-source-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.duplicate-source-row select {
    flex: 1;
}

.fuel-chart-wrap {
    width: 100%;
    height: 360px;
    margin-top: 8px;
}

.fuel-chart-title {
    text-align: center;
}

.fuel-chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.fuel-chart-toolbar label {
    color: var(--primary-800);
    font-weight: 700;
    font-size: 0.82rem;
}

.fuel-chart-toolbar select {
    width: auto;
    min-width: 78px;
    font-size: 0.82rem;
    padding: 6px 8px;
}

#fuel-chart-reset {
    min-width: 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.salary-chart-wrap {
    width: 100%;
    height: 360px;
    margin-top: 8px;
}

.salary-chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.salary-chart-toolbar label {
    color: var(--primary-800);
    font-weight: 700;
    font-size: 0.82rem;
}

.salary-chart-toolbar select {
    width: auto;
    min-width: 78px;
    font-size: 0.82rem;
    padding: 6px 8px;
}

#salary-chart-global,
#salary-chart-reset {
    min-width: 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.inline-form {
    display: inline;
}

.align-end {
    display: flex;
    align-items: end;
}

@media (max-width: 980px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(160px, 1fr));
    }

    .inline-grid {
        grid-template-columns: 1fr;
    }

    .align-end {
        align-items: stretch;
    }

    .table-wrap {
        overflow-x: auto;
    }

    table {
        min-width: 640px;
    }

    .budget-table {
        min-width: 100%;
    }

    th,
    td {
        padding: 9px 8px;
        font-size: 0.84rem;
    }

    th {
        font-size: 0.8rem;
    }

    td:nth-child(2),
    td:nth-child(3),
    td:nth-child(4) {
        white-space: nowrap;
    }

    .row-actions {
        gap: 6px;
    }

    .icon-btn {
        width: 30px;
        height: 30px;
        border-radius: 9px;
    }
}

@media (max-width: 560px) {
    .main-header {
        padding: 12px 14px;
    }

    .main-header .brand {
        gap: 6px;
        font-size: 0.98rem;
    }

    .main-header .brand .brand-logo {
        width: 60px;
        height: 60px;
        border-radius: 0;
        padding: 0;
    }

    .hamburger {
        display: inline-flex;
    }

    .header-nav {
        position: absolute;
        top: calc(100% + 8px);
        left: 12px;
        right: 12px;
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        background: #ffffff;
        border: 1px solid var(--line);
        border-radius: 14px;
        padding: 10px;
        box-shadow: var(--shadow-hover);
    }

    .header-nav a,
    .header-nav .btn-link {
        width: 100%;
        text-align: left;
    }

    .header-nav[data-open="true"] {
        display: flex;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(120px, 1fr));
    }

    table {
        min-width: 540px;
    }

    .budget-table {
        min-width: 100%;
    }

    th,
    td {
        padding: 7px 6px;
        font-size: 0.76rem;
    }

    th {
        font-size: 0.72rem;
    }

    .badge {
        padding: 4px 8px;
        font-size: 0.7rem;
    }

    .row-actions {
        gap: 5px;
    }

    .icon-btn {
        width: 28px;
        height: 28px;
        border-radius: 8px;
    }

    .container {
        margin-top: 20px;
    }
}
