/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

body {
    margin: 0 auto;
    background-color: #f8f9fa;
    color: #333;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

/* Контейнер */
.container {
    width: 100%;
    max-width: 1200px;
    background: #fff;
    margin: 0 auto; /* Центрируем */
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.hidden-column {
    display: none;
}


/* Центрирование заголовков */
h1, h2 {
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
}

.history-title {
    text-align: center;
    margin-top: 30px;
    margin-bottom: 15px;
    font-weight: bold;
}

/* Навигация */
nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

nav button {
    padding: 10px 15px;
    min-width: 130px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: 0.3s;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
}

nav button:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.top-user-panel {
    position: absolute;
    top: 14px;
    right: 20px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.top-user-name {
    max-width: 180px;
    overflow: hidden;
    padding: 8px 12px;
    border: 1px solid #d9e1ea;
    border-radius: 999px;
    background: #fff;
    color: #1f2933;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-logout-btn {
    min-height: 34px;
    padding: 8px 14px;
    border: 0;
    border-radius: 999px;
    background: #eef2f6;
    color: #1f2933;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.top-logout-btn:hover {
    background: #dde7f0;
}

/* Фильтры и формы */
form {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

form label {
    font-weight: bold;
}

form input,
form select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

/* Кнопки */
form button {
    background-color: #28a745;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

form button:hover {
    background-color: #218838;
}

form button:active {
    transform: scale(0.98);
}


/* Таблица */
.table-container {
    width: 100%;
    overflow-x: auto; /* Добавляем горизонтальную прокрутку */
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 14px;
}

table th, table td {
    padding: 10px;
    text-align: center;
    border: 1px solid #ddd;
}

table th {
    background-color: #007bff;
    color: white;
}

/* Чередование цветов строк */
table tr:nth-child(even) {
    background-color: #f2f2f2;
}

/* Сообщения об ошибках */
.error-msg {
    display: block;
    color: #d8000c;
    background-color: #f8d7da;
    padding: 10px;
    margin: 10px 0;
    border-left: 5px solid #d8000c;
    font-weight: bold;
    text-align: center;
}

.success-msg {
    color: #008000;
    background-color: #d4edda;
    padding: 10px;
    margin: 10px 0;
    border-left: 5px solid #008000;
    font-weight: bold;
    text-align: center;
}


/* Кнопка редактирования */
.edit-btn {
    background-color: #ffc107;
    color: white;
    padding: 6px 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
    font-size: 14px;
}

.edit-btn:hover {
    background-color: #e0a800;
}

/* Стили для кнопки удаления */
.delete-btn {
    background-color: #dc3545;
    color: white;
    padding: 6px 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
    font-size: 14px;
}

.delete-btn:hover {
    background-color: #c82333;
}

/* Авторизация */
.login-container {
    width: 100%;
    max-width: 400px;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    margin-top: 50px;
}

.login-container h2 {
    margin-bottom: 20px;
}

.login-container form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-container form input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.login-container form button {
    background-color: #28a745;
    padding: 10px;
    font-size: 16px;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

.login-container form button:hover {
    background-color: #218838;
}

/* Адаптивность для мобильных */
@media (max-width: 768px) {
    .container {
        width: 95%;
        padding: 20px;
    }

    nav {
        flex-direction: column;
        align-items: center;
    }

    nav button {
        width: auto;
        max-width: 300px;
    }

    form {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    form input, form select {
        width: 100%;
        min-height: 40px;
    }

    .table-container {
        overflow-x: auto;
        display: block;
        max-width: 100%;
    }

    table {
        font-size: 12px;
    }

    table th, table td {
        padding: 8px;
    }

    .login-container {
        width: 90%;
    }

    .modal-content {
        width: 80%;
        margin-top: 10%;
    }
}

.main-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.main-menu button {
    width: 200px;
    padding: 10px;
    font-size: 16px;
    background-color: #007BFF;
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 5px;
}

.main-menu button:hover {
    background-color: #0056b3;
}

.income { background-color: #d4edda; color: #155724; } /* Зелёный для прихода */
.expense { background-color: #f8d7da; color: #721c24; } /* Красный для расхода */

.modal {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s linear 0.3s, opacity 0.3s ease-in-out;
}
.modal.show {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
}

.modal-content {
    background-color: white;
    padding: 20px;
    margin: 15% auto;
    width: 30%;
    border-radius: 8px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
}

.close {
    float: right;
    font-size: 20px;
    cursor: pointer;
}

.price-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
}

.price-label {
    font-weight: bold;
    font-size: 16px;
    color: #D32F2F; /* Красный цвет */
    min-width: 60px; /* Минимальная ширина */
    display: inline-block;
}

.expense-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 80%;
    margin: 0 auto;
}

/* 🔹 Общий стиль для всех */
.expense-fields {
    display: flex; /* 📌 Гарантируем, что элементы расположены в строку */
    align-items: center; /* 📌 Выравнивание по центру */
    gap: 5px; /* 📌 Расстояние между элементами */
    padding: 6px 10px; /* 📌 Отступы */
    border-radius: 6px; /* 📌 Закругление углов */
    background: transparent; /* 📌 Фон прозрачный */
    width: auto; /* 📌 Адаптивная ширина */
}

.model, .wide-model {
    flex-grow: 2; /* 📌 Делаем поле "Модель" шире */
    min-width: 250px; /* 📌 Минимальная ширина */
    max-width: 500px !important; /* 📌 Увеличиваем максимальную ширину */
    width: 100%; /* 📌 Адаптация к родительскому контейнеру */
}


/* 🔹 Только для expenses.php */
#serial-number-container .expense-fields {
    display: flex;
    gap: 5px;
    padding: 4px 6px;
    border-radius: 4px;
    background: transparent;
}

/* 🔹 Только для expenses_misc.php */
.expenses-misc-container .expense-fields {
    display: grid;
    grid-template-columns: 1.5fr 2fr 1fr 1fr 1fr 1fr 0.5fr;
    border: 1px solid #ddd;
    background: #fff;
}

/* 🔹 Поля ввода */
.expense-fields input {
    height: 36px;
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
    background: #fff;
    max-width: 200px;
    min-width: 150px;
}

.expense-fields input[name*="model"] {
    flex-grow: 2;
    min-width: 250px;
    max-width: 500px;
    width: 100%;
}

.expense-fields input:focus {
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.4);
}

/* 🔹 Кнопки */
.expense-fields button {
    width: 35px;
    height: 35px;
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    cursor: pointer;
}

.expense-fields button.add-btn {
    background-color: #28a745;
}

.expense-fields button.remove {
    background-color: #dc3545;
}

.expense-fields button:hover {
    opacity: 0.8;
}

/* 🔹 Убираем лишние отступы */
#expense-container {
    gap: 6px;
}

#serial-number-container {
    gap: 4px;
}

/* Улучшение общего блока */
.expense-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Кнопка добавления */
.add-button {
    background-color: #28a745;
    border-radius: 6px;
    padding: 8px 15px;
    font-size: 16px;
    cursor: pointer;
}

.add-button:hover {
    background-color: #218838;
}

.expense-summary {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 10px;
}

.expense-table {
    width: 100%;
    max-width: none; /* Убираем ограничение */
    border-collapse: collapse;
    margin-top: 15px;
}

.expense-table th {
    background-color: #007bff;
    color: white;
    padding: 10px;
    text-align: center;
}

.expense-table td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: center;
}

/* Обертка для кнопок действий */
.actions {
    display: flex;
    justify-content: center;
    align-items: center; /* Добавлено */
    gap: 5px;
}

.expense-summary input,
.expense-summary select {
    height: 36px;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}

.expense-footer {
    display: flex;
    align-items: center; /* Выравниваем элементы по центру */
    justify-content: space-between; /* Размещаем элементы по краям */
    margin-top: 15px;
    font-size: 16px;
    font-weight: bold;
    padding: 15px; /* Добавили больше пространства */
    background: #f8f9fa; /* Светлый фон */
    border-radius: 8px;
    gap: 20px; /* 🔹 Добавляет пробел между текстом и кнопкой */
}

.expense-footer p {
    font-size: 18px;
    font-weight: bold;
    margin: 0; /* Убираем лишний отступ */
}

.expense-footer button {
    height: 40px;
    font-size: 16px;
    padding: 5px 20px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

.expense-footer button:hover {
    background: #218838;
}

.stock-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 15px;
}
.stock-info h3 {
    margin: 0;
}

.inventory-info {
    text-align: left;
    width: 100%;
    padding-left: 10px;
}

.dashboard-container {
    width: 100%;
    max-width: none;
    margin: 0 auto;
}

.expense-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 80%;
    margin: 0 auto;
}

.expense-wrapper .expense-fields input {
    height: 36px;
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    text-align: center;
}

.expense-wrapper .expense-fields input:focus {
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.4);
}

.expense-wrapper .expense-fields button {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 6px;
    font-size: 18px;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.expense-wrapper .expense-fields button:hover {
    background-color: #218838;
}

.expense-wrapper .expense-fields button.remove {
    background-color: #dc3545;
}

.expense-wrapper .expense-fields button.remove:hover {
    background-color: #c82333;
}

.expense-wrapper .expense-fields-container {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

.product-form {
    display: flex;
    flex-direction: column;
    gap: 10px; /* Отступ между строками */
}

.form-row {
    display: flex;
    gap: 10px; /* Отступ между элементами */
    justify-content: center; /* Центрирование элементов в строке */
    flex-wrap: wrap; /* Если экран маленький, элементы будут переноситься */
}

.wide-input, .model-input {
    flex-grow: 2; /* Одинаковое расширение */
    max-width: 350px; /* Ограничиваем максимальную ширину */
    min-width: 250px; /* Минимальная ширина для адаптивности */
}


input, select, button {
    padding: 8px;
    font-size: 14px;
}

/* ✅ Ограничиваем стиль только для expenses_misc.php */
.expenses-misc-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* ✅ Только для блока расходов в expenses_misc.php */
.expenses-misc-container .expense-fields {
    display: grid;
    grid-template-columns: 1.5fr 2fr 1fr 1fr 1fr 1fr 0.5fr;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    width: 100%;
    max-width: 1000px;
    transition: 0.2s ease-in-out;
}

/* ✅ Только для кнопок в расходах (прочие) */
.expenses-misc-container .expense-fields button {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 6px;
    font-size: 18px;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.expenses-misc-container .expense-fields button:hover {
    background-color: #218838;
}

.expenses-misc-container .expense-fields button.remove {
    background-color: #dc3545;
}

.expenses-misc-container .expense-fields button.remove:hover {
    background-color: #c82333;
}


/* Conservative visual polish: layout and readability only */
:root {
    --page-bg: #f4f6f8;
    --panel-bg: #ffffff;
    --border: #d9e1ea;
    --text: #1f2933;
    --muted: #5f6c7b;
    --primary: #1769aa;
    --primary-hover: #10517f;
    --success: #218739;
    --success-hover: #17692b;
    --danger: #c92a3a;
    --danger-hover: #a61f2d;
    --warning: #b7791f;
    --row-hover: #eef6ff;
}

body {
    background-color: var(--page-bg);
    color: var(--text);
}

.container,
.login-container,
.modal-content {
    border: 1px solid var(--border);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

h1 {
    margin-bottom: 16px;
    color: var(--text);
}

h2,
h3 {
    color: var(--text);
}

nav {
    align-items: center;
}

nav button,
.main-menu button {
    background-color: var(--primary);
    border-radius: 6px;
    box-shadow: none;
    font-weight: 600;
}

nav button:hover,
.main-menu button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

form input,
form select,
.expense-fields input,
.expense-summary input,
.expense-summary select {
    border-color: var(--border);
    color: var(--text);
}

form input:focus,
form select:focus,
.expense-fields input:focus,
.expense-summary input:focus,
.expense-summary select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.14);
    outline: none;
}

form button,
.add-button,
.expense-footer button,
.expense-fields button.add-btn,
.expense-wrapper .expense-fields button,
.expenses-misc-container .expense-fields button {
    background-color: var(--success);
    border-radius: 6px;
    box-shadow: none;
    font-weight: 600;
}

form button:hover,
.add-button:hover,
.expense-footer button:hover,
.expense-fields button.add-btn:hover,
.expense-wrapper .expense-fields button:hover,
.expenses-misc-container .expense-fields button:hover {
    background-color: var(--success-hover);
}

.edit-btn {
    background-color: var(--warning);
    border-radius: 6px;
    font-weight: 600;
}

.edit-btn:hover {
    background-color: #975a16;
}

.delete-btn,
.expense-wrapper .expense-fields button.remove,
.expenses-misc-container .expense-fields button.remove {
    background-color: var(--danger);
    border-radius: 6px;
    font-weight: 600;
}

.delete-btn:hover,
.expense-wrapper .expense-fields button.remove:hover,
.expenses-misc-container .expense-fields button.remove:hover {
    background-color: var(--danger-hover);
}

.table-container {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-bg);
}

table th,
.expense-table th {
    background-color: var(--primary);
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
}

table td,
.expense-table td {
    color: var(--text);
}

table tbody tr:hover {
    background-color: var(--row-hover);
}

.actions {
    gap: 8px;
    flex-wrap: wrap;
}

.error-msg,
.success-msg {
    border-radius: 6px;
}

.stock-info,
.expense-footer {
    border: 1px solid var(--border);
    background: #f8fafc;
}

@media (max-width: 768px) {
    body {
        padding: 12px;
    }

    nav {
        gap: 8px;
    }

    nav button {
        width: 100%;
        max-width: 320px;
    }

    .top-user-panel {
        position: static;
        justify-content: center;
        margin: 0 auto 12px;
    }

    .actions {
        flex-direction: column;
    }
}

/* Staff UI adaptation: CSS-only, no behavior changes */
html {
    min-width: 320px;
}

body {
    overflow-x: auto;
    line-height: 1.45;
}

.dashboard-container {
    width: 100%;
    padding: 0 6px 24px;
}

.dashboard-container > header,
.dashboard-container > h1,
.dashboard-container > h2,
section > h2,
.history-title {
    margin-top: 12px;
}

.messages-container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto 14px;
}

.error-msg,
.success-msg {
    max-width: 1100px;
    margin: 10px auto;
    line-height: 1.4;
}

nav {
    width: 100%;
    margin: 0 auto 24px;
}

nav button {
    min-height: 42px;
    min-width: 128px;
    padding: 10px 18px;
    line-height: 1.2;
}

form {
    align-items: center;
}

form input,
form select,
input,
select {
    min-height: 42px;
    line-height: 1.2;
}

form input,
form select {
    max-width: 420px;
}

input[type="date"] {
    min-width: 165px;
}

button,
.edit-btn,
.delete-btn,
form button {
    min-height: 36px;
    line-height: 1.2;
}

.product-form,
.filter-form,
.form-container,
.expense-form,
#debt-form,
.operation-section form {
    width: 100%;
}

.form-row,
.expense-summary,
.client-info,
.expense-footer,
.stock-info,
.inventory-info {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.expense-summary,
.client-info,
.expense-footer,
.stock-info {
    padding: 10px;
}

.expense-footer {
    justify-content: center;
    gap: 18px;
}

.inventory-info {
    padding: 10px 12px;
}

table,
.expense-table {
    background: var(--panel-bg);
}

table th,
table td,
.expense-table th,
.expense-table td {
    vertical-align: middle;
}

table td .edit-btn,
table td .delete-btn,
.actions .edit-btn,
.actions .delete-btn {
    margin: 2px;
}

.actions {
    display: flex;
    justify-content: center;
    align-items: center;
}

.wide-input,
.model-input,
.wide-model,
.model {
    min-width: 260px;
}

.expense-fields {
    max-width: 100%;
}

#serial-number-container .expense-fields {
    justify-content: center;
    flex-wrap: wrap;
}

.expenses-misc-container .expense-fields {
    grid-template-columns: minmax(120px, 1.1fr) minmax(220px, 2fr) minmax(90px, 0.8fr) minmax(110px, 0.9fr) minmax(110px, 0.9fr) minmax(110px, 0.9fr) 44px;
}

.expenses-misc-container .expense-fields input {
    width: 100%;
    min-width: 0;
    max-width: none;
}

.login-container {
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 1100px) {
    nav button {
        min-width: 150px;
    }

    .expenses-misc-container .expense-fields {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 760px;
    }

    .expenses-misc-container .expense-fields button {
        justify-self: center;
    }
}

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

    h1 {
        font-size: 30px;
    }

    h2 {
        font-size: 24px;
    }

    form {
        gap: 8px;
    }

    form input,
    form select,
    form button {
        width: 100%;
        max-width: 520px;
    }

    .form-row,
    .expense-summary,
    .client-info,
    .expense-footer,
    .stock-info {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .expense-summary input,
    .expense-summary select,
    .client-info input,
    .client-info select,
    .client-info button,
    .expense-footer button {
        width: 100%;
        max-width: none;
    }

    .wide-input,
    .model-input,
    .wide-model,
    .model {
        min-width: 0;
        max-width: none !important;
    }

    table,
    .expense-table {
        min-width: 760px;
    }
}

@media (max-width: 640px) {
    body {
        padding: 8px;
    }

    h1 {
        font-size: 28px;
    }

    h2 {
        font-size: 22px;
    }

    nav {
        gap: 6px;
    }

    nav button {
        width: 100%;
        max-width: none;
        min-width: 0;
    }

    .dashboard-container {
        padding-left: 0;
        padding-right: 0;
    }

    .expense-fields,
    #serial-number-container .expense-fields {
        width: 100%;
    }

    .expense-fields input,
    #serial-number-container .expense-fields input {
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    .expenses-misc-container .expense-fields {
        grid-template-columns: 1fr;
    }

    .stock-info,
    .inventory-info,
    .expense-footer {
        text-align: center;
    }
}

/* Debt and clients readability pass */
#debt-form {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto 22px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px 12px;
}

#debt-container {
    width: 100%;
    min-width: 0;
}

#debt-form .debt-item {
    display: grid;
    grid-template-columns: minmax(260px, 1.4fr) 92px minmax(140px, 0.8fr) minmax(140px, 0.8fr) 44px;
    gap: 8px;
    align-items: center;
}

#debt-form .debt-item input,
#debt-form .client-info input,
#debt-form .client-info button {
    width: 100%;
    max-width: none;
}

#debt-form .remove-row,
#debt-form .add-row {
    width: 44px;
    min-width: 44px;
    height: 42px;
    padding: 0;
    font-size: 18px;
}

#debt-form .client-info {
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 1fr) 170px minmax(150px, auto);
    gap: 8px;
    padding: 0;
}

a[href^="debts_pay.php"],
a[href^="debts_history.php"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    margin: 2px;
    padding: 6px 10px;
    border-radius: 6px;
    font-weight: 600;
    line-height: 1.15;
    text-decoration: none;
    white-space: nowrap;
}

a[href^="debts_pay.php"] {
    background: var(--success);
    color: #fff;
}

a[href^="debts_pay.php"]:hover {
    background: var(--success-hover);
}

a[href^="debts_history.php"] {
    background: #e8eef5;
    color: var(--primary);
    border: 1px solid var(--border);
}

a[href^="debts_history.php"]:hover {
    background: #dbe7f2;
    color: var(--primary-hover);
}

#add-client form,
#filters form {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
}

#add-client form input,
#filters form input,
#add-client form button,
#filters form button {
    max-width: 260px;
}

.center-text {
    color: var(--text);
    margin-top: -4px;
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: bold;
    text-align: center;
}

.cash-page table tr {
    background-color: transparent !important;
}

.cash-page table tr.income,
.cash-page .income {
    background-color: #d4edda !important;
    color: #155724;
}

.cash-page .operation-section {
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #ccc;
}

table td:first-child {
    text-align: left;
    padding-left: 18px;
}

table th:first-child {
    text-align: left;
    padding-left: 18px;
}

table td:last-child,
table th:last-child {
    text-align: center;
}

@media (max-width: 1100px) {
    #debt-form {
        grid-template-columns: 1fr;
    }

    #debt-form .add-row {
        justify-self: center;
    }

    #debt-form .debt-item,
    #debt-form .client-info {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    #debt-form .debt-item,
    #debt-form .client-info {
        grid-template-columns: 1fr;
    }

    #debt-form .remove-row,
    #debt-form .add-row {
        justify-self: center;
    }

    #add-client form input,
    #filters form input,
    #add-client form button,
    #filters form button {
        max-width: none;
    }
}

/* Visual correction: keep shared styles from changing expense entry layout */
:root {
    --page-bg: #f8f9fa;
    --primary: #007bff;
    --primary-hover: #0056b3;
    --success: #28a745;
    --success-hover: #218838;
    --danger: #dc3545;
    --danger-hover: #c82333;
    --warning: #ffc107;
    --warning-hover: #e0a800;
    --row-hover: #f4f9ff;
}

form input:focus,
form select:focus,
.expense-fields input:focus,
.expense-summary input:focus,
.expense-summary select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.14);
}

.edit-btn {
    background-color: var(--warning);
    color: #fff;
}

.edit-btn:hover {
    background-color: var(--warning-hover);
}

table td:first-child,
table th:first-child {
    text-align: center;
    padding-left: 10px;
}

#add-client form,
#add-client ~ #filters form {
    max-width: 980px;
}

#add-client form input,
#add-client form button,
#add-client ~ #filters form input,
#add-client ~ #filters form button {
    max-width: 260px;
}

section#filters form {
    max-width: 1200px;
}

section#filters form input,
section#filters form button {
    max-width: 420px;
}

section#filters[id="filters"] form {
    margin-left: auto;
    margin-right: auto;
}

#add-expense .form-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto 22px;
    padding: 12px 15px;
    gap: 16px;
}

#add-expense #serial-number-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 8px;
}

#add-expense #serial-number-container .expense-fields {
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 920px;
    gap: 8px;
    padding: 0;
    background: transparent;
    border: 0;
}

#add-expense .expense-fields input {
    height: 42px;
    max-width: none;
}

#add-expense .expense-fields .serial-number {
    flex: 0 1 230px;
    min-width: 180px;
    width: auto;
}

#add-expense .expense-fields .model,
#add-expense .expense-fields .wide-model {
    flex: 1 1 420px;
    min-width: 260px;
    max-width: 520px !important;
    width: auto;
}

#add-expense .expense-fields .price {
    flex: 0 1 180px;
    min-width: 140px;
    width: auto;
}

#add-expense .expense-fields button {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
}

#add-expense .expense-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 930px;
    gap: 12px;
    margin-top: 0;
    padding: 0;
}

#add-expense .expense-summary input,
#add-expense .expense-summary select {
    height: 42px;
    width: auto;
    max-width: none;
}

#add-expense .expense-summary input[type="date"] {
    flex: 0 0 180px;
}

#add-expense .expense-summary input[name="client_phone"],
#add-expense .expense-summary #client_name {
    flex: 0 1 240px;
    min-width: 220px;
}

#add-expense .expense-summary select {
    flex: 0 0 170px;
}

#add-expense .expense-footer {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: auto;
    max-width: none;
    margin-top: 2px;
    padding: 10px 14px;
    gap: 18px;
    border: 0;
    background: #f8f9fa;
    border-radius: 8px;
}

#add-expense .expense-footer p {
    white-space: nowrap;
}

@media (max-width: 900px) {
    #add-expense #serial-number-container .expense-fields,
    #add-expense .expense-summary {
        max-width: 620px;
    }

    #add-expense #serial-number-container .expense-fields {
        flex-wrap: wrap;
    }

    #add-expense .expense-fields .serial-number,
    #add-expense .expense-fields .model,
    #add-expense .expense-fields .wide-model,
    #add-expense .expense-fields .price,
    #add-expense .expense-summary input,
    #add-expense .expense-summary select {
        flex: 1 1 100%;
        width: 100%;
        min-width: 0;
        max-width: none !important;
    }
}

@media (max-width: 640px) {
    #add-expense .form-container {
        padding-left: 8px;
        padding-right: 8px;
    }

    #add-expense .expense-footer {
        width: 100%;
        flex-direction: column;
        gap: 10px;
    }

    #add-expense .expense-footer p,
    #add-expense .expense-footer button {
        width: 100%;
        max-width: 520px;
        text-align: center;
    }
}

/* Mobile correction: compact menu and contained table scrolling */
@media (max-width: 640px) {
    body {
        align-items: stretch;
        overflow-x: hidden;
        padding: 6px;
    }

    .dashboard-container,
    .expenses-misc-container,
    .container {
        width: 100%;
        max-width: 100%;
        padding-left: 8px;
        padding-right: 8px;
        overflow-x: hidden;
    }

    h1 {
        font-size: 26px;
        margin: 10px 0 14px;
    }

    h2 {
        font-size: 22px;
        margin: 18px 0 12px;
    }

    nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        max-width: 620px;
        gap: 7px;
        margin: 0 auto 20px;
        padding: 0;
    }

    nav button {
        width: 100%;
        max-width: none;
        min-width: 0;
        min-height: 42px;
        padding: 9px 6px;
        font-size: 15px;
    }

    form {
        width: 100%;
        max-width: 620px;
        margin-left: auto;
        margin-right: auto;
    }

    form input,
    form select,
    form button {
        min-height: 44px;
        font-size: 16px;
    }

    table,
    .expense-table {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        border-collapse: separate;
        border-spacing: 0;
        -webkit-overflow-scrolling: touch;
    }

    table thead,
    table tbody,
    .expense-table thead,
    .expense-table tbody {
        display: table;
        width: 100%;
        min-width: 720px;
    }

    table tr,
    .expense-table tr {
        display: table-row;
    }

    table th,
    table td,
    .expense-table th,
    .expense-table td {
        padding: 10px 8px;
        font-size: 14px;
        white-space: normal;
    }

    .stock-info,
    .inventory-info {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        max-width: 620px;
        margin: 8px auto 16px;
        padding: 8px 10px;
        gap: 6px;
        border: 0;
        background: transparent;
        text-align: center;
    }

    .stock-info h3,
    .inventory-info h3 {
        width: 100%;
        margin: 0;
        font-size: 18px;
        line-height: 1.3;
    }

    .stock-info button,
    .inventory-info button {
        min-height: 38px;
        padding: 8px 14px;
        border: 1px solid var(--border);
        border-radius: 5px;
        background: #fff;
        color: var(--text);
        cursor: pointer;
    }
}

/* Desktop correction: keep product filters centered and wide enough */
@media (min-width: 641px) {
    .dashboard-container {
        margin-left: auto;
        margin-right: auto;
        padding-left: 28px;
        padding-right: 28px;
    }

    .dashboard-container > h3 {
        width: 100%;
        max-width: 720px;
        margin: 2px auto;
        text-align: center;
    }

    #toggle-prices {
        display: block;
        margin: 10px auto 18px;
    }
}

/* Filter layout correction: each page has a different filter form */
@media (min-width: 641px) {
    section#filters form[action="dashboard.php"],
    section#filters form[action="stock.php"],
    section#filters form[action="clients.php"] {
        margin-left: auto;
        margin-right: auto;
    }

    section#filters form[action="dashboard.php"] {
        display: grid;
        grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr) minmax(180px, 1.2fr) 160px 12px 160px minmax(160px, 1fr) 190px;
        width: 100%;
        max-width: 1500px;
        gap: 10px;
        align-items: center;
    }

    section#filters form[action="stock.php"] {
        display: grid;
        grid-template-columns: minmax(150px, 1fr) minmax(170px, 1fr) minmax(170px, 1fr) 165px 12px 165px minmax(165px, 1fr) minmax(165px, 1fr) 190px;
        width: 100%;
        max-width: 1700px;
        gap: 10px;
        align-items: center;
    }

    #add-client ~ section#filters form[action="clients.php"],
    section#filters form[action="clients.php"] {
        display: flex;
        width: 100%;
        max-width: 760px;
        gap: 10px;
        justify-content: center;
    }

    section#filters form[action="dashboard.php"] > *,
    section#filters form[action="stock.php"] > *,
    #add-client ~ section#filters form[action="clients.php"] > *,
    section#filters form[action="clients.php"] > * {
        width: 100%;
        max-width: none;
        min-width: 0;
    }

    section#filters form[action="dashboard.php"] > span,
    section#filters form[action="stock.php"] > span {
        width: auto;
        text-align: center;
        font-weight: 600;
    }

    section#filters form[action="dashboard.php"] button,
    section#filters form[action="stock.php"] button,
    #add-client ~ section#filters form[action="clients.php"] button,
    section#filters form[action="clients.php"] button {
        white-space: nowrap;
    }

    section#filters form[action="dashboard.php"] button,
    section#filters form[action="stock.php"] button {
        min-width: 0;
    }
}

@media (min-width: 641px) and (max-width: 1500px) {
    section#filters form[action="stock.php"] {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        max-width: 1100px;
    }

    section#filters form[action="stock.php"] > span {
        display: none;
    }

    section#filters form[action="stock.php"] button {
        grid-column: 2 / 4;
    }
}

@media (min-width: 641px) and (max-width: 1200px) {
    section#filters form[action="dashboard.php"] {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        max-width: 900px;
    }

    section#filters form[action="dashboard.php"] > span {
        display: none;
    }

    section#filters form[action="dashboard.php"] button {
        grid-column: 2 / 3;
    }
}

/* Unified controls and dense table polish */
:root {
    --control-height: 40px;
    --action-height: 34px;
    --control-radius: 6px;
}

button,
.edit-btn,
.delete-btn,
.back-btn,
.back-button,
a[href^="debts_pay.php"],
a[href^="debts_history.php"] {
    border-radius: var(--control-radius);
    font-weight: 600;
    line-height: 1.15;
    cursor: pointer;
}

form button,
.add-button,
.btn-success {
    min-height: var(--control-height);
    padding: 8px 16px;
    font-size: 15px;
}

table th,
table td,
.expense-table th,
.expense-table td {
    padding: 8px 10px;
    line-height: 1.25;
}

table td .edit-btn,
table td .delete-btn,
.actions .edit-btn,
.actions .delete-btn,
a[href^="debts_pay.php"],
a[href^="debts_history.php"] {
    min-height: var(--action-height);
    padding: 7px 12px;
    font-size: 14px;
    white-space: nowrap;
}

table td .edit-btn,
.actions .edit-btn {
    min-width: 128px;
}

table td .delete-btn,
.actions .delete-btn {
    min-width: 82px;
}

td .edit-btn + .delete-btn,
.actions .edit-btn + .delete-btn {
    margin-left: 6px;
}

.back-btn,
.back-button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: var(--control-height) !important;
    padding: 8px 18px !important;
    border: 1px solid var(--border) !important;
    background: #e8eef5 !important;
    color: var(--primary) !important;
    text-decoration: none !important;
}

.back-btn:hover,
.back-button:hover {
    background: #dbe7f2 !important;
    color: var(--primary-hover) !important;
}

#toggle-prices {
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--control-radius);
    background: #ffffff;
    color: var(--text);
    font-weight: 600;
}

#toggle-prices:hover {
    background: #eef6ff;
    color: var(--primary-hover);
}

.login-container form button {
    width: 100%;
    max-width: 220px;
    min-height: 44px;
    align-self: center;
    border-radius: 8px;
    font-size: 17px;
}

.inventory-info {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto 18px;
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    border: 0;
    background: transparent;
    text-align: left;
}

.inventory-info h3 {
    margin: 0;
    font-size: 18px;
    line-height: 1.35;
}

.inventory-info #toggle-prices {
    align-self: flex-start;
    margin: 8px 0 0;
}

.expenses-misc-container {
    gap: 10px;
}

.expenses-misc-container h2 {
    margin: 16px 0 10px;
}

.expenses-misc-container .expense-form {
    width: 100%;
    max-width: 1220px;
    gap: 12px;
    margin-bottom: 16px;
}

.expenses-misc-container .expense-wrapper {
    width: 100%;
    max-width: 1220px;
}

.expenses-misc-container .expense-summary {
    margin-top: 6px;
}

.expenses-misc-container .expense-footer {
    margin-top: 8px;
}

#filter-form {
    width: 100%;
    max-width: 1760px;
    gap: 10px;
}

@media (max-width: 640px) {
    table td .edit-btn,
    table td .delete-btn,
    .actions .edit-btn,
    .actions .delete-btn,
    a[href^="debts_pay.php"],
    a[href^="debts_history.php"] {
        min-width: 0;
        padding: 7px 10px;
    }

    .inventory-info {
        align-items: center;
        text-align: center;
    }

    .inventory-info #toggle-prices {
        align-self: center;
        margin: 8px 0 0;
    }
}

/* Desktop consistency pass: forms, table actions and dense rows */
@media (min-width: 641px) {
    form input,
    form select {
        min-height: 40px;
        padding: 8px 12px;
        border-radius: var(--control-radius);
        font-size: 15px;
    }

    section#filters form,
    section#filter-expenses form,
    #filter-form {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 10px 12px;
        margin-left: auto;
        margin-right: auto;
    }

    #add-client form,
    section#filters form[action="clients.php"] {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 10px 12px;
    }

    #add-client form input,
    section#filters form[action="clients.php"] input {
        flex: 0 1 250px;
        width: 250px;
        max-width: 250px;
    }

    #add-client form button,
    section#filters form[action="clients.php"] button {
        width: auto;
        min-width: 118px;
        max-width: none;
        flex: 0 0 auto;
    }

    #filter-expenses form input,
    #filter-expenses form select,
    #filter-form input,
    #filter-form select {
        flex: 0 1 210px;
        max-width: 260px;
    }

    #filter-expenses form button,
    #filter-form button {
        flex: 0 0 auto;
        min-width: 190px;
        max-width: none;
    }

    table th,
    table td,
    .expense-table th,
    .expense-table td {
        padding: 7px 9px;
        font-size: 15px;
        line-height: 1.22;
    }

    table td .edit-btn,
    table td .delete-btn,
    .actions .edit-btn,
    .actions .delete-btn,
    a[href^="debts_pay.php"],
    a[href^="debts_history.php"] {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 32px;
        padding: 6px 10px;
        font-size: 14px;
    }

    table td .edit-btn,
    .actions .edit-btn {
        min-width: 118px;
    }

    table td .delete-btn,
    .actions .delete-btn {
        min-width: 76px;
    }

    a[href^="debts_pay.php"] {
        min-width: 82px;
    }

    a[href^="debts_history.php"] {
        min-width: 78px;
    }

    .back-btn,
    .back-button {
        min-height: 38px !important;
        padding: 8px 16px !important;
    }

    .expenses-misc-container .expense-form {
        gap: 10px;
        margin-bottom: 14px;
    }

    .expenses-misc-container .expense-summary {
        gap: 10px;
        margin-top: 4px;
    }

    .expenses-misc-container .expense-footer {
        gap: 14px;
        padding: 8px 12px;
    }
}

/* Active navigation state */
nav button.nav-active,
nav button[aria-current="page"],
.nav-more-summary.nav-active {
    background-color: #0056b3;
    box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.55);
    transform: none;
}

nav button.nav-active:hover,
nav button[aria-current="page"]:hover,
.nav-more-summary.nav-active:hover {
    background-color: #004a99;
    transform: none;
}

.nav-more {
    position: relative;
    display: inline-flex;
}

.nav-more-summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    min-width: 150px;
    padding: 10px 18px;
    border: none;
    border-radius: 5px;
    background-color: #007bff;
    color: #fff;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    list-style: none;
    transition: 0.3s;
}

.nav-more-summary::-webkit-details-marker {
    display: none;
}

.nav-more-summary::after {
    content: "▾";
    margin-left: 8px;
    font-size: 13px;
}

.nav-more-summary:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

.nav-more-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    z-index: 30;
    display: flex;
    min-width: 210px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
    flex-direction: column;
    gap: 8px;
    transform: translateX(-50%);
}

.nav-more:not([open]) .nav-more-menu {
    display: none;
}

.nav-more-menu button {
    width: 100%;
    min-width: 0;
}

@media (max-width: 700px) {
    .nav-more,
    .nav-more-summary {
        width: 100%;
    }

    .nav-more-menu {
        position: static;
        width: 100%;
        margin-top: 6px;
        transform: none;
    }
}

/* Section dividers: clearer separation between add/filter/list blocks */
body:not(.cash-page) .dashboard-container section + section,
.unified-page section + section {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 2px solid #d0d6dd;
}

.expenses-misc-container {
    margin-bottom: 28px;
    padding-bottom: 22px;
    border-bottom: 2px solid #d0d6dd;
}

#filter-form + h2 {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 2px solid #d0d6dd;
}

/* Usability helpers: messages, filters, sticky table headers and copy hints */
.messages-container {
    width: 100%;
    max-width: 980px;
    margin: 0 auto 16px;
}

.success-msg,
.error-msg,
.info-msg,
.warning-msg {
    display: block;
    width: 100%;
    max-width: 980px;
    margin: 10px auto;
    padding: 11px 14px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
}

.success-msg {
    background: #e8f7ee;
    border-color: #bfe8cc;
    color: #17692b;
}

.error-msg {
    background: #fdecef;
    border-color: #f4c2c9;
    color: #a61f2d;
}

.info-msg {
    background: #eef6ff;
    border-color: #c9e4ff;
    color: #0056b3;
}

.warning-msg {
    background: #fff7df;
    border-color: #ffe39c;
    color: #8a5a00;
}

.reset-filter-btn {
    min-height: var(--control-height);
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--control-radius);
    background: #eef2f6;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.reset-filter-btn:hover {
    background: #dde7f0;
}

table thead th,
.expense-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

.sale-type-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.15;
    white-space: nowrap;
}

.sale-type-cash,
.sale-type-income {
    background: #dff7e7;
    color: #17692b;
}

.sale-type-card {
    background: #eaf2ff;
    color: #0056b3;
}

.sale-type-transfer {
    background: #f0edff;
    color: #5541a3;
}

.sale-type-debt {
    background: #fff2c2;
    color: #7a5200;
}

.sale-type-expense {
    background: #fdecef;
    color: #a61f2d;
}

.copyable-cell {
    cursor: copy;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.copyable-cell:hover {
    background: #eef6ff;
}

.ui-toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 9999;
    max-width: min(420px, calc(100vw - 36px));
    padding: 10px 14px;
    border-radius: 8px;
    background: #1f2933;
    color: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    font-weight: 600;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.ui-toast.show {
    opacity: 1;
    transform: translateY(0);
}

.ui-toast-error {
    background: #a61f2d;
}

button:disabled,
input[type="submit"]:disabled {
    cursor: wait;
    opacity: 0.72;
}

.ui-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.36);
}

.ui-confirm-overlay.show {
    display: flex;
}

.ui-confirm-box {
    width: min(420px, 100%);
    padding: 22px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.24);
    text-align: center;
}

.ui-confirm-box h3 {
    margin: 0 0 10px;
    font-size: 22px;
}

.ui-confirm-message {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.4;
}

.ui-confirm-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.ui-confirm-actions button {
    min-width: 130px;
    min-height: 40px;
    border-radius: var(--control-radius);
    border: 0;
    font-weight: 700;
}

.ui-confirm-cancel {
    background: #e8eef5;
    color: var(--text);
}

.ui-confirm-cancel:hover {
    background: #dbe7f2;
}

.ui-confirm-ok {
    background: var(--danger);
    color: #fff;
}

.ui-confirm-ok:hover {
    background: var(--danger-hover);
}

/* Quick return to top */
.scroll-top-btn {
    position: fixed;
    right: 18px;
    bottom: 22px;
    z-index: 80;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
}

.scroll-top-btn.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-top-btn:hover {
    background: var(--primary-hover);
}

/* Stock page: two-line filter layout */
@media (min-width: 641px) {
    section#filters form.stock-filter-form {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        max-width: 1500px;
        gap: 12px;
    }

    .stock-filter-form .filter-row {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        gap: 10px 12px;
    }

    .stock-filter-form .filter-row-primary {
        max-width: 1450px;
    }

    .stock-filter-form .filter-row-primary input {
        max-width: none;
    }

    .stock-filter-form .filter-row-primary input[name="sap_code"] {
        flex: 0 1 280px;
    }

    .stock-filter-form .filter-row-primary input[name="serial_number"] {
        flex: 0 1 280px;
    }

    .stock-filter-form .filter-row-primary .suggest-field {
        flex: 0 1 280px;
        max-width: none;
    }

    .stock-filter-form .filter-row-primary input[name="model"] {
        flex: 1.55 1 460px;
    }

    .stock-filter-form .filter-row-primary .stock-filter-actions {
        display: flex;
        gap: 10px;
        flex: 0 0 auto;
    }

    .stock-filter-form .filter-row-primary .stock-filter-actions button {
        min-width: 150px;
        max-width: none;
    }

    .stock-filter-form .filter-row-secondary {
        max-width: 1080px;
    }

    .stock-filter-form .filter-row-secondary input,
    .stock-filter-form .filter-row-secondary select {
        flex: 0 1 190px;
        max-width: none;
    }

    .stock-filter-form .filter-row-secondary span {
        flex: 0 0 auto;
        width: auto;
        font-weight: 600;
    }

}

@media (max-width: 900px) {
    .stock-filter-form .filter-row {
        flex-wrap: wrap;
    }

    .stock-filter-form .filter-row > * {
        flex: 1 1 220px;
    }
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.empty-row {
    padding: 18px !important;
    color: var(--muted);
    font-weight: 600;
    text-align: center !important;
}

.action-form {
    display: inline-flex;
    margin: 0 3px;
}

.cash-page td.cash-actions {
    width: 240px;
    min-width: 240px;
    white-space: nowrap;
}

.cash-page .table-actions {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.cash-page .table-actions .action-form {
    margin: 0;
}

body.debt-history-page,
body.debt-pay-page {
    display: block;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    background: var(--page-bg);
    color: var(--text);
}

.debt-history-page h2,
.debt-pay-page h2 {
    text-align: center;
}

.debt-history-page table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.debt-history-page .payment {
    background-color: #d4f3dd;
}

.debt-pay-page form {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background-color: var(--panel-bg);
}

.debt-pay-page label {
    display: block;
    margin: 10px 0 5px;
    font-weight: 700;
}

.debt-pay-page input,
.debt-pay-page select,
.debt-pay-page button {
    width: 100%;
    margin-bottom: 10px;
}

.debt-pay-page .back-btn,
.debt-history-page .back-btn {
    display: flex !important;
    width: fit-content;
    margin: 20px auto;
}

/* Expenses table: keep row actions compact */
@media (min-width: 641px) {
    .expense-table td.actions {
        display: table-cell;
        width: 230px;
        min-width: 230px;
        white-space: nowrap;
    }

    .expense-table td.actions .edit-btn,
    .expense-table td.actions .delete-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 32px;
        margin: 0 3px;
        padding: 6px 10px;
        vertical-align: middle;
    }

    .expense-table td.actions .edit-btn {
        min-width: 116px;
    }

    .expense-table td.actions .delete-btn {
        min-width: 76px;
    }
}

@media (max-width: 640px) {
    .scroll-top-btn {
        right: 12px;
        bottom: 14px;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }
}

/* Unified sale page */
.unified-page {
    max-width: 1920px;
}

#unified-message[hidden] {
    display: none !important;
}

#unified-message {
    white-space: pre-line;
}

.unified-page section {
    margin: 24px auto;
}

.unified-page h2 {
    margin-bottom: 14px;
}

.unified-product-form,
.unified-summary-fields {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.unified-product-form {
    max-width: 1500px;
    margin-left: auto;
    margin-right: auto;
}

.unified-field {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    margin: 0;
}

.unified-field span {
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}

.unified-product-form input,
.unified-summary-fields input,
.unified-summary-fields select {
    width: 100%;
    max-width: none;
}

#unified-model-search {
    min-width: 0;
}

.unified-field-model {
    flex: 1 1 680px;
    max-width: 820px;
}

.unified-field-qty {
    flex: 0 1 130px;
}

.unified-field-money {
    flex: 0 1 180px;
}

.unified-field-stock {
    flex: 0 1 150px;
}

.unified-field-action {
    flex: 0 0 auto;
}

.unified-product-form button {
    min-width: 170px;
}

#unified-buy-btn,
#serial-confirm-btn {
    min-height: var(--control-height);
    padding: 8px 18px;
    border: 0;
    border-radius: var(--control-radius);
    background: var(--success);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
}

#unified-buy-btn:hover,
#serial-confirm-btn:hover {
    background: var(--success-hover);
}

#unified-buy-btn:disabled {
    cursor: not-allowed;
    background: #9ca3af;
    opacity: 0.65;
}

#unified-buy-btn:disabled:hover {
    background: #9ca3af;
}

.unified-cart-table {
    margin-top: 10px;
}

.unified-cart-table th,
.unified-cart-table td {
    padding: 7px 8px;
}

.unified-cart-heading {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.unified-cart-heading h2 {
    grid-column: 2;
    margin: 0;
}

.unified-cart-toolbar {
    grid-column: 3;
    justify-self: end;
    display: flex;
    justify-content: flex-end;
    margin: 0;
}

.unified-cart-table td.actions {
    white-space: nowrap;
}

.unified-type-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 22px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.unified-type-incoming {
    background: #e8f2ff;
    color: #0759b3;
}

.unified-type-misc {
    background: #eef7ed;
    color: #1b6b31;
}

.unified-cart-table input {
    width: 100%;
    min-height: 30px;
    padding: 4px 7px;
    border: 1px solid var(--border);
    border-radius: var(--control-radius);
    background: #fff;
    font-size: 14px;
    text-align: center;
}

.unified-cart-table input.cart-input-error {
    border-color: var(--danger);
    background: #fff5f5;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.12);
}

.cart-row-error {
    display: block;
    margin-top: 4px;
    color: var(--danger);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
}

.cart-row-error[hidden] {
    display: none;
}

.cart-quantity-input {
    max-width: 90px;
}

.cart-price-input {
    max-width: 150px;
}

.unified-cart-remove {
    min-width: 76px;
    min-height: 30px;
    padding: 5px 10px;
    border: 0;
    border-radius: var(--control-radius);
    background: var(--danger);
    color: #fff;
    font-weight: 700;
}

.unified-cart-remove:hover {
    background: var(--danger-hover);
}

.unified-recent-section {
    max-width: 100%;
}

.unified-recent-filter {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin: 12px auto 8px;
    max-width: 1500px;
}

.unified-recent-filter input,
.unified-recent-filter select {
    flex: 1 1 170px;
    max-width: 230px;
}

.unified-recent-filter .suggest-field {
    flex: 1 1 170px;
    max-width: 230px;
}

.unified-recent-filter .suggest-field:has(input[name="recent_model"]) {
    flex: 1.6 1 280px;
    max-width: 380px;
}

.unified-recent-filter .suggest-field input {
    width: 100%;
    max-width: none;
}

.unified-recent-filter-actions {
    display: inline-flex;
    align-items: stretch;
    justify-content: center;
    gap: 10px;
    flex: 0 1 auto;
}

.unified-recent-filter button,
.unified-recent-reset {
    min-height: 42px;
}

.unified-recent-reset {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.unified-recent-note {
    margin: 4px 0 10px;
    color: var(--muted-text);
    font-size: 14px;
    text-align: center;
}

.unified-recent-pagination {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 0 auto 12px;
}

.unified-recent-table {
    margin-top: 10px;
    font-size: 14px;
}

.unified-recent-table th,
.unified-recent-table td {
    padding: 7px 8px;
}

.unified-recent-table td.actions {
    white-space: nowrap;
}

.unified-recent-table .delete-btn {
    min-height: 30px;
    padding: 5px 10px;
}

.unified-recent-table .client-history-link {
    color: #0b70d8;
    font-weight: 700;
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}

.unified-recent-table .client-history-link:hover {
    color: #0759ad;
}

.unified-summary {
    max-width: 1180px;
}

.unified-summary-fields input,
.unified-summary-fields select {
    width: 100%;
}

.unified-summary-fields .unified-field {
    flex: 1 1 220px;
}

.unified-field-sale-type {
    flex: 0 1 170px;
}

.unified-client-status {
    width: fit-content;
    max-width: 100%;
    margin: 10px auto 0;
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 700;
}

.unified-client-status.ok {
    background: #e8f7ee;
    color: #17692b;
}

.unified-client-status.error {
    background: #fdecef;
    color: #a61f2d;
}

.unified-total-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    width: fit-content;
    max-width: 100%;
    margin: 22px auto 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-bg);
}

.unified-total-box strong {
    font-size: 20px;
}

.unified-modal {
    position: fixed;
    inset: 0;
    z-index: 9997;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.38);
}

.unified-modal[hidden] {
    display: none;
}

.unified-modal-box {
    width: min(760px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    padding: 22px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.24);
    text-align: center;
}

.unified-modal-box h3 {
    margin: 0 0 8px;
    font-size: 24px;
}

.unified-modal-box p {
    margin: 0 0 16px;
    color: var(--muted);
}

.unified-success-box {
    width: min(620px, 100%);
}

.sale-success-details {
    margin: 14px auto 0;
    padding: 14px;
    border: 1px solid #bfe8cc;
    border-radius: 8px;
    background: #f4fbf6;
    color: #17692b;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.55;
    text-align: left;
    white-space: pre-line;
}

.serial-group {
    margin: 14px 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--page-bg);
}

.serial-group h4 {
    margin: 0 0 10px;
}

.serial-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
}

.serial-row input {
    flex: 1 1 auto;
    max-width: none;
}

.serial-status {
    flex: 0 0 170px;
    color: var(--muted);
    font-weight: 700;
    text-align: left;
}

.serial-ok {
    border-color: var(--success) !important;
    background: #f4fbf6;
}

.serial-error {
    border-color: var(--danger) !important;
    background: #fff6f7;
}

.unified-modal-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
}

@media (max-width: 700px) {
    .unified-product-form,
    .unified-summary-fields,
    .unified-total-box,
    .unified-cart-heading,
    .serial-row,
    .unified-modal-actions {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .unified-cart-heading h2,
    .unified-cart-toolbar {
        grid-column: auto;
        justify-self: center;
    }

    .unified-cart-toolbar {
        justify-content: center;
    }

    #unified-model-search,
    #unified-quantity,
    #unified-price,
    #unified-line-total,
    #unified-stock,
    .unified-product-form button,
    .unified-summary-fields input,
    .unified-summary-fields select {
        flex: 1 1 auto;
        width: 100%;
        max-width: none;
    }

    .serial-status {
        flex: 1 1 auto;
        text-align: center;
    }
}

/* Product/client cards and profit report */
.report-panel {
    max-width: 1180px;
    margin: 24px auto 28px;
    text-align: center;
}

.card-search-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.card-search-form input,
.card-search-form select {
    min-width: 220px;
}

.card-search-form input[name="q"] {
    flex: 1 1 440px;
    max-width: 720px;
}

.suggest-field {
    position: relative;
    display: inline-flex;
    max-width: none;
}

.suggest-field input {
    width: 100%;
    max-width: none;
}

.card-search-form .suggest-field {
    flex: 1 1 440px;
    max-width: 720px;
}

.field-suggest-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 60;
    max-height: 300px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.16);
    text-align: left;
}

.field-suggest-option {
    display: block;
    width: 100%;
    min-height: 36px;
    margin: 0;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    box-shadow: none;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
}

.field-suggest-option:hover,
.field-suggest-option:focus {
    background: #eaf3ff;
    color: #075da7;
    outline: none;
    transform: none;
}

.ui-autocomplete {
    z-index: 10000;
    max-height: 260px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-family: inherit;
    font-size: 14px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 12px;
    width: min(1180px, 100%);
    margin: 20px auto 28px;
}

.cash-summary-grid {
    grid-template-columns: repeat(5, minmax(160px, 1fr));
}

.clients-report-main-summary {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    margin-bottom: 12px;
}

.clients-report-payment-summary {
    margin-top: 0;
}

.report-note {
    width: min(1180px, 100%);
    margin: -4px auto 10px;
    text-align: center;
    font-weight: 600;
}

.summary-card {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    text-align: center;
}

.summary-card span,
.summary-card small,
.muted-text {
    color: var(--muted);
}

.summary-card strong {
    display: block;
    margin: 6px 0;
    color: var(--text);
    font-size: 20px;
}

.report-table {
    margin-bottom: 28px;
}

.two-column-section {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 22px;
    width: min(1500px, 100%);
    margin: 0 auto;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 74px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
}

.status-available,
.status-stock {
    background: #eaf3ff;
    color: #075da7;
}

.status-sold {
    background: #fff1d6;
    color: #8a5a00;
}

.status-misc {
    background: #eaf7ed;
    color: #17692b;
}

.profit-positive {
    color: #17692b;
    font-weight: 700;
}

.profit-negative {
    color: var(--danger);
    font-weight: 700;
}

td.actions {
    white-space: nowrap;
}

td.actions a,
td.actions button {
    margin: 2px 3px;
}

@media (max-width: 900px) {
    .summary-grid,
    .two-column-section {
        grid-template-columns: 1fr;
    }
}
