:root {
    --font-bump: 0px;
    --btn-height: 36px;
    --bg-app: #ffffff;
    --bg-sidebar: #f8fafc;
    --border: #e5e7eb;
    --text-main: #111827;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --warning-bg: #fffbeb;
    --warning-text: #92400e;
    --danger-bg: #fee2e2;
    --danger-text: #991b1b;
    --info-bg: #dbeafe;
    --info-text: #1d4ed8;
}

@media (max-width: 768px) {
    :root {
        --font-bump: 2px;
        --btn-height: 42px;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: calc(14px + var(--font-bump));
    line-height: 1.45;
    color: var(--text-main);
    background: var(--bg-app);
}

.ui-page.with-topbar {
    padding-top: 0;
    padding-bottom: 20px;
}

.ui-container {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.ui-header {
    margin-bottom: 14px;
}

.ui-header h1 {
    margin: 0;
    font-size: calc(24px + var(--font-bump));
    font-weight: 700;
}

.ui-topbar {
    position: relative;
    padding: 16px 0 12px;
    background: transparent;
    border-bottom: 0;
    z-index: 10;
}

.ui-topbar-inner {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    min-height: 74px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.ui-topbar-title {
    min-width: 0;
    font-size: calc(24px + var(--font-bump));
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ui-topbar-heading {
    min-width: 0;
}

.ui-topbar-subtitle {
    margin-top: 3px;
    font-size: calc(12px + var(--font-bump));
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ui-project-selector {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
}

.ui-project-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    padding: 8px 10px;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.ui-project-toggle-btn:hover {
    background: #f8fafc;
}

.ui-project-toggle-btn:focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}

.ui-logo-img {
    display: block;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    aspect-ratio: 1 / 1;
    border-radius: 0;
    object-fit: contain;
    background: #fff;
}

.ui-project-name {
    font-size: calc(13px + var(--font-bump));
    font-weight: 600;
}

.ui-project-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.ui-project-trigger svg {
    display: block;
}

.ui-project-trigger.active {
    transform: rotate(90deg);
}

.ui-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);
    width: 270px;
    max-width: calc(100vw - 16px);
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 16px 30px rgba(15, 23, 42, 0.12);
    padding: 6px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: 0.2s ease;
    z-index: 1100;
}

.ui-dropdown.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.ui-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #111827;
    font-size: calc(14px + var(--font-bump));
    padding: 10px 12px;
    border-radius: 10px;
}

.ui-dropdown a + a {
    border-top: 1px solid #f1f5f9;
}

.ui-dropdown a:hover {
    background: #f8fafc;
}

.svg-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #111827;
}

.ui-card {
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    padding: 16px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.ui-card-title {
    margin: 0 0 10px;
    font-size: calc(18px + var(--font-bump));
    font-weight: 700;
}

.demo-mode-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    border: 1px solid #93c5fd;
    border-radius: 14px;
    background: #eff6ff;
    padding: 14px 16px;
    color: #1e3a8a;
}

.demo-mode-banner[hidden] {
    display: none;
}

.demo-mode-banner strong,
.demo-mode-banner span {
    display: block;
}

.demo-mode-banner span {
    margin-top: 2px;
    font-size: calc(13px + var(--font-bump));
    color: #1d4ed8;
}

.entity-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.entity-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 98px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    transition: 0.15s ease;
}

.entity-card:hover {
    border-color: #9ca3af;
}

#entity-deal:checked ~ .entity-cards label[for='entity-deal'],
#entity-smart:checked ~ .entity-cards label[for='entity-smart'] {
    background: #e0e7ff;
    border-color: #c7d2fe;
    color: #1d4ed8;
    font-weight: 600;
}

.entity-card-icon {
    font-size: 24px;
    line-height: 1;
}

.entity-card-title {
    font-size: calc(14px + var(--font-bump));
}

input[type='radio'][name='entity'] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

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

.ui-form-group {
    margin-bottom: 12px;
}

.ui-form-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
}

.ui-label {
    color: #374151;
    font-size: calc(13px + var(--font-bump));
}

.ui-hint {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: calc(12px + var(--font-bump));
}

.ui-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #374151;
    cursor: pointer;
}

.ui-radio input {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid #d1d5db;
    background: #fff;
    margin: 0;
    position: relative;
}

.ui-radio input:checked {
    border-color: var(--primary);
}

.ui-radio input:checked::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.file-upload-area {
    border: 1px dashed #d1d5db;
    border-radius: 10px;
    padding: 16px;
    background: #fff;
    margin-bottom: 12px;
}

.file-upload-area:hover,
.file-upload-area.is-dragover {
    border-color: #93c5fd;
    background: #eff6ff;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.upload-icon {
    font-size: 30px;
}

.upload-text {
    color: #374151;
    font-size: calc(14px + var(--font-bump));
}

.upload-button {
    pointer-events: none;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    font-size: calc(13px + var(--font-bump));
    color: #374151;
}

.file-name {
    max-width: min(360px, 100%);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-clear {
    border: none;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 6px;
    width: var(--btn-height);
    height: var(--btn-height);
    min-height: var(--btn-height);
    padding: 0;
    cursor: pointer;
    font-size: calc(16px + var(--font-bump));
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.file-clear:hover {
    background: #fecaca;
}

.ui-btn {
    min-height: var(--btn-height);
    padding: 0 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: calc(14px + var(--font-bump));
    line-height: 1.1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ui-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ui-btn-primary {
    color: #fff;
    background: var(--primary);
}

.ui-btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.ui-btn-light {
    color: #374151;
    background: #fff;
    border-color: #d1d5db;
}

.ui-btn-light:hover:not(:disabled) {
    border-color: #9ca3af;
    color: #111827;
}

.ui-btn-ghost {
    color: var(--primary);
    background: #eff6ff;
    border-color: #bfdbfe;
}

.ui-btn-ghost:hover:not(:disabled) {
    background: #dbeafe;
}

.ui-input {
    width: 100%;
    min-height: var(--btn-height);
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0 10px;
    font-family: inherit;
    font-size: calc(14px + var(--font-bump));
    color: #111827;
    background: #fff;
}

.ui-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

select.ui-input {
    appearance: none;
    padding-right: 30px;
    background-image:
        linear-gradient(45deg, transparent 50%, #6b7280 50%),
        linear-gradient(135deg, #6b7280 50%, transparent 50%);
    background-position:
        calc(100% - 16px) 50%,
        calc(100% - 11px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.ui-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.preview-controls {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.preview-controls-left,
.preview-controls-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-page-size {
    width: 92px;
    min-width: 92px;
}

.ui-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
    font-size: calc(14px + var(--font-bump));
}

.ui-table th,
.ui-table td {
    border-bottom: 1px solid var(--border);
    padding: 10px;
    text-align: left;
    vertical-align: middle;
}

.ui-table th {
    background: #f9fafb;
    font-weight: 600;
}

.ui-table tbody tr:hover td {
    background: #f8fafc;
}

.status-cell {
    white-space: nowrap;
}

.ui-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    min-height: 30px;
    padding: 0 14px;
    font-size: calc(14px + var(--font-bump));
    font-weight: 400;
    border: 1.5px solid transparent;
    line-height: 1;
}

.ui-badge-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: #86efac;
}

.ui-badge-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-color: #fde68a;
}

.ui-badge-danger {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: #fca5a5;
}

.ui-badge-info {
    background: var(--info-bg);
    color: var(--info-text);
    border-color: #93c5fd;
}

.ui-loader {
    margin-top: 10px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #374151;
}

.ui-spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #e5e7eb;
    border-top-color: var(--primary);
    animation: spin 0.7s linear infinite;
}

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

.log-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    padding: 10px;
    font-size: calc(13px + var(--font-bump));
    line-height: 1.45;
}

.log-container > div {
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 6px;
    border: 1px solid #f1f5f9;
    background: #fff;
}

.log-container > div:last-child {
    margin-bottom: 0;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.stat-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    padding: 12px;
}

.stat-value {
    margin-top: 8px;
    font-size: calc(22px + var(--font-bump));
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: calc(13px + var(--font-bump));
    color: var(--text-muted);
}

.stat-card.success .stat-value {
    color: var(--success-text);
}

.stat-card.warning .stat-value {
    color: var(--warning-text);
}

.stat-card.danger .stat-value {
    color: var(--danger-text);
}

.ui-toast-container {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ui-toast {
    border-radius: 10px;
    padding: 10px 12px;
    font-size: calc(13px + var(--font-bump));
    line-height: 1.45;
    border: 1px solid transparent;
    background: #fff;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ui-toast-success {
    background: #ecfdf3;
    border-color: #bbf7d0;
    color: #166534;
}

.ui-toast-warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

.ui-toast-error {
    background: #fee2e2;
    border-color: #fecaca;
    color: #7f1d1d;
}

.ui-toast-info {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
}

@media (max-width: 960px) {
    .stats-cards {
        grid-template-columns: 1fr;
    }

    .entity-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .ui-page.with-topbar {
        padding-top: 0;
    }

    .ui-container {
        width: calc(100% - 20px);
    }

    .demo-mode-banner {
        align-items: stretch;
        flex-direction: column;
    }

    .ui-topbar {
        padding: 10px 0;
    }

    .ui-topbar-inner {
        width: calc(100% - 20px);
        min-height: 0;
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .ui-project-name {
        display: none;
    }

    .ui-topbar-title {
        font-size: calc(18px + var(--font-bump));
    }

    .ui-topbar-subtitle {
        display: none;
    }

    .ui-dropdown {
        width: min(92vw, 280px);
    }

    .ui-form-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .preview-controls-right {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .ui-header h1 {
        font-size: calc(20px + var(--font-bump));
    }

    .ui-table {
        min-width: 620px;
    }

    .ui-toast-container {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }
}
