@import url('https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #0c0f1a;
    --bg-accent: #161b2e;
    --card: #ffffff;
    --card-hover: #f8fafc;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.15);
    --radius: 12px;
    --radius-lg: 16px;
    font-family: "Roboto Condensed", "Inter", "Segoe UI", sans-serif;
    font-stretch: 95%;
    letter-spacing: -0.01em;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

h1, h2, h3 {
    margin: 0;
    font-weight: 600;
}

p {
    margin: 0;
}

.content {
    min-height: 100vh;
    padding: 32px 48px;
    background: linear-gradient(135deg, var(--bg) 0%, #12162a 100%);
    color: #fff;
    flex: 1;
    min-width: 0;
    overflow-x: hidden;
}

.content.standalone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
}

.hero {
    text-align: center;
    max-width: 760px;
}

.hero--landing {
    gap: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hero__badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 13px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.8);
}

.hero h1 {
    font-size: 56px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #fff, var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.7);
}

.hero__list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 15px;
}

.hero__list li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hero__list li::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-light);
}

.hero__meta {
    margin-top: 28px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    width: 100%;
}

.hero__meta-item {
    padding: 16px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(15, 23, 42, 0.25);
    text-align: left;
}

.hero__meta-item strong {
    display: block;
    font-size: 22px;
    margin-bottom: 4px;
    color: #fff;
}

.hero__meta-item span {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
}

.cta {
    margin-top: 32px;
    display: flex;
    gap: 16px;
    justify-content: center;
}

.auth-card {
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-card input {
    width: 100%;
}

.auth-card__subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--text-muted);
}

.auth-card__note {
    margin: 0;
    font-size: 13px;
    text-align: center;
    color: var(--text-muted);
}

.auth-card__note a {
    color: var(--primary);
    text-decoration: none;
}

.auth-card__note a:hover {
    text-decoration: underline;
}

.btn {
    padding: 12px 24px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn.secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
}

.btn-ghost:hover {
    background: var(--card-hover);
    color: var(--text);
    box-shadow: none;
    transform: none;
}

.btn-danger {
    background: var(--error);
    color: #fff;
    border: 1px solid var(--error);
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-small.btn-danger {
    padding: 6px 12px;
    font-size: 13px;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    max-width: 900px;
}

.features article {
    background: var(--bg-accent);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

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

.value-card {
    background: rgba(15, 23, 42, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    padding: 24px;
    color: rgba(255, 255, 255, 0.85);
    text-align: left;
    box-shadow: var(--shadow);
}

.value-card h3 {
    color: #fff;
    margin-bottom: 12px;
}

.value-card p {
    margin-bottom: 12px;
    color: rgba(255, 255, 255, 0.65);
}

.value-card ul {
    margin: 0;
    padding-left: 18px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 14px;
    line-height: 1.5;
}

.product-showcase {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    width: 100%;
    max-width: 960px;
}

.product-showcase__panel {
    background: rgba(15, 23, 42, 0.4);
    border-radius: var(--radius-lg);
    padding: 28px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    text-align: left;
}

.product-showcase__panel--glass {
    background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(15,23,42,0.6));
    border-color: rgba(99, 102, 241, 0.45);
}

.product-showcase__panel h4 {
    margin-bottom: 12px;
    color: #fff;
}

.product-showcase__panel p {
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 16px;
}

.product-showcase__pill-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pill {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
}

.timeline {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.timeline__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(15, 23, 42, 0.45);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
}

.timeline__row strong {
    color: #fff;
    font-weight: 600;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 900px;
}

.metric-card {
    background: rgba(15, 23, 42, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 20px;
    text-align: left;
}

.metric-card span {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
}

.metric-card strong {
    display: block;
    font-size: 24px;
    margin: 8px 0;
    color: #fff;
}

.metric-card p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
}

.cta-secondary {
    width: 100%;
    max-width: 760px;
    text-align: center;
    padding: 32px;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(15,23,42,0.6));
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: var(--shadow-lg);
}

.cta-secondary h2 {
    font-size: 32px;
    margin-bottom: 12px;
}

.cta-secondary p {
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 16px;
}

@media (max-width: 640px) {
    .hero h1 {
        font-size: 40px;
    }

    .cta {
        flex-direction: column;
        width: 100%;
    }

    .btn,
    .btn.secondary {
        width: 100%;
        justify-content: center;
    }

    .timeline__row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

/* App Shell */
.app-shell {
    display: flex;
    min-height: 100vh;
    position: relative;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.sidebar {
    width: 200px;
    background: var(--card);
    color: var(--text);
    padding: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    transition: width 0.25s ease;
    position: relative;
    flex-shrink: 0;
}

.sidebar-content {
    padding: 56px 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    transition: opacity 0.2s ease;
}

.sidebar nav,
.sidebar .brand,
.sidebar .logout-form {
    transition: opacity 0.2s ease;
}

body.sidebar-collapsed .sidebar {
    width: 48px;
    min-width: 48px;
}

body.sidebar-collapsed .sidebar-content {
    opacity: 0;
    pointer-events: none;
}

body.sidebar-collapsed .sidebar nav,
body.sidebar-collapsed .sidebar .brand,
body.sidebar-collapsed .sidebar .logout-form {
    opacity: 0;
}

.sidebar-toggle {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sidebar-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--card-hover);
}

.sidebar-toggle__icon {
    transition: transform 0.2s ease;
}

body.sidebar-collapsed .sidebar-toggle__icon {
    transform: rotate(180deg);
}

@media (max-width: 600px) {
    .sidebar-toggle {
        width: 28px;
        height: 28px;
    }
    
    body.sidebar-collapsed .sidebar {
        width: 40px;
        min-width: 40px;
    }
}

.sidebar .brand {
    font-size: 22px;
    font-weight: 700;
    padding: 0 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-user-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card-hover);
    margin: 10px 0 6px;
}

.sidebar-user-card__label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.sidebar-user-card__email {
    font-weight: 600;
    color: var(--text);
    word-break: break-all;
}

.sidebar-user-card__link {
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    width: fit-content;
}

.sidebar-user-card__link:hover {
    text-decoration: underline;
}

.sidebar nav a {
    padding: 12px 14px;
    border-radius: 10px;
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.15s ease;
}

.sidebar nav a:hover {
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary);
}

.logout-form {
    margin-top: auto;
}

.logout-form button {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.logout-form button:hover {
    border-color: var(--error);
    color: var(--error);
    background: rgba(239, 68, 68, 0.05);
}

.content .card {
    background: var(--card);
    color: var(--text);
    border-radius: var(--radius-lg);
    padding: 28px;
    border: 1px solid var(--border);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.card-section {
    padding: 24px 28px;
}

.card.table-card {
    padding: 0;
    overflow: visible;
}

.card.table-card > .table-wrapper {
    padding: 0 28px 28px;
}

.card.table-card > .table-wrapper:first-child {
    padding-top: 28px;
}

.card.table-card > .card-section + .table-wrapper,
.card.table-card > .table-wrapper + .card-section {
    border-top: 1px solid var(--border);
}


/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header .page-title {
    flex: 1 1 240px;
}

.page-title h1 {
    font-size: 28px;
    color: #fff;
    margin-bottom: 6px;
}

.page-title p {
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
}

.create-btn {
    padding: 14px 28px;
    font-size: 15px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

.create-btn:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.45);
}

/* Stats Row */
.stats-row {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: nowrap;
}

.stats-row .stat-card {
    flex: 1 1 0;
    min-width: 0;
}

.stat-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 6px;
    min-height: auto;
}

.stat-card.accent {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: transparent;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    line-height: 1.2;
    margin-bottom: 2px;
}

.stat-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.4;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.stat-card.accent .stat-label {
    color: rgba(255, 255, 255, 0.8);
}

/* Invoices Card */
.invoices-card {
    padding: 0 !important;
    overflow: visible;
}

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

.table-wrapper table {
    width: max(100%, var(--table-min-width, 1100px));
}

.invoices-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    min-width: 100%;
}

/* Обеспечиваем минимальную ширину для таблиц, чтобы они не сжимались слишком сильно */
.invoices-table {
    min-width: 800px;
}

.invoices-table.deals-table {
    min-width: 1000px;
}

/* Универсальные правила для всех таблиц - предотвращение перекрытия */
.invoices-table th,
.invoices-table td,
table.invoices-table th,
table.invoices-table td {
    overflow: hidden;
    position: relative;
    isolation: isolate;
}

.invoices-table th {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--card-hover);
    position: relative;
    z-index: 2;
}

.invoices-table td {
    position: relative;
    z-index: 1;
}

/* Для ячеек с длинным текстом - обрезка с ellipsis */
.invoices-table td > span:not(.status-badge):not(.doc-type-badge):not(.counter-badge):not(.deal-title):not(.deal-project),
.invoices-table td > div:not(.client-cell):not(.date-cell):not(.deal-title-cell):not(.deal-counters):not(.row-actions):not(.deal-totals) {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* Специальные правила для элементов, которые могут быть длинными */
.invoices-table td .doc-number,
.invoices-table td .doc-note {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* Для событий без сделки */
.event-without-deal {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--text-muted);
    font-size: 13px;
    flex-wrap: wrap;
    max-width: 100%;
    overflow: hidden;
}

.event-without-deal > * {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Для многострочного контента - правильная обработка */
.invoices-table td .client-cell,
.invoices-table td .date-cell {
    white-space: normal;
    overflow: visible;
    max-width: 100%;
}

.invoices-table td .client-cell > *,
.invoices-table td .date-cell > * {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Предотвращение перекрытия - строгие границы для ячеек */
.invoices-table td,
.invoices-table th {
    border-right: 1px solid transparent;
    border-left: 1px solid transparent;
}

.invoices-table td:not(:last-child),
.invoices-table th:not(:last-child) {
    border-right-color: var(--border);
}

.invoices-table th {
    white-space: nowrap;
}

/* Предотвращение перекрытия текста в ячейках таблицы */
.invoices-table td > div,
.invoices-table td > span {
    display: block;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.invoices-table td strong {
    display: block;
    margin-bottom: 2px;
    word-wrap: break-word;
}

/* Убеждаемся, что содержимое ячеек не выходит за границы */
.invoices-table td > * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Строгие правила для бейджей и кнопок в ячейках таблицы - предотвращение перекрытия */
.invoices-table td .status-badge {
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    box-sizing: border-box;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.invoices-table td .btn,
.invoices-table td .btn-small,
.invoices-table td button {
    max-width: calc(100% - 4px);
    box-sizing: border-box;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Контейнеры с flex внутри ячеек */
.invoices-table td > div[style*="display:flex"],
.invoices-table td > div[style*="display: flex"] {
    flex-wrap: wrap;
    gap: 4px 8px;
    max-width: 100%;
    box-sizing: border-box;
    align-items: center;
    overflow: hidden;
    width: 100%;
}

.invoices-table td > div[style*="display:flex"] > *,
.invoices-table td > div[style*="display: flex"] > * {
    flex-shrink: 1;
    min-width: 0;
}

/* Для столбца действий - кнопки в ряд, но с ограничением */
.invoices-table td:nth-last-child(1) > div[style*="display:flex"],
.invoices-table td:nth-last-child(1) > div[style*="display: flex"] {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
}

.invoices-table td:nth-last-child(1) > div[style*="display:flex"] > *,
.invoices-table td:nth-last-child(1) > div[style*="display: flex"] > * {
    flex: 0 1 auto;
    min-width: 0;
    max-width: calc(50% - 2px);
}

/* Формы внутри ячеек */
.invoices-table td form {
    display: inline-block;
    max-width: 100%;
    box-sizing: border-box;
}

.invoices-table td form button {
    max-width: 100%;
    box-sizing: border-box;
}

/* Минимальные ширины для последних столбцов (действия, статус, автоотправка) */
.invoices-table th:nth-last-child(1),
.invoices-table td:nth-last-child(1) {
    min-width: 180px !important;
    width: auto;
    max-width: 200px;
}

.invoices-table th:nth-last-child(2),
.invoices-table td:nth-last-child(2) {
    min-width: 100px !important;
    max-width: 120px;
}

.invoices-table th:nth-last-child(3),
.invoices-table td:nth-last-child(3) {
    min-width: 120px !important;
    max-width: 140px;
}

/* Дополнительная защита от перекрытия - изоляция содержимого ячеек */
.invoices-table td {
    isolation: isolate;
    contain: layout style;
}

.invoices-table th {
    isolation: isolate;
    contain: layout style;
}

/* Строгая изоляция для последних столбцов */
.invoices-table td:nth-last-child(1),
.invoices-table td:nth-last-child(2),
.invoices-table td:nth-last-child(3) {
    overflow: hidden;
    position: relative;
}

.invoices-table th:nth-last-child(1),
.invoices-table th:nth-last-child(2),
.invoices-table th:nth-last-child(3) {
    overflow: hidden;
    position: relative;
}

.invoices-table th {
    text-align: left;
    padding: 16px 20px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--card-hover);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: relative;
    z-index: 1;
}

.invoices-table td {
    padding: 16px 20px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 0;
}

.invoices-table tbody tr {
    transition: background 0.15s ease;
}

.invoices-table tbody tr:hover {
    background: var(--card-hover);
}

.invoice-related-acts td {
    background: rgba(15, 23, 42, 0.04);
    padding: 12px 20px;
}

.invoice-acts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.invoice-act-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.invoice-act-line .act-number {
    font-weight: 600;
    color: var(--text);
}

.invoice-act-line .act-date {
    font-size: 12px;
    color: var(--text-muted);
}

.invoice-act-line .status-badge {
    font-size: 11px;
    padding: 2px 8px;
}

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

.doc-number {
    font-weight: 600;
    color: var(--primary);
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
}

.client-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.client-name {
    font-weight: 500;
}

.client-email {
    font-size: 12px;
    color: var(--text-muted);
}

.amount {
    font-weight: 600;
    font-size: 15px;
}

.currency {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 4px;
}

.doc-type {
    font-size: 13px;
    color: var(--text-muted);
}

.date {
    font-size: 13px;
    color: var(--text-muted);
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-draft {
    background: rgba(100, 116, 139, 0.12);
    color: #64748b;
}

.status-sent {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}

.status-paid {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

.status-error {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

/* Action Button */
.action-form {
    display: inline-flex;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.action-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.row-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Empty State */
.empty-state {
    padding: 80px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.empty-icon {
    color: var(--text-muted);
    opacity: 0.4;
    margin-bottom: 8px;
}

.empty-state h3 {
    font-size: 20px;
    color: var(--text);
}

.empty-state p {
    color: var(--text-muted);
    max-width: 300px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
    z-index: 1000;
    padding: 24px;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 640px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.96);
    transition: transform 0.25s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.modal-close:hover {
    background: var(--card-hover);
    color: var(--text);
}

.modal-form {
    padding: 16px 20px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

.form-row.three {
    grid-template-columns: repeat(3, 1fr);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.form-label .required {
    color: var(--error);
}

.form-input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    font-size: 14px;
    width: 100%;
    transition: all 0.15s ease;
    background: #fff;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-input::placeholder {
    color: #94a3b8;
}

.form-input[readonly] {
    background: var(--card-hover);
    cursor: not-allowed;
}

.input-with-loader {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-loader .form-input {
    padding-right: 40px;
}

.loader {
    position: absolute;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    display: block;
}

/* Checkbox styles - чекбокс всегда слева от подписи */
label.checkbox,
.form-group > label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
}

label.checkbox input[type="checkbox"],
.form-group > label:has(input[type="checkbox"]) input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
    flex-shrink: 0;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.form-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

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

.form-details summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 500;
    font-size: 14px;
    padding: 8px 0;
}

.form-details[open] summary {
    margin-bottom: 16px;
}

/* Items Section */
.items-section {
    margin: 12px 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

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

.items-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.items-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: #fff;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
}

.items-table thead {
    background: var(--card-hover);
}

.items-table th {
    padding: 10px 8px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.items-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.items-table .form-input {
    margin: 0;
    padding: 8px 10px;
    font-size: 14px;
}

/* Увеличенные поля для кол-ва и цены */
.items-table td:nth-child(2) .form-input,
.items-table td:nth-child(4) .form-input {
    padding: 10px 12px;
    font-size: 15px;
    font-weight: 500;
}

.items-table td:nth-child(3) .form-input {
    text-align: center;
    padding: 8px 10px;
    font-size: 14px;
}

.items-table .item-unit {
    text-transform: none;
    min-width: 72px;
}

.unit-field {
    position: relative;
    width: 100%;
}

.unit-field .form-input {
    padding-right: 36px;
}

.unit-field__toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
}

.unit-field__toggle:hover,
.unit-field__toggle:focus {
    color: var(--text);
    background: rgba(15, 23, 42, 0.08);
    outline: none;
}

.unit-field__dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    width: max-content;
    min-width: 120px;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.18);
    padding: 4px 0;
    z-index: 50;
    display: none;
}

.unit-field__dropdown--open {
    display: block;
}

.unit-field__option {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.unit-field__option:hover,
.unit-field__option:focus {
    background: var(--card-hover);
    outline: none;
}

.quantity-field {
    display: flex;
    width: 100%;
    position: relative;
    align-items: stretch;
}

.quantity-field .form-input::-webkit-inner-spin-button,
.quantity-field .form-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.quantity-field .form-input[type="number"] {
    -moz-appearance: textfield;
}

.quantity-field .form-input {
    flex: 1;
    padding-right: 12px;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.quantity-field__controls {
    display: flex;
    flex-direction: column;
    width: 36px;
    border: 1px solid var(--border-strong);
    border-left: none;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
    overflow: hidden;
    margin-left: -1px;
    background: #fff;
}

.quantity-field__btn {
    width: 100%;
    height: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.quantity-field__btn + .quantity-field__btn {
    border-top: 1px solid var(--border-strong);
}

.quantity-field__btn:hover,
.quantity-field__btn:focus {
    color: var(--text);
    background: rgba(15, 23, 42, 0.08);
    outline: none;
}

.items-table .item-total {
    font-weight: 600;
    color: var(--text);
    text-align: right;
}

/* Выравнивание чисел вправо */
.items-table .item-price,
.items-table .item-quantity,
.items-table .item-total,
.items-table td:nth-child(2),
.items-table td:nth-child(4),
.items-table td:nth-child(5) {
    text-align: right;
}

.items-table .form-input.item-price,
.items-table .form-input.item-quantity {
    text-align: right;
}

/* Выравнивание итоговых сумм */
#itemsSubtotal,
#itemsVat,
#itemsTotal,
#editItemsSubtotal,
#editItemsVat,
#editItemsTotal,
#actItemsSubtotal,
#actItemsVat,
#actItemsTotal,
#editActItemsSubtotal,
#editActItemsVat,
#editActItemsTotal {
    text-align: right;
    display: inline-block;
    min-width: 100px;
}

/* Выравнивание полей с суммами */
#totalAmount,
#actTotalAmount,
#editActTotalAmount {
    text-align: right;
}

.items-subtotal {
    background: var(--card-hover);
}

.items-subtotal td {
    padding: 10px;
    border-top: 1px solid var(--border-strong);
}

.items-vat-row td {
    padding: 10px;
}

.items-total {
    background: var(--card-hover);
    font-weight: 600;
}

.items-total td {
    padding: 14px 10px;
    border-top: 2px solid var(--border-strong);
}

.btn-remove {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s ease;
    padding: 0;
}

.btn-remove:hover {
    background: var(--error);
    border-color: var(--error);
    color: #fff;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.match-modal-body {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
}

.match-modal-column {
    flex: 1 1 220px;
}

/* Filter chips */
.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    padding: 0 24px;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
}

.filter-chip-remove {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.filter-chip-remove:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 1);
}

/* Attention banner */
.attention-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius);
    margin-bottom: 16px;
    color: #fff;
    font-size: 14px;
}

.attention-banner span {
    font-weight: 500;
}

/* KPI clickable */
.stat-card {
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 72px;
}

.stat-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.stat-sublabel {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
}

/* Table header controls */
.table-header-controls {
    display: flex;
    justify-content: flex-end;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.view-mode-toggle {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: rgba(15, 23, 42, 0.7);
}

.view-mode-toggle .btn-ghost {
    border-radius: 999px;
    border: none;
    padding: 6px 14px;
    font-size: 13px;
    color: rgba(226, 232, 240, 0.8);
    background: transparent;
}

.view-mode-toggle .btn-ghost.active {
    background: #fff;
    color: var(--text);
}

/* Doc type badges */
.doc-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
}

.doc-type-payment {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}

.doc-type-invoice {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

.doc-type-act {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

.doc-type-operation {
    background: rgba(100, 116, 139, 0.12);
    color: #64748b;
}

/* Date cell */
.date-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.date-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* Amount cell */
.amount-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

/* Links cell */
.links-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.link-badge {
    font-size: 14px;
}

.link-counters {
    font-size: 11px;
    color: var(--text-muted);
    font-family: "JetBrains Mono", monospace;
}

/* Row actions */
.btn-mini {
    padding: 6px 12px;
    font-size: 12px;
    height: 28px;
    border-radius: 6px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: var(--card-hover);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-icon.btn-mini {
    width: 28px;
    height: 28px;
}

/* Popover menu */
.popover-menu-wrapper {
    position: relative;
    display: inline-block;
}

.popover-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 1000;
    overflow: hidden;
}

.popover-menu.show {
    display: block;
}

.popover-item {
    display: block;
    padding: 10px 16px;
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    transition: background-color 0.15s ease;
}

.popover-item:last-child {
    border-bottom: none;
}

.popover-item:hover {
    background-color: var(--card-hover);
}

/* Drawer */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    justify-content: flex-end;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.drawer-overlay.active {
    opacity: 1;
    visibility: visible;
}

.drawer {
    width: 100%;
    max-width: 520px;
    height: 100%;
    background: var(--card);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    overflow: hidden;
}

.drawer-overlay.active .drawer {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.drawer-title h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.drawer-title p {
    font-size: 14px;
    color: var(--text-muted);
}

.drawer-actions {
    display: flex;
    gap: 8px;
}

.drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    flex-shrink: 0;
}

.drawer-tab {
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: -1px;
}

.drawer-tab:hover {
    color: var(--text);
}

.drawer-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.drawer-tab-content {
    display: none;
}

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

/* Event details styles */
.event-details {
    margin-bottom: 24px;
}

.detail-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: flex-start;
}

.detail-label {
    font-weight: 500;
    color: var(--text-muted);
    min-width: 100px;
    flex-shrink: 0;
}

.detail-value {
    color: var(--text);
    flex: 1;
}

.links-section {
    margin-bottom: 24px;
}

.links-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.connection-block {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--card-hover);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.connection-block h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.history-section {
    margin-bottom: 24px;
}

.history-timeline {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.history-item {
    padding: 12px;
    background: var(--card-hover);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}

.history-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.history-action {
    font-size: 14px;
    color: var(--text);
}

/* Deal rows */
.deal-row {
    cursor: pointer;
}

.deal-title-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}

.deal-title-cell > * {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deal-title-cell .deal-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deal-expand-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.deal-expand-btn:hover {
    background: var(--card-hover);
    color: var(--text);
}

.deal-expand-btn.expanded svg {
    transform: rotate(90deg);
}

.deal-title {
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    flex: 1 1 auto;
    min-width: 0;
}

.deal-project {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 150px;
}

.deal-project {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
}

.deal-totals {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    font-size: 13px;
}

.deal-planned,
.deal-actual {
    color: var(--text-muted);
}

.deal-counters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.counter-badge {
    display: inline-block;
    padding: 4px 8px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 4px;
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    font-family: "JetBrains Mono", monospace;
}

.deal-events {
    padding: 16px;
    background: var(--card-hover);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nested-table {
    margin: 0;
    min-width: 600px;
    width: 100%;
}

.nested-table th,
.nested-table td {
    padding: 10px 12px;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.nested-table th {
    white-space: nowrap;
}

.nested-table td > * {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.event-without-deal {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Status badges extended */
.status-overdue {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

.status-unmatched {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

.status-partial {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

.status-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

/* Row clickable */
.js-row-clickable {
    cursor: pointer;
}

.js-row-clickable:hover {
    background: var(--card-hover);
}

/* Empty actions */
.empty-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* Header actions group */
.header-actions-group {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

/* Table sticky header */
.invoices-table thead {
    background: var(--card);
    position: relative;
    z-index: 1;
}

.table-wrapper.table-sticky {
    --table-sticky-offset: 0px;
}

.table-wrapper.table-sticky .invoices-table thead {
    position: sticky;
    top: var(--table-sticky-offset, 0px);
    z-index: 5;
    box-shadow: 0 1px 0 var(--border);
}

/* Match suggestions */
.match-suggestions {
    margin-top: 8px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
}

.match-suggestion-item {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s ease;
}

.match-suggestion-item:hover {
    background: var(--card-hover);
}

.match-suggestion-item:last-child {
    border-bottom: none;
}

.match-option-group {
    margin-bottom: 16px;
}

/* Comments and tasks */
.comments-section,
.tasks-section {
    margin-bottom: 24px;
}

.comment-form,
.task-form {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

.comment-form textarea {
    flex: 1;
    resize: vertical;
    min-height: 80px;
}

.task-form input {
    flex: 1;
}

.comment-item,
.task-item {
    padding: 12px;
    background: var(--card-hover);
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.task-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.task-item.completed {
    opacity: 0.6;
}

.task-item.completed .task-content {
    text-decoration: line-through;
}

/* Legacy styles */
.page-grid {
    display: grid;
    grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
    gap: 32px;
    align-items: flex-start;
}

.card.table-card {
    padding: 24px 28px;
}

.section-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 18px;
}

.section-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

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

.counter {
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.1);
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
}

.stacked {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

label {
    font-weight: 500;
}

input, select, textarea {
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-strong);
    font-size: 14px;
    width: 100%;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

th, td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.flash {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-weight: 500;
}

.flash.success {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.flash.error {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.grid {
    display: grid;
    gap: 16px;
}

.grid.two {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid.three {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.inline-form {
    display: inline-block;
    margin-right: 8px;
}

.btn.small {
    padding: 8px 16px;
    font-size: 13px;
}

.card pre {
    background: var(--bg);
    color: #e2e8f0;
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
}

.actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.text-danger {
    color: var(--error);
    font-weight: 600;
}

.muted {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.4;
    margin-top: 4px;
    display: block;
}

details summary {
    cursor: pointer;
    color: var(--primary);
}

@media (max-width: 960px) {
    .app-shell {
        flex-direction: column;
    }

    .page-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        padding: 16px 20px;
    }

    .sidebar nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .logout-form {
        margin-top: 0;
    }

    .content {
        padding: 24px 20px;
    }

    .stats-row {
        flex-wrap: wrap;
    }

    .stats-row .stat-card {
        flex: 1 1 calc(50% - 6px);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .form-row,
    .form-row.three {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 600px) {
    .stats-row .stat-card {
        flex: 1 1 100%;
    }
}

/* Operations page - scrollable tables */
.operations-table-wrapper {
    max-height: 600px;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.operations-table-wrapper table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.operations-table-wrapper thead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--card);
}

.operations-table-wrapper th {
    background: var(--card-hover);
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    z-index: 1;
}

.operations-table-wrapper td {
    padding: 12px 16px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
}

.operations-table-wrapper td > *:not(details):not(pre) {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.operations-table-wrapper tbody tr:hover {
    background: var(--card-hover);
}

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

.datetime-cell {
    font-family: "JetBrains Mono", "Consolas", "Courier New", monospace;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    white-space: nowrap;
    letter-spacing: 0;
    font-weight: 400;
}

/* Overview page */
.overview-page .page-header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding-bottom: 12px;
    padding-left: 72px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--bg) 0%, #12162a 100%);
}

.overview-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    flex: 1 1 320px;
    flex-wrap: wrap;
}

.overview-header-actions .header-actions-left {
    flex: 1 1 320px;
    min-width: 280px;
}

.overview-header-actions .header-actions-right {
    display: flex;
    gap: 12px;
    align-items: center;
}

.dropdown {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: block;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    transition: background-color 0.2s;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background-color: var(--card-hover);
}

.dropdown-item:active {
    background-color: #f1f5f9;
}

.dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.overview-header-actions .header-actions-right {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.segmented-control {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: rgba(15, 23, 42, 0.7);
}

.segmented-control .btn-ghost {
    border-radius: 999px;
    border: none;
    padding: 6px 14px;
    font-size: 13px;
    color: rgba(226, 232, 240, 0.8);
    background: transparent;
}

.segmented-control .btn-ghost.active {
    background: #fff;
    color: var(--text);
}

.overview-filters {
    margin-bottom: 20px;
}

.overview-filters-main {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.overview-filter-field {
    flex: 1 1 200px;
    min-width: 180px;
}

.overview-filter-field-search {
    flex: 1 1 300px;
    min-width: 200px;
}

.overview-filter-field-type {
    flex: 0 0 160px;
}

.overview-filter-field-period {
    flex: 0 0 140px;
}

.overview-filter-actions-main {
    display: flex;
    align-items: center;
    gap: 8px;
}

.overview-filter-actions-main {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
}

.overview-filter-actions-main .btn {
    display: flex;
    align-items: center;
    gap: 4px;
}

#advanced-filters-arrow {
    margin-left: 0;
    transition: transform 0.2s ease;
    display: inline-block;
    vertical-align: middle;
}

.overview-filters-advanced {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.overview-filter-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
}

#advanced-filters-arrow {
    transition: transform 0.2s ease;
    display: inline-block;
    vertical-align: middle;
}

@media (max-width: 960px) {
    .overview-filters-main {
        flex-direction: column;
        align-items: stretch;
    }

    .overview-filter-field,
    .overview-filter-field-search,
    .overview-filter-field-type {
        flex: 1 1 100%;
    }

    .overview-filters-advanced {
        flex-direction: column;
        align-items: stretch;
    }
}

.company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.company-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    background: var(--card);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.company-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.company-card__meta {
    margin: 0;
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 4px 12px;
    font-size: 13px;
}

.company-card__meta dt {
    color: var(--text-muted);
}

.company-card__meta dd {
    margin: 0;
}

.company-card__actions {
    display: flex;
    justify-content: flex-end;
}

.company-switcher {
    margin-bottom: 16px;
}

.company-switcher__form select {
    width: 100%;
}
