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

:root {
    /* Light mode colors */
    --bg-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-secondary: white;
    --bg-tertiary: #f5f5f5;
    --bg-hover: #e8e8e8;
    --text-primary: #333;
    --text-secondary: #666;
    --text-tertiary: #999;
    --border-color: #e0e0e0;
    --shadow: rgba(0,0,0,0.1);
    --shadow-hover: rgba(0,0,0,0.15);
    --modal-overlay: rgba(0,0,0,0.5);
    --card-bg: white;
    --table-row-even: #f9f9f9;
    --table-row-hover: #f5f5f5;

    /* Единна типографска скала (база 14px вместо 16px) */
    --font-size-root: 14px;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.8125rem;
    --font-size-base: 0.875rem;
    --font-size-md: 0.9375rem;
    --font-size-lg: 1rem;
    --font-size-xl: 1.125rem;
    --font-size-2xl: 1.3125rem;
    --font-size-3xl: 1.5rem;
}

html {
    font-size: var(--font-size-root);
}

[data-theme="dark"] {
    /* Dark mode colors */
    --bg-primary: linear-gradient(135deg, #2d1b4e 0%, #1a0d2e 100%);
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --bg-hover: #3d3d3d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-tertiary: #808080;
    --border-color: #404040;
    --shadow: rgba(0,0,0,0.3);
    --shadow-hover: rgba(0,0,0,0.5);
    --modal-overlay: rgba(0,0,0,0.7);
    --card-bg: #252525;
    --table-row-even: #2a2a2a;
    --table-row-hover: #333333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: var(--font-size-lg);
    line-height: 1.45;
    background: var(--bg-primary);
    min-height: 100vh;
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

/* Форми и филтри — един размер навсякъде */
.container select,
.container input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.container textarea,
.modal-content select,
.modal-content input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
.modal-content textarea,
.login-box select,
.login-box input,
.login-box textarea {
    font-size: var(--font-size-md);
}

/* Заглавия на секции в таблици (генерирани от JS) */
.company-section > h3,
.proforma-section > h3,
.unpaid-section > h3 {
    font-size: var(--font-size-xl) !important;
}

/* Login страница */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 60px var(--shadow);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 10px;
    color: #667eea;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 0.95em;
    transition: color 0.3s ease;
}

.login-info {
    margin-top: 20px;
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.85em;
    color: var(--text-secondary);
    transition: background 0.3s ease, color 0.3s ease;
}

.login-info p {
    margin: 5px 0;
}

.error-message {
    margin-top: 15px;
    padding: 12px;
    background: #fee;
    color: #c33;
    border-radius: 8px;
    text-align: center;
}

/* Основна страница */
.container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    background: var(--bg-secondary);
    min-height: 100vh;
    box-shadow: 0 0 40px var(--shadow);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 24px;
}

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

header h1 {
    font-size: var(--font-size-3xl);
    margin-bottom: 4px;
}

header p {
    opacity: 0.9;
    font-size: var(--font-size-md);
}

.tabs {
    display: flex;
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.tab-btn {
    flex: 1;
    padding: 11px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-md);
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s;
    border-bottom: 3px solid transparent;
}

.tab-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
    background: var(--bg-secondary);
}

.tab-content {
    display: none;
    padding: 20px 24px;
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 25px;
    gap: 15px;
}

.section-header h2 {
    font-size: var(--font-size-2xl);
    color: var(--text-primary);
    transition: color 0.3s ease;
    margin: 0;
}

.section-header > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.filter-buttons {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: var(--font-size-md);
    font-weight: 500;
    transition: all 0.3s;
}

.btn-sm {
    padding: 6px 12px;
    font-size: var(--font-size-sm);
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-block {
    width: 100%;
    margin-top: 10px;
}

.btn-success {
    background: #4caf50;
    color: white;
}

.btn-success:hover {
    background: #45a049;
}

.btn-danger {
    background: #f44336;
    color: white;
}

.btn-danger:hover {
    background: #da190b;
}

.btn-warning {
    background: #ff9800;
    color: white;
}

.btn-warning:hover {
    background: #e68900;
}

/* Напомняния grid */
.reminders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
}

.reminder-card {
    background: var(--card-bg);
    border-left: 5px solid #667eea;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow);
    transition: all 0.3s;
}

.reminder-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px var(--shadow-hover);
}

.reminder-card.overdue {
    border-left-color: #f44336;
    background: var(--card-bg);
}

[data-theme="dark"] .reminder-card.overdue {
    background: rgba(244, 67, 54, 0.1);
}

[data-theme="light"] .reminder-card.overdue {
    background: #fff5f5;
}

.reminder-card.due-soon {
    border-left-color: #ff9800;
}

[data-theme="dark"] .reminder-card.due-soon {
    background: rgba(255, 152, 0, 0.1);
}

[data-theme="light"] .reminder-card.due-soon {
    background: #fffbf0;
}

.reminder-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.reminder-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.reminder-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
}

.badge-overdue {
    background: #fee;
    color: #c33;
}

[data-theme="dark"] .badge-overdue {
    background: rgba(244, 67, 54, 0.2);
    color: #ff6b6b;
}

.badge-due-soon {
    background: #fff3cd;
    color: #856404;
}

[data-theme="dark"] .badge-due-soon {
    background: rgba(255, 152, 0, 0.2);
    color: #ffb74d;
}

.badge-pending {
    background: #e3f2fd;
    color: #1976d2;
}

[data-theme="dark"] .badge-pending {
    background: rgba(25, 118, 210, 0.2);
    color: #64b5f6;
}

.badge-issued {
    background: #e8f5e9;
    color: #2e7d32;
}

[data-theme="dark"] .badge-issued {
    background: rgba(76, 175, 80, 0.2);
    color: #81c784;
}

.reminder-info {
    margin: 10px 0;
    color: var(--text-secondary);
    font-size: 0.95em;
    transition: color 0.3s ease;
}

.reminder-date {
    font-size: 1.1em;
    font-weight: 600;
    color: #667eea;
    margin: 10px 0;
}

.reminder-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.reminder-actions .btn {
    flex: 1;
    padding: 8px 16px;
    font-size: 0.9em;
}

/* Cards grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow);
    transition: all 0.3s;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px var(--shadow-hover);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 15px;
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
    transition: color 0.3s ease;
}

.card-info {
    margin: 8px 0;
    color: var(--text-secondary);
    font-size: 0.95em;
    transition: color 0.3s ease;
}

.card-amount {
    font-size: 1.5em;
    font-weight: 700;
    color: #667eea;
    margin: 15px 0;
}

.card-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.card-actions .btn {
    flex: 1;
    padding: 8px 16px;
    font-size: 0.9em;
}

/* Модално прозорче */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(5px);
    transition: background 0.3s ease;
}

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

.modal-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 22px 24px;
    max-width: 600px;
    font-size: var(--font-size-md);
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: slideIn 0.3s;
    transition: background 0.3s ease;
}

.modal-content h2 {
    color: var(--text-primary);
    font-size: var(--font-size-xl);
    margin-bottom: 16px;
}

.form-group small {
    font-size: var(--font-size-sm);
}

#client-details-content .client-details-body a:hover {
    opacity: 0.85;
}

.client-name-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
}
.client-name-link:hover {
    color: #667eea !important;
}
[data-theme="dark"] .client-name-link:hover {
    color: #a0a0ff !important;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close {
    position: absolute;
    right: 16px;
    top: 14px;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.3s;
}

.close:hover {
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: var(--font-size-md);
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 11px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: var(--font-size-md);
    transition: border-color 0.3s, background 0.3s ease, color 0.3s ease;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Подобрена четимост на input полетата в тъмен режим */
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-group select,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] select {
    background: #2d2d2d !important;
    color: #ffffff !important;
    border-color: #404040 !important;
}

[data-theme="dark"] .form-group input::placeholder,
[data-theme="dark"] .form-group textarea::placeholder,
[data-theme="dark"] input::placeholder {
    color: #999999 !important;
    opacity: 1;
}

[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-group select:focus,
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus {
    background: #333333 !important;
    border-color: #667eea !important;
    color: #ffffff !important;
}

/* Стилове за select опции в тъмен режим */
[data-theme="dark"] .form-group select option,
[data-theme="dark"] select option {
    background: #2d2d2d !important;
    color: #ffffff !important;
}

[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-group select:focus {
    background: #333333 !important;
    border-color: #667eea !important;
    color: #ffffff !important;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

/* Скриване на LastPass за date полета */
input[type="date"] {
    position: relative;
    cursor: pointer;
}

/* Скриване на вградената календар икона на браузъра (за да използваме нашата) */
input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0;
    position: absolute;
    right: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

/* За Firefox - скриване на вградената икона */
input[type="date"]::-moz-calendar-picker-indicator {
    opacity: 0;
    position: absolute;
    right: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

/* Скриване на LastPass елементи */
input[type="date"][data-lastpass-ignore],
input[type="date"][data-lpignore],
input[type="date"][data-1p-ignore] {
    background-image: none !important;
}

/* Скриване на LastPass overlay и икони САМО около date полета */
/* LastPass е активиран за login формата и другите полета */

/* Премахване на LastPass икони в date полета */
input[type="date"]::before,
input[type="date"]::after {
    display: none !important;
}

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

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
    transition: color 0.3s ease;
}

/* Таблица за фактури */
#invoices-list table,
.invoice-data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--shadow);
    transition: background 0.3s ease, box-shadow 0.3s ease;
    table-layout: fixed;
}

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

#invoices-list table th,
.invoice-data-table th,
.container table th {
    padding: 7px 10px;
    text-align: left;
    font-weight: 600;
    font-size: var(--font-size-md);
}

#invoices-list table td,
.invoice-data-table td,
.container table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    vertical-align: middle;
}

#invoices-list table tbody tr:hover,
.invoice-data-table tbody tr:hover {
    background: var(--table-row-hover);
}

#invoices-list table tbody tr:nth-child(even),
.invoice-data-table tbody tr:nth-child(even) {
    background: var(--table-row-even);
}

#invoices-list table tbody tr:nth-child(even):hover,
.invoice-data-table tbody tr:nth-child(even):hover {
    background: var(--table-row-hover);
}

.invoice-data-table col.invoice-col-num { width: 9.75rem; }
.invoice-data-table col.invoice-col-client { width: 34%; }
.invoice-data-table col.invoice-col-amount { width: 6.25rem; }
.invoice-data-table col.invoice-col-date { width: 6.5rem; }
.invoice-data-table col.invoice-col-notes { width: 5.75rem; }
.invoice-data-table col.invoice-col-files { width: 11.5rem; }
.invoice-data-table col.invoice-col-actions { width: 4.5rem; }

.invoice-data-table .invoice-td-num,
.invoice-data-table .invoice-th-num,
.invoice-data-table .invoice-td-amount,
.invoice-data-table .invoice-th-amount {
    white-space: nowrap;
}

.invoice-data-table .invoice-td-num,
.invoice-data-table .invoice-th-num {
    overflow: hidden;
    max-width: 9.75rem;
}

.invoice-data-table .invoice-td-client,
.invoice-data-table .invoice-th-client {
    overflow: hidden;
    min-width: 0;
}

.invoice-client-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.invoice-date-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    line-height: 1.2;
}

.invoice-date-issue {
    white-space: nowrap;
}

.invoice-num-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    line-height: 1.25;
    max-width: 100%;
    overflow: hidden;
}

.invoice-num-final,
.invoice-num-proforma {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.invoice-num-final {
    font-weight: 600;
}

.invoice-num-proforma {
    font-size: 0.82em;
    font-weight: 700;
    color: #e65100;
}

[data-theme="dark"] .invoice-num-proforma {
    color: #ffb74d;
}

.invoice-data-table .invoice-td-notes {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.invoice-th-actions,
.invoice-td-actions {
    padding: 6px 4px !important;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    width: 4.5rem;
    min-width: 4.5rem;
    max-width: 4.5rem;
}

.invoice-th-actions {
    font-size: 1rem;
    color: #ffc107;
}

.invoice-row-actions {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.invoice-row-edit-btn,
.invoice-row-cancel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border-radius: 5px;
    font-size: var(--font-size-md);
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.invoice-row-edit-btn {
    border: 2px solid #ffc107;
    background: rgba(255, 193, 7, 0.22);
    color: #ffc107;
}

.invoice-row-edit-btn:hover {
    background: rgba(255, 193, 7, 0.42);
    transform: scale(1.06);
}

.invoice-row-cancel-btn {
    border: 2px solid #ef5350;
    background: rgba(244, 67, 54, 0.18);
    color: #ef5350;
    font-weight: 700;
}

.invoice-row-cancel-btn:hover {
    background: rgba(244, 67, 54, 0.32);
}

[data-theme="dark"] .invoice-row-edit-btn {
    border-color: #ffca28;
    color: #ffca28;
    background: rgba(255, 202, 40, 0.25);
}

[data-theme="dark"] .invoice-th-actions {
    color: #ffca28;
}

.finalize-proforma-hint {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid #ff9800;
    background: rgba(255, 152, 0, 0.12);
    font-size: var(--font-size-sm, 0.875rem);
    line-height: 1.45;
}

.finalize-proforma-hint p {
    margin: 6px 0 0;
    color: inherit;
}

[data-theme="dark"] .finalize-proforma-hint {
    border-color: #ffb74d;
    background: rgba(255, 183, 77, 0.15);
}

.invoice-file-links {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
    justify-content: center;
    align-items: center;
}

.invoice-file-row {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 4px;
    justify-content: center;
    align-items: center;
}

.invoice-file-links a {
    display: inline-block;
    padding: 3px 7px;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: var(--font-size-xs);
    line-height: 1.25;
    white-space: nowrap;
    font-weight: 600;
}

.invoice-file-links a.invoice-file-proforma { background: #e65100; }
.invoice-file-links a.invoice-file-proforma-copy { background: #ff9800; }
.invoice-file-links a.invoice-file-final { background: #667eea; }
.invoice-file-links a.invoice-file-final-copy { background: #4caf50; }

.empty-state p {
    font-size: var(--font-size-md);
}

/* Theme toggle button */
.theme-toggle {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    vertical-align: middle;
    line-height: 1;
}

.theme-toggle:hover {
    background: var(--bg-hover);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    stroke: currentColor;
}

/* Компактни бутони в антетката — еднаква височина */
header .header-toolbar .btn {
    box-sizing: border-box;
    height: 30px;
    min-height: 30px;
    max-height: 30px;
    padding: 0 10px;
    font-size: var(--font-size-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 0.82em;
    font-weight: 700;
    letter-spacing: 0.04em;
    gap: 0;
}
header .header-toolbar .theme-toggle.header-icon-btn {
    width: 30px;
    min-width: 30px;
    padding: 0;
}
header .header-toolbar .theme-toggle svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}
header .theme-toggle #theme-text {
    display: none !important;
}
header .header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
}
header .header-toolbar {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Responsive */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
    }

    .invoice-file-links {
        flex-wrap: wrap;
        max-width: 160px;
    }

    .invoice-data-table .invoice-td-num,
    .invoice-data-table .invoice-td-amount,
    .invoice-data-table .invoice-td-date,
    .invoice-data-table .invoice-td-files {
        white-space: normal;
    }

    .reminders-grid,
    .cards-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header > div {
        flex-wrap: wrap;
    }
    
    header {
        padding: 18px 14px;
    }

    header h1 {
        font-size: 1.9em;
    }
    
    .header-content {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
        max-width: 520px;
        margin: 0 auto;
    }

    .header-content > div:first-child {
        text-align: left;
    }

    .header-content > div:last-child {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        gap: 8px !important;
        width: 100%;
    }
    header .header-actions {
        align-items: center;
        width: 100%;
    }
    header .header-toolbar {
        justify-content: center;
        flex-wrap: nowrap;
    }

    .container {
        max-width: 100%;
        width: 100%;
    }

    .tab-content {
        padding: 16px;
        max-width: 520px;
        margin: 0 auto;
    }

    .tabs {
        display: flex;
        flex-wrap: wrap;
        overflow: visible;
        white-space: normal;
        max-width: 520px;
        margin: 0 auto;
    }

    .tab-btn {
        flex: 1 1 33.33%;
        min-width: 0;
        padding: 10px 8px;
        font-size: 0.9em;
        text-align: center;
    }

    .btn {
        padding: 10px 14px;
        font-size: 0.95em;
    }

    /* Mobile cards generated by adaptTablesForMobile() */
    .mobile-cards-for-table {
        display: grid;
        gap: 12px;
        margin-top: 10px;
    }

    .mobile-table-card {
        border: 1px solid var(--border-color);
        border-radius: 10px;
        background: var(--card-bg);
        padding: 10px 12px;
        box-shadow: 0 2px 8px var(--shadow);
    }

    .mobile-card-row {
        display: grid;
        grid-template-columns: minmax(90px, 38%) 1fr;
        gap: 10px;
        padding: 7px 0;
        border-bottom: 1px solid var(--border-color);
        align-items: center;
    }

    .mobile-card-row:last-child {
        border-bottom: none;
        padding-bottom: 2px;
    }

    .mobile-card-label {
        color: var(--text-tertiary);
        font-size: 0.82em;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    .mobile-card-value {
        color: var(--text-primary);
        font-size: 0.94em;
        word-break: break-word;
    }

    .mobile-card-value .btn {
        width: 100%;
        margin-top: 4px;
    }
}

/* Плаващ бутон „Нагоре“ — дълги списъци (фактури, мобилен изглед) */
.scroll-to-top-btn {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: calc(18px + env(safe-area-inset-right, 0px));
    width: 50px;
    height: 50px;
    padding: 0;
    border: none;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 900;
    color: #fff;
    background: rgba(102, 126, 234, 0.42);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: opacity 0.25s ease, transform 0.2s ease, background 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

.scroll-to-top-btn.visible {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.scroll-to-top-btn:hover {
    background: rgba(102, 126, 234, 0.62);
    transform: translateY(-2px);
}

.scroll-to-top-btn:active {
    transform: translateY(0);
}

[data-theme="dark"] .scroll-to-top-btn {
    background: rgba(140, 140, 220, 0.38);
    box-shadow: 0 4px 22px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .scroll-to-top-btn:hover {
    background: rgba(160, 160, 240, 0.55);
}

@media (max-width: 600px) {
    .scroll-to-top-btn {
        width: 48px;
        height: 48px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: calc(14px + env(safe-area-inset-right, 0px));
    }
}

/* Предупреждение за активни проформи в антетката (върху лилав header) */
header .proforma-header-alert {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 2px solid #ffcc80;
    border-radius: 8px;
    background: #e65100;
    color: #fff;
    font-weight: 700;
    font-size: var(--font-size-sm);
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    transition: background 0.2s, transform 0.15s;
}
header .proforma-header-alert.is-visible,
header .proforma-header-alert[style*="inline-flex"] {
    display: inline-flex !important;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}
header .proforma-header-alert .billing-alert-line {
    display: block;
    white-space: nowrap;
    line-height: 1.3;
}
header .proforma-header-alert:hover {
    background: #f57c00;
    transform: translateY(-1px);
}
header .proforma-header-alert.has-unpaid:not(.has-proforma) {
    background: #1565c0;
    border-color: #90caf9;
}
header .proforma-header-alert.has-unpaid:not(.has-proforma):hover {
    background: #1976d2;
}
header .proforma-header-alert.has-unpaid.has-proforma {
    background: linear-gradient(135deg, #1565c0 0%, #e65100 100%);
    border-color: #ffe0b2;
}
.badge-proforma {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 152, 0, 0.25);
    color: #e65100;
    font-size: 0.75em;
    font-weight: 700;
}
.btn-proforma {
    background: linear-gradient(135deg, #ff9800 0%, #f57c00 100%);
    color: #fff;
    border: none;
}
.btn-proforma-outline {
    background: transparent;
    color: #e65100;
    border: 1px solid #ff9800;
}
.btn-proforma-outline:hover {
    background: rgba(255, 152, 0, 0.15);
}
.cancel-proforma-btn {
    color: #c62828;
    border-color: rgba(198, 40, 40, 0.5);
}
.unpaid-section h3 {
    color: #1565c0;
    font-size: 1.15em;
    margin: 0 0 8px;
}
.unpaid-row {
    background: rgba(33, 150, 243, 0.06);
}
.unpaid-row.unpaid-remind {
    background: rgba(255, 193, 7, 0.12);
}
.unpaid-row.unpaid-overdue {
    background: rgba(244, 67, 54, 0.1);
}
[data-theme="dark"] .unpaid-section h3 {
    color: #64b5f6;
}
tbody tr.invoice-row-paid {
    background: rgba(76, 175, 80, 0.14) !important;
}
tbody tr.invoice-row-paid td {
    border-bottom-color: rgba(76, 175, 80, 0.2);
}
tbody tr.invoice-row-paid.invoice-row-proforma {
    background: rgba(255, 152, 0, 0.12) !important;
}
.invoice-paid-date-hint {
    font-size: 0.78em;
    color: #2e7d32;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}
[data-theme="dark"] tbody tr.invoice-row-paid {
    background: rgba(76, 175, 80, 0.22) !important;
}
[data-theme="dark"] .invoice-paid-date-hint {
    color: #81c784;
}
