*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f5f7fa;
    color: #222;
    margin: 0;
    padding: 20px;
    max-width: 100%;
    overflow-x: hidden;
}

[hidden] {
    display: none !important;
}

h2, h3 {
    color: #333;
}

.card-container,
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    align-items: stretch;
    width: 100%;
}

.card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-width: 0;
    width: 100%;
}

.card strong {
    display: block;
    font-size: 18px;
    margin-bottom: 5px;
}

.financial-summary-grid,
.financial-period-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
    gap: 24px;
    align-items: start;
    margin-top: 20px;
    width: 100%;
}

.financial-period {
    min-width: 0;
}

.dashboard-project-card {
    color: inherit;
    text-decoration: none;
}

.dashboard-project-card:hover {
    border-color: #007bff;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.checkbox-label input {
    width: auto;
}

.dashboard-logo {
    display: block;
    max-width: 260px;
    width: 100%;
    height: auto;
    margin: 0 auto 12px;
}

.celebration-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    overflow: hidden;
}

.celebration-balloon {
    position: absolute;
    bottom: -90px;
    width: 38px;
    height: 50px;
    border-radius: 50% 50% 45% 45%;
    animation: floatBalloon 3s ease-out forwards;
}

.celebration-balloon::after {
    content: "";
    position: absolute;
    left: 18px;
    top: 48px;
    width: 1px;
    height: 48px;
    background: rgba(255, 255, 255, 0.8);
}

.celebration-confetti {
    position: absolute;
    top: -20px;
    width: 9px;
    height: 14px;
    animation: fallConfetti 3s linear forwards;
}

.celebration-firework {
    position: absolute;
    width: 12px;
    height: 12px;
    border: 3px solid;
    border-radius: 50%;
    opacity: 0;
    animation: burstFirework 1.25s ease-out forwards;
}

.celebration-firework::before,
.celebration-firework::after {
    content: "";
    position: absolute;
    inset: -24px;
    border: 2px dotted currentColor;
    border-radius: 50%;
}

.celebration-firework::after {
    transform: rotate(45deg);
}

@keyframes floatBalloon {
    0% {
        transform: translateY(0) rotate(-4deg);
        opacity: 0;
    }
    12% {
        opacity: 1;
    }
    100% {
        transform: translateY(-115vh) rotate(8deg);
        opacity: 0;
    }
}

@keyframes burstFirework {
    0% {
        transform: scale(0);
        opacity: 0;
        box-shadow:
            0 0 0 currentColor,
            0 0 0 currentColor,
            0 0 0 currentColor,
            0 0 0 currentColor;
    }
    20% {
        opacity: 1;
    }
    100% {
        transform: scale(2.8);
        opacity: 0;
        box-shadow:
            0 -28px 0 currentColor,
            28px 0 0 currentColor,
            0 28px 0 currentColor,
            -28px 0 0 currentColor;
    }
}

@keyframes fallConfetti {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(105vh) rotate(720deg);
        opacity: 0;
    }
}

.nav,
.button-row,
.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 20px;
}

.dashboard-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
}

.dashboard-account-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    margin-top: 0;
}

.ikea-primary-actions {
    gap: 16px;
}

.ikea-action-group {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.ikea-settings-form {
    margin-top: 24px;
}

.ikea-settings-form hr {
    width: 100%;
    margin: 10px 0 2px;
    border: 0;
    border-top: 1px solid #d1d5db;
}

.nav a {
    text-decoration: none;
    color: #007bff;
}

.nav a:hover {
    text-decoration: underline;
}

table {
    background: white;
    border-collapse: collapse;
    width: 100%;
    margin-top: 10px;
}

th {
    background: #f0f0f0;
}

th, td {
    padding: 10px;
    text-align: left;
    vertical-align: top;
}

.calendar-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.calendar-range-form {
    margin-bottom: 12px;
}

.schedule-calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(130px, 1fr));
    min-width: 910px;
    background: white;
    border: 1px solid #d9dde3;
    border-radius: 8px;
    overflow: hidden;
}

.calendar-weekday {
    background: #f0f0f0;
    font-weight: bold;
    text-align: center;
    padding: 10px;
    border-right: 1px solid #d9dde3;
    border-bottom: 1px solid #d9dde3;
}

.calendar-day {
    min-height: 130px;
    padding: 8px;
    border-right: 1px solid #d9dde3;
    border-bottom: 1px solid #d9dde3;
    background: white;
}

.calendar-day-muted {
    background: #f8f9fb;
}

.calendar-day-today {
    box-shadow: inset 0 0 0 2px #007bff;
}

.calendar-day-number {
    font-weight: bold;
    margin-bottom: 8px;
}

.calendar-projects {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calendar-project {
    display: block;
    padding: 6px;
    border-radius: 6px;
    background: #eaf3ff;
    color: #0b4f9c;
    text-decoration: none;
    line-height: 1.25;
}

.calendar-project strong,
.calendar-project span {
    display: block;
}

.calendar-project span {
    font-size: 12px;
    color: #475569;
}

button, a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #EAAA1B !important;
    color: #000000 !important;
    padding: 6px 12px;
    border-radius: 8px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    font-weight: bold;
    line-height: 1.2;
    min-height: 44px;
    max-width: 100%;
    white-space: normal;
    text-align: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

button:hover, a.button:hover {
    background: #EAAA1B !important;
    color: #000000 !important;
    text-decoration: none;
}

a.button.button-red {
    background: #a83232 !important;
    color: #ffffff !important;
}

a.button.button-red:hover {
    background: #8f2828 !important;
    color: #ffffff !important;
}

a.button.button-green {
    background: #22c55e !important;
    color: #000000 !important;
}

a.button.button-green:hover {
    background: #16a34a !important;
    color: #000000 !important;
}

.setup-list-groups {
    display: grid;
    gap: 14px;
    margin: 10px 0 22px;
}

.setup-list-group {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px;
}

.setup-list-group h4 {
    margin: 0 0 10px;
    color: #111827;
}

.setup-list-group .button {
    box-shadow: none;
}

.setup-list-contacts .button {
    background: #b7dce0 !important;
}

.setup-list-payments .button {
    background: #bde1c0 !important;
}

.setup-list-projects .button {
    background: #ead28e !important;
}

.setup-list-vehicles .button {
    background: #c3cedb !important;
}

.setup-list-payments .setup-list-warning-button {
    background: #f3b6b6 !important;
}

.section-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #22c55e;
    color: #000000;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: bold;
    line-height: 1.2;
    min-height: 44px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

button[style*="#a83232"],
button[style*="red"],
button[style*="background: red"],
button[style*="background-color: red"],
button[style*="background:#a83232"],
button[style*="background-color:#a83232"] {
    background: #a83232 !important;
    color: #ffffff !important;
    min-height: auto;
    padding: 4px 8px;
    border-radius: 6px;
    box-shadow: none;
}

button[style*="#a83232"]:hover,
button[style*="red"]:hover,
button[style*="background: red"]:hover,
button[style*="background-color: red"]:hover,
button[style*="background:#a83232"]:hover,
button[style*="background-color:#a83232"]:hover {
    background: #8f2828 !important;
    color: #ffffff !important;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 520px;
    width: 100%;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    width: 100%;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    max-width: 100%;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
    width: auto;
    min-width: 180px;
    max-width: 100%;
}

.inline-form button {
    min-height: auto;
    padding: 4px 10px;
    border-radius: 6px;
    box-shadow: none;
}

.project-list-card {
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 8px;
    background: white;
    border: 1px solid #ddd;
}

.assignment-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.92rem;
}

.assignment-checkbox input {
    width: auto;
}

.assignment-entry-card {
    max-width: 560px;
}

.assignment-total-field strong {
    min-height: 36px;
    display: flex;
    align-items: center;
    font-size: 1.05rem;
}

.assignment-entry-card .form-stack {
    max-width: 100%;
}

.create-section-card {
    width: 100%;
}

.create-section-card h3:first-child {
    margin-top: 0;
}

.assignment-detail-card {
    margin-top: 10px;
    max-width: 560px;
}

.assignment-preview-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: visible;
}

.assignment-preview-table {
    width: 100%;
    min-width: 0 !important;
    table-layout: fixed;
}

.assignment-preview-table th,
.assignment-preview-table td {
    overflow-wrap: anywhere;
    word-break: normal;
    vertical-align: top;
}

.assignment-preview-table button {
    min-height: auto;
    padding: 6px 10px;
    white-space: normal;
}

.task-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;
    justify-content: flex-end;
    margin-left: auto;
}

.task-assign-form {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    max-width: none;
}

.task-assign-label {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 6px 10px;
    border-radius: 6px;
    background: #d1d5db;
    font-weight: bold;
    color: #000000;
    white-space: nowrap;
}

.task-assign-form select {
    width: auto;
    min-width: 170px;
}

.task-assign-form textarea {
    width: 180px;
    min-height: 44px;
    resize: vertical;
}

.task-assign-form-inline {
    display: inline-flex;
    margin-top: 8px;
    margin-right: 8px;
    vertical-align: middle;
}

.task-note {
    margin-top: 8px;
    padding: 8px;
    border-left: 3px solid #EAAA1B;
    background: #fff7ed;
    color: #222;
    white-space: pre-wrap;
}

.task-note-form {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    max-width: 520px;
}

.task-note-form label {
    font-weight: bold;
}

.task-note-form textarea {
    width: 100%;
    min-height: 86px;
    resize: vertical;
}

.task-note-form button {
    justify-self: start;
}

.duplicate-warning {
    background: #fff3cd;
    border: 1px solid #ffe69c;
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
}

.soft-note {
    background: #eef6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    color: #1e3a8a;
    padding: 12px;
    margin-top: 12px;
}

.duplicate-client-option {
    display: block;
    margin-top: 8px;
}

input,
select,
textarea {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    max-width: 100%;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 5px;
    color: white;
}

.status-active {
    background-color: green;
}

.status-completed {
    background-color: gray;
}

.status-canceled {
    background-color: red;
}

.status-on-hold {
    background-color: #EAAA1B;
}

.profit-positive {
    color: green;
}

.profit-negative {
    color: red;
}

.pie-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.chart-card-row {
    width: 100%;
}

.financial-breakdown-card {
    align-items: center;
}

.pie-chart {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--chart-background, conic-gradient(
        #007bff 0 var(--payroll-percent),
        #ffc107 var(--payroll-percent) var(--expenses-end),
        #7c3aed var(--expenses-end) var(--business-expense-end),
        var(--result-color) var(--business-expense-end) 100%
    ));
    border: 1px solid #ddd;
}

.pie-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 12px;
    font-size: 14px;
    width: 100%;
}

.pie-legend span {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    text-align: center;
}

.whole-project-percent {
    font-size: 0.86rem;
    font-weight: 600;
}

.pie-legend .legend-label {
    flex-direction: row;
    justify-content: center;
}

.pie-legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.legend-payroll {
    background: #007bff;
}

.legend-expenses {
    background: #ffc107;
}

.legend-business-expense {
    background: #7c3aed;
}

.legend-result {
    background: var(--result-color);
}

.legend-regular-income {
    background: #0f766e;
}

.legend-ikea-income {
    background: #84cc16;
}

.legend-regular-labor {
    background: #2563eb;
}

.legend-ikea-labor {
    background: #38bdf8;
}

.legend-regular-expenses {
    background: #f59e0b;
}

.legend-ikea-expenses {
    background: #ef4444;
}

.dark-mode body {
    background-color: #111827;
    color: #e5e7eb;
}

.dark-mode h2,
.dark-mode h3 {
    color: #f9fafb;
}

.dark-mode .card,
.dark-mode table {
    background: #1f2937;
    color: #e5e7eb;
}

.dark-mode .card {
    box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.dark-mode th {
    background: #374151;
}

.dark-mode .schedule-calendar {
    background: #1f2937;
    border-color: #4b5563;
}

.dark-mode .calendar-weekday {
    background: #374151;
    border-color: #4b5563;
}

.dark-mode .calendar-day {
    background: #1f2937;
    border-color: #4b5563;
}

.dark-mode .calendar-day-muted {
    background: #111827;
}

.dark-mode .calendar-project {
    background: #1d4ed8;
    color: #f9fafb;
}

.dark-mode .calendar-project span {
    color: #dbeafe;
}

.dark-mode input,
.dark-mode select,
.dark-mode textarea {
    background: #111827;
    color: #f9fafb;
    border: 1px solid #4b5563;
}

.dark-mode a {
    color: #93c5fd;
}

.dark-mode .pie-chart {
    border-color: #4b5563;
}

.dark-mode .project-list-card {
    background: #1f2937;
    border-color: #4b5563;
}

.dark-mode .setup-list-group {
    background: #1f2937;
    border-color: #4b5563;
}

.dark-mode .setup-list-group h4 {
    color: #f9fafb;
}

.dark-mode .setup-list-contacts .button {
    background: #86c5cc !important;
}

.dark-mode .setup-list-payments .button {
    background: #98d19d !important;
}

.dark-mode .setup-list-projects .button {
    background: #dfc06f !important;
}

.dark-mode .setup-list-vehicles .button {
    background: #aebccc !important;
}

.dark-mode .setup-list-payments .setup-list-warning-button {
    background: #e6a4a4 !important;
}

.dark-mode .duplicate-warning {
    background: #3b2f12;
    border-color: #8a6d1d;
}

.dark-mode .soft-note {
    background: #172554;
    border-color: #2563eb;
    color: #dbeafe;
}

.dark-mode .section-label {
    background: #22c55e;
    color: #000000;
}

.table-wrapper,
.responsive-table {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrapper table,
.responsive-table table {
    min-width: 640px;
}

/* Mobile responsiveness */
@media (max-width: 768px) {

    body {
        padding: 10px;
    }

    .card-container,
    .card-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .card {
        width: 100%;
    }

    table {
        font-size: 14px;
    }

    th, td {
        padding: 6px;
    }

    .nav,
    .button-row,
    .action-row {
        gap: 8px;
    }

    .nav a.button,
    .button-row a.button,
    .action-row a.button,
    .nav button,
    .button-row button,
    .action-row button {
        flex: 1 1 180px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    .nav,
    .button-row,
    .action-row {
        align-items: stretch;
        flex-direction: column;
    }

    .nav a.button,
    .button-row a.button,
    .action-row a.button,
    .nav button,
    .button-row button,
    .action-row button,
    input,
    select,
    textarea {
        width: 100%;
    }

    input[type="checkbox"],
    input[type="radio"] {
        width: auto;
    }

    .nav a.button,
    .button-row a.button,
    .action-row a.button,
    .nav button,
    .button-row button,
    .action-row button {
        flex: 0 0 auto;
    }
}

/* Pagination */
.pagination-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
    margin: 16px 0;
}

.pagination-actions {
    margin: 0;
}

.button-disabled {
    opacity: 0.55;
    pointer-events: none;
}

@media print {
    body {
        background: white;
        color: #222;
        padding: 0;
    }

    body > *:not(.print-calendar-section) {
        display: none;
    }

    .print-calendar-section {
        display: block;
    }

    .calendar-range-form,
    .nav {
        display: none;
    }

    .calendar-wrapper {
        overflow: visible;
    }

    .schedule-calendar {
        min-width: 0;
        width: 100%;
        border-radius: 0;
        box-shadow: none;
        page-break-inside: avoid;
    }

    .calendar-weekday {
        padding: 6px;
    }

    .calendar-day {
        min-height: 96px;
        padding: 5px;
    }

    .calendar-project {
        background: white;
        color: #222;
        border: 1px solid #d9dde3;
        padding: 4px;
    }

    .calendar-project span {
        color: #444;
    }
}
