/* === Общие стили === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f4f6f9;
    color: #2c3e50;
    line-height: 1.6;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #ffffff;
    padding: 30px 35px;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s ease;
}

.container:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

/* === Заголовки и навигация === */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

h1 {
    font-size: 2rem;
    font-weight: 600;
    color: #1e293b;
    letter-spacing: -0.5px;
}

nav {
    display: flex;
    align-items: center;
    gap: 15px;
}

nav a {
    color: #3b82f6;
    text-decoration: none;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    transition: background 0.2s, color 0.2s;
}

nav a:hover {
    background: #eef2ff;
    color: #1e40af;
}

nav a.active {
    background: #10b981;
    color: #fff !important;
    border-radius: 8px;
    font-weight: 600;
}

.logout-btn {
    background: #fee2e2;
    color: #b91c1c !important;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 500;
}

.logout-btn:hover {
    background: #fecaca !important;
}

/* === Кнопки и фильтры === */
.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-btn {
    display: inline-block;
    padding: 8px 20px;
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    font-weight: 500;
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.filter-btn.active {
    background: #3b82f6 !important;
    color: #fff !important;
    border-color: #3b82f6 !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.filter-btn:hover:not(.active) {
    background: #e2e8f0;
}

.filter-btn:disabled {
    opacity: 0.7;
    cursor: default;
}

.add-btn {
    display: inline-flex;
    align-items: center;
    background: #10b981;
    color: #fff;
    padding: 10px 22px;
    text-decoration: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s, transform 0.1s;
    margin: 15px 0;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.add-btn:hover {
    background: #059669;
    transform: translateY(-1px);
}

.add-btn.top {
    margin-top: 0;
}

.add-btn.bottom {
    margin-bottom: 0;
}

/* === Таблицы === */
.clients-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.03);
    border: 1px solid #e2e8f0;
}

.clients-table thead th {
    background: #f8fafc;
    color: #334155;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 16px;
    border-bottom: 2px solid #cbd5e1;
    border-right: 1px solid #e2e8f0;
    text-align: center;
    white-space: nowrap;
}

.clients-table thead th:last-child {
    border-right: none;
}

.clients-table thead th a {
    color: #334155;
    text-decoration: none;
    transition: color 0.2s;
    display: block;
    text-align: center;
}

.clients-table thead th a:hover {
    color: #1e293b;
}

.clients-table tbody td {
    padding: 8px 16px;
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    color: #334155;
    font-size: 0.95rem;
}

.clients-table tbody td:last-child {
    border-right: none;
}

.clients-table tbody tr:last-child td {
    border-bottom: none;
}

.clients-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

.clients-table tbody tr:hover {
    background: #f1f5f9;
}

/* Неоплаченные строки */
tr.unpaid {
    background-color: #fff0f0 !important;
}

/* Цветовые индикаторы сальдо */
.clients-table tbody tr.balance-positive {
    background-color: #e0f7fa !important;
}
.clients-table tbody tr.balance-zero {
    background-color: #e8f5e9 !important;
}
.clients-table tbody tr.balance-negative {
    background-color: #ffebee !important;
}

.clients-table tbody tr.balance-positive:hover {
    background-color: #b2ebf2 !important;
}
.clients-table tbody tr.balance-zero:hover {
    background-color: #c8e6c9 !important;
}
.clients-table tbody tr.balance-negative:hover {
    background-color: #ffcdd2 !important;
}

/* Кнопки действий в таблицах (иконки-эмодзи) */
.edit-btn,
.delete-btn,
.pdf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 1.1rem;
    text-decoration: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
    margin: 0 2px;
}

.edit-btn {
    background: #2563eb;
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.edit-btn:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.delete-btn {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #ff7d7d;
}
.delete-btn:hover {
    background: #fecaca;
    transform: translateY(-1px);
}

.pdf-btn {
    background: #10b981;
    color: #ffffff;
}
.pdf-btn:hover {
    background: #059669;
    transform: translateY(-1px);
}

/* === Формы === */
.login-box {
    max-width: 400px;
    margin: 80px auto;
    background: #fff;
    padding: 35px 30px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
}

.login-box h2 {
    margin-bottom: 25px;
    font-size: 1.8rem;
    color: #1e293b;
    text-align: center;
}

.login-box label,
.add-form label {
    display: block;
    margin-bottom: 16px;
    font-weight: 500;
    color: #475569;
}

.login-box input[type="text"],
.login-box input[type="password"],
.add-form input[type="text"],
.add-form input[type="number"],
.add-form select {
    width: 100%;
    padding: 10px 14px;
    margin-top: 6px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    font-size: 0.95rem;
    transition: border 0.2s, box-shadow 0.2s;
    background: #fafafa;
}

.add-form input:focus,
.add-form select:focus,
.login-box input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background: #fff;
}

.add-form button,
.login-box button {
    padding: 11px 24px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    width: 100%;
    margin-top: 10px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.add-form button:hover,
.login-box button:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.radio-group {
    display: flex;
    gap: 25px;
    margin-bottom: 20px;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
    cursor: pointer;
}

/* === Сообщения === */
.success {
    background: #dcfce7;
    color: #166534;
    padding: 12px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-weight: 500;
    border-left: 4px solid #22c55e;
}

.error {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-weight: 500;
    border-left: 4px solid #ef4444;
}

.error-box {
    background: #fee2e2;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    color: #991b1b;
}

.error-box p {
    margin-bottom: 5px;
}

/* === Вспомогательные элементы === */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 25px;
    color: #64748b;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s;
}

.back-link:hover {
    color: #1e293b;
}

small {
    display: block;
    color: #64748b;
    margin-top: 4px;
    font-size: 0.85rem;
}

/* === Сводка сальдо === */
.balance-summary {
    display: flex;
    gap: 30px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}

.balance-debt,
.balance-advance {
    flex: 1;
    min-width: 250px;
    padding: 15px 20px;
    border-radius: 12px;
}

.balance-debt {
    background: #fff5f5;
    border: 1px solid #fecaca;
}

.balance-advance {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.balance-debt h3,
.balance-advance h3 {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
}

/* Общая сумма */
.balance-debt .total,
.balance-advance .total {
    font-weight: bold;
    margin: 5px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}

/* Таблицы внутри сводки */
.summary-table {
    width: 100%;
    border-collapse: collapse;
}

.summary-table tr {
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.summary-table td {
    padding: 6px 0;
    font-size: 0.95rem;
}

.summary-table td.amount {
    text-align: right;
    font-weight: 500;
    white-space: nowrap;
}

/* Чередование строк */
.summary-table tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.4);
}

/* Сброс старых стилей для списков (на случай, если где-то остались) */
.balance-debt ul,
.balance-advance ul,
.balance-debt li,
.balance-advance li {
    list-style: none;
    padding: 0;
    margin: 0;
}


/* Заголовок строки с общей суммой */
.summary-header td {
    font-weight: bold;
    font-size: 1.1rem;
    padding: 6px 0;
}

/* Красный текст для суммы долгов */
.balance-debt .summary-header .amount {
    color: #dc2626;
    font-size: 1.5rem;
}

/* Зелёный текст для суммы авансов */
.balance-advance .summary-header .amount {
    color: #16a34a;
    font-size: 1.5rem;
}


/* === Адаптивность для мобильных === */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    .clients-table thead {
        display: none;
    }
    .clients-table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 12px;
    }
    .clients-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #475569;
        margin-right: 10px;
    }
}

/* Компактные таблицы – общий стиль */
.clients-table {
    font-size: 0.9rem;
}
.clients-table tbody td,
.clients-table thead th {
    padding: 6px 10px;
}
.clients-table tbody td {
    word-wrap: break-word;
}

/* Числовые и короткие столбцы: не переносить, минимальная ширина */
.clients-table th:not(:first-child):not(:nth-child(2)):not(:nth-child(3)),
.clients-table td:not(:first-child):not(:nth-child(2)):not(:nth-child(3)) {
    white-space: nowrap;
    width: 1%;
}

/* Столбец с кнопками */
.clients-table th:last-child,
.clients-table td:last-child {
    width: 100px;
    white-space: nowrap;
    padding: 6px 8px;
}

/* Первый столбец (№ п/п) */
.clients-table th:first-child,
.clients-table td:first-child {
    width: 1%;
    white-space: nowrap;
}

/* Блок выбора времени */
/* Сброс стилей формы для кнопок времени */
.time-picker-block .hour-btn,
.time-picker-block .minute-btn,
.time-picker-block .plus-one-btn {
    width: auto !important;
    display: inline-block !important;
    margin: 0 !important;
    padding: 4px 10px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #334155;
    transition: all 0.2s;
    font-family: inherit;
    min-width: auto;
    text-align: center;
    box-shadow: none;
}

.time-picker-block .hour-btn.active,
.time-picker-block .minute-btn.active {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
    box-shadow: 0 2px 5px rgba(59, 130, 246, 0.3);
}

.time-picker-block .plus-one-btn {
    background: #3b82f6;
    color: #fff;
    border: none;
}
.time-picker-block .plus-one-btn:hover {
    background: #2563eb;
}

.time-picker-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    align-items: center;
}

.time-picker-label {
    font-weight: 500;
    margin-right: 8px;
    color: #475569;
    font-size: 0.9rem;
}

.time-picker-block {
    margin-top: 6px;
}

.final-amount-highlight {
    font-weight: bold;
    color: #10b981;
    background: #eff6ff;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 1.1em;
}

.clients-table tbody td small {
    font-size: 0.85rem;
    color: #64748b;
}