:root {
    --brand-red: #ea1228;
    --brand-red-hover: #cc1023;
    --brand-black: #0f1217;
    --brand-dark-2: #181818;

    --text-main: #1b2430;
    --text-soft: #5f6d7c;
    --text-on-dark: #f3f4f6;

    --bg-app: #f5f7fb;
    --bg-card: #ffffff;
    --bg-soft: #f8fafc;
    --bg-dark: #0f0f10;

    --line: #e5eaf2;
    --line-dark: #2a2b30;

    --success-bg: #ecfdf3;
    --success-text: #166534;
    --warning-bg: #fff7e6;
    --warning-text: #8a4b12;

    --shadow-xs: 0 2px 8px rgba(16, 24, 40, 0.06);
    --shadow-sm: 0 8px 22px rgba(16, 24, 40, 0.08);
    --shadow-md: 0 18px 40px rgba(16, 24, 40, 0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
    color: var(--text-main);
    background:
        radial-gradient(1200px 620px at 12% -4%, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0) 62%),
        radial-gradient(900px 420px at 94% 100%, rgba(241, 56, 86, 0.08) 0%, rgba(241, 56, 86, 0) 74%),
        linear-gradient(180deg, #f8f9fd 0%, #f2f5fb 52%, #eef2f8 100%);
}

a {
    color: inherit;
}

.hidden {
    display: none !important;
}

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

.error-text {
    margin: 0;
    font-size: 13px;
    color: var(--brand-red);
}

.full-width {
    width: 100%;
}

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-container {
    width: 100%;
    max-width: 460px;
    background: var(--bg-card);
    border: 1px solid #edf0f6;
    border-radius: 20px;
    padding: 34px;
    box-shadow: var(--shadow-md);
}

.login-title {
    margin: 0 0 8px;
    font-size: 31px;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--brand-black);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 4px;
}

.brand-mark span {
    background: var(--brand-red);
    border-radius: 5px;
    transform: skewX(-12deg);
}

.form-stack {
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.remember {
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.remember label {
    margin: 0;
    cursor: pointer;
    font-weight: 500;
}

/* App shell */
.app-body {
    margin: 0;
    position: relative;
    overflow-x: hidden;
}

.app-body::before {
    content: "";
    position: fixed;
    right: -110px;
    bottom: -110px;
    width: 520px;
    height: 360px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, rgba(242, 87, 114, 0.16) 0%, rgba(242, 87, 114, 0.04) 44%, rgba(242, 87, 114, 0) 72%);
    pointer-events: none;
    z-index: 0;
}

.app-body::after {
    content: "";
    position: fixed;
    right: 26px;
    bottom: 22px;
    width: 210px;
    height: 210px;
    opacity: 0.42;
    background-image: radial-gradient(rgba(234, 18, 40, 0.38) 1.6px, transparent 1.7px);
    background-size: 14px 14px;
    pointer-events: none;
    z-index: 0;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    position: relative;
    z-index: 1;
}

.sidebar {
    width: 252px;
    min-width: 252px;
    background: linear-gradient(180deg, #10141c 0%, #0b0e14 100%);
    color: var(--text-on-dark);
    padding: 24px 18px;
    border-right: 1px solid var(--line-dark);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.2;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar h2::before {
    content: "";
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(180deg, #ff3a4f, #d40f25);
    box-shadow: 0 0 0 4px rgba(234, 18, 40, 0.16);
}

.sidebar-subtitle {
    margin: 0 0 12px;
    color: #c9ced7;
    font-size: 13px;
}

.menu-item {
    display: block;
    width: 100%;
    border: 1px solid #2f333b;
    border-radius: 12px;
    background: #1a1d22;
    color: #f3f4f6;
    padding: 11px 12px;
    text-decoration: none;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.menu-item:hover {
    transform: translateY(-1px);
    border-color: #4c535f;
}

.menu-item.active {
    background: linear-gradient(180deg, #ef1f35 0%, #d20e22 100%);
    border-color: var(--brand-red);
    color: #ffffff;
}

.menu-item.danger {
    margin-top: auto;
    background: #2a171a;
    border-color: #4f242a;
    color: #ffe5e8;
}

.content {
    flex: 1;
    width: min(1160px, 100%);
    margin: 0 auto;
    padding: 30px 34px 32px;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    align-items: start;
}

.content-main {
    min-width: 0;
}

.content-side {
    position: sticky;
    top: 18px;
}

.side-card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.content-side .side-card + .side-card {
    margin-top: 12px;
}

.side-card-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.side-card-header h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.side-card-body {
    padding: 14px 14px 16px;
}

.topbar {
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
}

.topbar h1 {
    margin: 0 0 6px;
    font-size: 36px;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--brand-black);
}

.topbar p {
    margin: 0;
    color: var(--text-soft);
}

.user-box {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 11px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-xs);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.user-avatar,
.user-avatar-placeholder {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    display: inline-grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}

.user-avatar-placeholder {
    background: #f1f5f9;
    color: #334155;
}

.table-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    display: inline-grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
}

.table-avatar-placeholder {
    background: #f1f5f9;
    color: #334155;
}

.user-box-text {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
    align-items: flex-start;
}

.user-box-text strong {
    font-size: 12px;
    line-height: 1.1;
}

.user-box-text small {
    font-size: 11px;
    color: #64748b;
    line-height: 1.1;
}

.steps {
    margin: 0 0 20px;
    padding: 0;
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.step {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 9px 13px;
    font-size: 13px;
    color: #334155;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.step:hover {
    transform: translateY(-1px);
    border-color: #cfd8e6;
}

.step.active {
    background: var(--brand-red);
    border-color: var(--brand-red);
    color: #fff;
}

.step.done {
    background: var(--success-bg);
    border-color: #bbf7d0;
    color: var(--success-text);
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.card h2 {
    margin: 0 0 16px;
    font-size: 21px;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: #304152;
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #d4dbe6;
    border-radius: 11px;
    background: #fff;
    color: var(--text-main);
    padding: 11px 12px;
    font-size: 14px;
    line-height: 1.35;
    outline: none;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input::placeholder,
textarea::placeholder {
    color: #9aa5b1;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #e18d97;
    box-shadow: 0 0 0 3px rgba(209, 11, 31, 0.12);
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    margin: 0;
    padding: 0;
    accent-color: var(--brand-red);
}

textarea {
    min-height: 138px;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.tabs label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 0;
    font-weight: 500;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.button-row.align-end {
    align-items: end;
}

.primary-btn,
.secondary-btn {
    appearance: none;
    border-radius: 12px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.primary-btn {
    border: none;
    background: var(--brand-red);
    color: #fff;
    box-shadow: 0 10px 20px rgba(209, 11, 31, 0.25);
}

.primary-btn:hover {
    background: var(--brand-red-hover);
    transform: translateY(-1px);
}

.secondary-btn {
    border: 1px solid #d3dae5;
    background: #ffffff;
    color: #111827;
}

.secondary-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-xs);
}

.as-link {
    display: inline-flex;
    align-items: center;
}

.notice {
    margin-bottom: 12px;
    background: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid #f7d7a8;
    border-left: 4px solid #ef9b32;
    border-radius: 10px;
    padding: 11px 12px;
    line-height: 1.4;
}

.system-chat {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - 260px);
    overflow: auto;
    padding-right: 6px;
}

.system-chat::-webkit-scrollbar {
    width: 10px;
}

.system-chat::-webkit-scrollbar-thumb {
    background: #d6ddea;
    border-radius: 999px;
    border: 3px solid transparent;
    background-clip: padding-box;
}

.chat-message {
    border: 1px solid var(--line);
    background: #ffffff;
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: var(--shadow-xs);
    font-size: 14px;
    line-height: 1.4;
}

.chat-message .chat-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
    color: #475569;
}

.chat-message.success {
    border-color: #b9ebca;
    background: #f0fcf5;
}

.chat-message.warning {
    border-color: #f7d7a8;
    background: #fff9ed;
}

.chat-message.error {
    border-color: #f2b7bf;
    background: #fff1f3;
}

.folder-list {
    display: grid;
    gap: 10px;
}

.folder-item {
    border: 1px solid #d3dae5;
    border-radius: 12px;
    background: #fff;
    padding: 12px 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.folder-item.as-link {
    display: block;
}

.folder-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-xs);
}

.folder-item.active {
    border-color: var(--brand-red);
    background: #fff8f8;
}

.folder-title {
    font-weight: 700;
    font-size: 15px;
    color: #111827;
}

.folder-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.folder-icon {
    font-size: 16px;
    line-height: 1;
}

.folder-domain {
    letter-spacing: -0.01em;
}

.folder-subtitle {
    display: block;
    margin-top: 4px;
    color: #526274;
    font-size: 13px;
}

.contracts-search-block {
    margin-bottom: 14px;
}

.client-contact-big {
    font-size: 22px;
    font-weight: 700;
    color: #111827;
}

.highlight-box {
    background: #fff8ef;
    border: 1px solid #f4d7b2;
    border-radius: 14px;
    padding: 14px;
    line-height: 1.45;
}

.kv-grid {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 10px 14px;
    align-items: start;
}

.kv-key {
    color: #526274;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.kv-val {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 14px;
    color: #111827;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid transparent;
}

.kv-val.status-found_exact,
.legend-item.status-found_exact {
    background: #ecfdf3;
    border-color: #86efac;
}

.kv-val.status-found_by_pattern,
.legend-item.status-found_by_pattern {
    background: #eff6ff;
    border-color: #93c5fd;
}

.kv-val.status-generated,
.legend-item.status-generated {
    background: #fff7ed;
    border-color: #fdba74;
}

.kv-val.status-needs_review,
.legend-item.status-needs_review {
    background: #fff1f2;
    border-color: #fda4af;
}

.kv-val.status-missing,
.legend-item.status-missing {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.status-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 22px 12px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    border: 1px solid;
    font-size: 12px;
    font-weight: 600;
}

.json-preview-title {
    margin: 12px 22px 8px;
    font-size: 14px;
    color: #334155;
}

.json-preview {
    margin: 0 22px 10px;
    background: #0b1220;
    color: #e2e8f0;
    border-radius: 12px;
    border: 1px solid #1f2937;
    padding: 12px;
    font-size: 12px;
    line-height: 1.45;
    overflow-x: auto;
}

.hint {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-soft);
}

.hints-card {
    background:
        radial-gradient(circle at 100% 100%, rgba(234, 18, 40, 0.05) 0, rgba(234, 18, 40, 0) 48%),
        #fff;
}

.hints-list {
    display: grid;
    gap: 12px;
}

.hint-item {
    border: 1px solid #eceff5;
    border-radius: 12px;
    padding: 10px 11px;
    background: #ffffff;
}

.hint-item strong {
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
    color: #111827;
}

.hint-item span {
    display: block;
    color: #5f6d7c;
    font-size: 13px;
    line-height: 1.4;
}

details.card {
    padding: 0;
}

details.card > *:not(summary) {
    padding: 0 22px 22px;
}

.details-summary {
    cursor: pointer;
    user-select: none;
    padding: 18px 22px;
    font-weight: 700;
    list-style: none;
}

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

.details-summary::after {
    content: "▾";
    float: right;
    color: #64748b;
}

details[open] .details-summary::after {
    content: "▴";
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.compare-table thead th {
    background: var(--bg-soft);
    color: #334155;
    font-weight: 600;
}

.compare-table th,
.compare-table td {
    border: 1px solid #eceff4;
    padding: 10px 11px;
    text-align: left;
    font-size: 14px;
}

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

/* Responsive */
@media (max-width: 1120px) {
    .content {
        padding: 26px 22px 28px;
    }
}

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

    .sidebar {
        width: 100%;
        min-width: 100%;
    }

    .content {
        width: 100%;
        padding: 20px 16px 22px;
    }

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

    .content-side {
        position: static;
    }

    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

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