* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

header {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 1rem 0;
    margin-bottom: 2rem;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.main-nav {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    text-decoration: none;
    color: #666;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover {
    background: #f0f0ff;
    color: #667eea;
}

.nav-link.active {
    background: #667eea;
    color: white;
}

header h1 {
    font-size: 1.8rem;
    color: #667eea;
}

.version {
    font-size: 0.875rem;
    color: #666;
    background: #f5f5f5;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

main {
    padding-bottom: 3rem;
}

.header-section {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-section h2 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.5rem;
}

.search-bar {
    margin-top: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
}

.counterparties-table {
    width: 100%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-collapse: collapse;
}

.counterparties-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.counterparties-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    letter-spacing: 0.5px;
}

.counterparties-table td {
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
}

.counterparties-table tbody tr:hover {
    background: #f8f9ff;
    transition: background 0.2s;
}

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

.invoice-btn {
    font-size: 1.5rem;
    text-decoration: none;
    transition: transform 0.2s;
    display: inline-block;
}

.invoice-btn:hover {
    transform: scale(1.2);
}

.no-link {
    color: #ccc;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.pagination-btn {
    padding: 0.5rem 1rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.3s;
    font-weight: 500;
}

.pagination-btn:hover:not(:disabled) {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.pagination-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.5;
}

.pagination-info {
    font-size: 0.875rem;
    color: #666;
    font-weight: 500;
}

.loading {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.empty-state {
    background: white;
    padding: 3rem;
    text-align: center;
    border-radius: 12px;
    color: #666;
    font-size: 1.125rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

footer {
    background: rgba(255, 255, 255, 0.95);
    padding: 1.5rem 0;
    margin-top: 3rem;
    text-align: center;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

footer p {
    color: #666;
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    .counterparties-table {
        font-size: 0.875rem;
    }

    .counterparties-table th,
    .counterparties-table td {
        padding: 0.75rem 0.5rem;
    }

    .pagination {
        flex-wrap: wrap;
    }

    header h1 {
        font-size: 1.5rem;
    }
}

/* Invoice status badges */
.status-paid {
    background: #d4edda;
    color: #155724;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-unpaid {
    background: #ffe0b2;
    color: #e65100;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-written-off {
    background: #fff9c4;
    color: #f57f17;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-draft {
    background: #e1f5fe;
    color: #0277bd;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-void {
    background: #f8d7da;
    color: #721c24;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-unknown {
    background: #e2e3e5;
    color: #383d41;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Invoice page specific styles */
.header-with-back {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.back-btn {
    color: #667eea;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.3s;
}

.back-btn:hover {
    color: #5568d3;
    text-decoration: underline;
}

.error-state {
    background: #f8d7da;
    color: #721c24;
    padding: 1.5rem;
    text-align: center;
    border-radius: 12px;
    border: 1px solid #f5c6cb;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Bank Entities page */
.be-table {
    width: 100%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-collapse: collapse;
}

.be-table thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.be-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

.be-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.875rem;
}

.be-table tbody tr:hover {
    background: #f8f9ff;
}

.be-table tbody tr.inactive {
    opacity: 0.5;
}

.be-table.compact th,
.be-table.compact td {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

.be-table code {
    background: #f5f5f5;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.muted {
    color: #ccc;
}

.not-linked {
    font-style: italic;
    font-size: 0.8rem;
}

.cp-link {
    color: #667eea;
    font-weight: 500;
}

.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.comment-cell {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.resolution-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
}

.rt-direct { background: #d4edda; color: #155724; }
.rt-alias { background: #e1f5fe; color: #0277bd; }
.rt-intermediary { background: #fff3e0; color: #e65100; }
.rt-internal_transfer { background: #f3e5f5; color: #6a1b9a; }

.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.primary-btn {
    background: #667eea;
    color: white;
}

.primary-btn:hover:not(:disabled) {
    background: #5568d3;
}

.secondary-btn {
    background: #f0f0f0;
    color: #333;
}

.secondary-btn:hover:not(:disabled) {
    background: #e0e0e0;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.info-banner {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.info-banner.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.info-banner.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.close-banner {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    padding: 0 0.25rem;
}

.close-banner:hover {
    opacity: 1;
}

.candidates-panel {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    max-height: 500px;
    overflow-y: auto;
}

.candidates-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.candidates-header h3 {
    font-size: 1.1rem;
    color: #333;
}

.candidates-section {
    margin-bottom: 1.5rem;
}

.candidates-section h4 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.accounts-badge {
    display: inline-block;
    background: #e1f5fe;
    color: #0277bd;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.accounts-badge:hover {
    background: #b3e5fc;
}

.accounts-row td {
    padding: 0 !important;
    border-bottom: 2px solid #667eea !important;
}

.accounts-detail {
    padding: 0.5rem 1rem 0.5rem 3rem;
    background: #fafbff;
}

.accounts-subtable {
    width: auto;
    border-collapse: collapse;
}

.accounts-subtable td {
    padding: 0.25rem 0.75rem !important;
    border: none !important;
    font-size: 0.8rem;
}

.accounts-subtable code {
    background: #f0f0f0;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.75rem;
}

.loading-small {
    font-size: 0.8rem;
    color: #999;
    padding: 0.25rem 0;
}

.filters-row {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.filter-search {
    flex: 1;
}

.filter-select {
    padding: 0.75rem 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    min-width: 160px;
}

.filter-select:focus {
    outline: none;
    border-color: #667eea;
}

/* Менеджер-фильтр + крестик сброса — компактная связка */
.manager-filter {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.manager-filter .clear-filter {
    font-size: 1.4rem;
    line-height: 1;
    padding: 0 0.4rem;
}

.filter-label {
    font-size: 1rem;
    font-weight: 400;
    color: #666;
}

.clear-filter {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #999;
    margin-left: 0.25rem;
}

.clear-filter:hover {
    color: #333;
}

.reload-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.15rem 0.4rem;
    color: #667eea;
    transition: all 0.2s;
}

.reload-btn:hover:not(:disabled) {
    background: #f0f0ff;
    border-color: #667eea;
}

.reload-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.row-unpaid {
    background: #fff8f0 !important;
}

.row-unpaid:hover {
    background: #fff3e0 !important;
}

.row-writeoff {
    background: #fafafa !important;
    color: #888;
}
.row-writeoff:hover { background: #f3f3f3 !important; }

.row-ignored {
    background: #f6f6f6 !important;
    color: #888;
}
.row-ignored:hover { background: #ececec !important; }

/* 5-tab bar above the invoice table */
.tab-bar {
    display: flex;
    gap: 0.25rem;
    margin: 0.75rem 0 0;
    border-bottom: 1px solid #e0e0e0;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #555;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: #222; }

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-count {
    background: #e9ecef;
    color: #495057;
    padding: 0.05rem 0.45rem;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
}

.tab-btn.active .tab-count {
    background: #667eea;
    color: white;
}

.filters-row-secondary {
    margin-top: 0.5rem;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.filter-label-sm {
    font-size: 0.8rem;
    color: #666;
    white-space: nowrap;
}

.filter-date {
    padding: 0.5rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.85rem;
    width: 140px;
}

.filter-number {
    padding: 0.5rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.85rem;
    width: 100px;
}

.filter-date:focus,
.filter-number:focus {
    outline: none;
    border-color: #667eea;
}

.filter-sep {
    color: #999;
    font-size: 0.8rem;
}

.sortable {
    cursor: pointer;
    user-select: none;
}

.sortable:hover {
    background: rgba(255,255,255,0.15);
}

.parse-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.parse-ok { background: #d4edda; color: #155724; }
.parse-partial { background: #fff3cd; color: #856404; }
.parse-failed { background: #f8d7da; color: #721c24; }
.parse-pending { background: #e9ecef; color: #495057; }

.row-failed { background: #fff5f5 !important; }
.row-partial { background: #fffbea !important; }

.source-chip {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    margin: 0 0.15rem 0.15rem 0;
    background: #eef2ff;
    color: #4338ca;
    border-radius: 4px;
    font-size: 0.7rem;
    font-family: monospace;
}

.invoice-link {
    color: #333;
    text-decoration: none;
}

.invoice-link:hover {
    color: #667eea;
    text-decoration: underline;
}

.plan-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 500;
    background: #e8f5e9;
    color: #2e7d32;
}

.plan-warning {
    background: #fff3e0;
    color: #e65100;
}

.unpaid-badge {
    display: inline-block;
    background: #f8d7da;
    color: #721c24;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
}

.unpaid-badge:hover {
    background: #f1aeb5;
}

.billing-id-link {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 0.75rem;
    color: #667eea;
    text-decoration: none;
    background: #f0f0ff;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
}

.billing-id-link:hover {
    background: #e0e0ff;
    text-decoration: underline;
}
