:root {
    --background: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #172033;
    --text-secondary: #667085;
    --border: #dfe4ea;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --success: #157347;
    --success-bg: #e9f8f0;
    --warning: #9a5b00;
    --warning-bg: #fff5dc;
    --danger: #b42318;
    --danger-bg: #fef0ef;
    --sidebar: #111827;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .04);
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--background); }
body { margin: 0; color: var(--text); background: var(--background); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }
button, input, select { font: inherit; }
button, a, input, select, summary { outline-offset: 3px; }
:focus-visible { outline: 3px solid rgba(37, 99, 235, .35); }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(26px, 3vw, 34px); line-height: 1.2; letter-spacing: -.025em; }
h2 { margin-bottom: 16px; font-size: 19px; }
h3 { font-size: 16px; }
code { padding: 2px 5px; border-radius: 5px; background: #edf1f5; }

.page-loading { position: fixed; z-index: 100; top: 0; left: 0; width: 0; height: 3px; background: var(--accent); opacity: 0; transition: width .25s, opacity .2s; }
.page-loading.is-active { width: 70%; opacity: 1; }
.app-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.app-shell--guest { display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 32px 16px; }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 24px 16px; color: #d7deea; background: var(--sidebar); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: white; font-size: 18px; font-weight: 750; }
.brand:hover { color: white; }
.brand__mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: white; background: var(--accent); font-size: 13px; font-weight: 800; letter-spacing: .04em; }
.nav { display: grid; gap: 4px; margin-top: 32px; }
.nav__link { padding: 11px 12px; border-radius: 8px; color: #aeb8c8; font-weight: 650; }
.nav__link:hover, .nav__link.is-active { color: white; background: #263244; }
.sidebar__footer { display: grid; gap: 12px; margin-top: auto; padding: 16px 8px 0; border-top: 1px solid #2b3647; }
.sidebar__user { overflow: hidden; color: white; text-overflow: ellipsis; white-space: nowrap; }
.main-content { width: 100%; max-width: 1600px; margin: 0 auto; padding: 32px; }
.app-shell--guest .main-content { max-width: 560px; padding: 0; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-header p { margin-bottom: 0; color: var(--text-secondary); }
.page-header--compact { align-items: center; }
.eyebrow { margin-bottom: 6px !important; color: var(--accent) !important; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 16px; font-weight: 650; }
.panel { margin-bottom: 24px; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-header h2 { margin-bottom: 0; }
.section-header > span { color: var(--text-secondary); }

.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-weight: 700; line-height: 1.2; transition: background .15s, border-color .15s; }
.button--primary { color: white; background: var(--accent); }
.button--primary:hover { color: white; background: var(--accent-dark); }
.button--secondary { color: #24436f; border-color: #b9cae2; background: #eef4fc; }
.button--secondary:hover { color: #18345c; background: #e3ecf8; }
.button--ghost { color: var(--text); border-color: var(--border); background: transparent; }
.sidebar .button--ghost { color: #d7deea; border-color: #48556a; }
.button--warning { color: var(--warning); border-color: #eed59f; background: var(--warning-bg); }
.button--small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.button--full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .55; }

.alert { margin-bottom: 24px; padding: 14px 16px; border: 1px solid; border-radius: 10px; }
.alert ul { margin: 8px 0 0; padding-left: 20px; }
.alert--success { color: var(--success); border-color: #b9e5cc; background: var(--success-bg); }
.alert--danger { color: var(--danger); border-color: #f0c1bd; background: var(--danger-bg); }
.auth-card { width: 100%; padding: 32px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card__heading { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.auth-card__heading p, .auth-card--center p { color: var(--text-secondary); }
.auth-card__switch { margin: 24px 0 0; text-align: center; }
.auth-card--center { text-align: center; }
.state-icon { display: grid; width: 52px; height: 52px; place-items: center; margin: 0 auto 16px; border-radius: 50%; color: var(--accent); background: #eaf1ff; font-size: 24px; font-weight: 800; }
.form-stack { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; min-width: 0; color: #344054; font-size: 13px; font-weight: 700; }
.field input, .field select { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cbd3dc; border-radius: 8px; color: var(--text); background: white; }
.field input::placeholder { color: #98a2b3; font-weight: 400; }
.field__error { color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.field-help { color: var(--text-secondary); font-size: 13px; font-weight: 400; }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric { display: grid; gap: 6px; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.metric span { color: var(--text-secondary); font-size: 13px; }
.metric strong { font-size: 28px; letter-spacing: -.03em; }
.compact-post { display: grid; grid-template-columns: minmax(130px, .6fr) minmax(220px, 2fr) auto; gap: 16px; padding: 14px 0; border-top: 1px solid var(--border); color: var(--text); }
.compact-post__source { font-weight: 700; }
.compact-post__text { overflow: hidden; color: var(--text-secondary); text-overflow: ellipsis; white-space: nowrap; }
.compact-post time { color: var(--text-secondary); font-size: 13px; }

.metrics--import { grid-template-columns: repeat(5, minmax(0, 1fr)); margin: 24px 0; }
.import-control__hint { margin-bottom: 0; }
.import-progress { height: 14px; overflow: hidden; border-radius: 999px; background: #e7ecf2; }
.import-progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .3s ease; }
.import-progress__label { margin: 10px 0 0; color: var(--text-secondary); }
.import-progress__label strong { color: var(--text); }
.import-live { min-height: 24px; margin-top: 14px; color: var(--text-secondary); }
.import-live.is-error { color: var(--danger); }
.worker-state { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-soft); }
.worker-state__indicator { width: 10px; height: 10px; margin-top: 6px; flex: 0 0 auto; border-radius: 50%; background: #98a2b3; }
.worker-state--online .worker-state__indicator { background: var(--success); box-shadow: 0 0 0 4px var(--success-bg); }
.worker-state p { margin: 3px 0 0; color: var(--text-secondary); }
.import-diagnostic { margin-top: 16px; padding: 14px 16px; border: 1px solid #eed59f; border-radius: 10px; background: var(--warning-bg); }
.import-diagnostic p { margin: 4px 0 8px; color: #6f4608; }
.import-diagnostic__meta { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; }
.import-diagnostic__meta span { color: var(--text-secondary); }
.import-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.import-grid > .panel { min-width: 0; }
.import-summary__grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin: 0; }
.import-summary__grid div { display: grid; gap: 4px; }
.import-summary__grid dt { color: var(--text-secondary); font-size: 13px; }
.import-summary__grid dd { margin: 0; font-size: 22px; font-weight: 750; }
.steps-list { margin: 0; padding-left: 22px; }
.steps-list li + li { margin-top: 10px; }
.import-private-note { margin: 20px 0 0; }

.filters { padding-bottom: 16px; }
.filters__primary { display: flex; align-items: end; gap: 12px; margin-bottom: 20px; }
.field--search { flex: 1; }
.filters__grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 16px; }
.filters__footer { display: flex; justify-content: flex-end; margin-top: 16px; }
.filter-notice { margin: -8px 0 24px; padding: 12px 16px; border: 1px solid #bcd0ee; border-radius: 10px; color: #254d82; background: #edf4ff; }
.table-panel { padding: 0; overflow: hidden; }
.table-panel > .section-header { padding: 20px 24px 0; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { padding: 12px 16px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); color: var(--text-secondary); background: var(--surface-soft); font-size: 12px; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
.data-table td { max-width: 420px; padding: 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table small { display: block; margin-top: 3px; color: var(--text-secondary); }
.source-name { display: block; max-width: 180px; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.post-preview { display: -webkit-box; overflow: hidden; margin: 0; white-space: pre-line; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; color: #475467; background: #eef1f4; font-size: 12px; font-weight: 750; white-space: nowrap; }
.badge--active { color: var(--success); background: var(--success-bg); }
.badge--hidden { color: var(--warning); background: var(--warning-bg); }
.badge--archived { color: #475467; background: #eaecf0; }
.badge--neutral { color: #475467; background: #eef1f4; }
.duplicate-link { font-size: 13px; font-weight: 750; white-space: nowrap; }
.muted { color: var(--text-secondary); }
.empty-state { padding: 48px 24px; text-align: center; }
.empty-state p { color: var(--text-secondary); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 24px; border-top: 1px solid var(--border); }
.pagination a { font-weight: 700; }
.pagination__disabled { color: #98a2b3; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .85fr); gap: 24px; }
.full-text { max-width: 850px; white-space: pre-wrap; overflow-wrap: anywhere; }
.media-box { margin-top: 24px; padding: 16px; border-radius: 8px; background: var(--surface-soft); }
.meta-list { display: grid; gap: 12px; margin: 0 0 24px; }
.meta-list div { display: grid; gap: 2px; }
.meta-list dt { color: var(--text-secondary); font-size: 12px; }
.meta-list dd { margin: 0; font-weight: 650; }
.meta-list--inline { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 20px; }
.status-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.technical-details summary { cursor: pointer; font-weight: 750; }
.technical-details pre { max-height: 520px; overflow: auto; padding: 16px; border-radius: 8px; color: #dbe6f5; background: #111827; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.break-all { word-break: break-all; }
.duplicate-stack { display: grid; gap: 16px; }
.duplicate-card { margin-bottom: 0; }
.duplicate-card--canonical { border-left: 4px solid var(--success); }
.duplicate-card__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.duplicate-card__header > div { display: flex; align-items: center; gap: 10px; }
.duplicate-card time { color: var(--text-secondary); font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
    .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filters__grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
    .detail-grid { grid-template-columns: 1fr; }
    .metrics--import { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; height: auto; padding: 14px 16px; }
    .brand { padding: 0; }
    .nav { grid-template-columns: 1fr 1fr; margin-top: 12px; }
    .sidebar__footer { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 12px 0 0; }
    .sidebar__footer form { width: auto; }
    .main-content { padding: 24px 16px; }
    .page-header, .filters__primary, .duplicate-card__header { align-items: stretch; flex-direction: column; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters__grid { grid-template-columns: 1fr; }
    .filters__primary .button { width: 100%; }
    .compact-post { grid-template-columns: 1fr; gap: 4px; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
    .data-table td { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 12px; max-width: none; padding: 6px 0; border: 0; }
    .data-table td::before { content: attr(data-label); color: var(--text-secondary); font-size: 12px; font-weight: 700; }
    .meta-list--inline { grid-template-columns: 1fr; }
    .import-grid, .import-summary__grid { grid-template-columns: 1fr; }
    .pagination { flex-wrap: wrap; }
}

@media (max-width: 440px) {
    .metrics { grid-template-columns: 1fr; }
    .panel, .auth-card { padding: 20px; }
    .table-panel { padding: 0; }
    .data-table td { grid-template-columns: 84px minmax(0, 1fr); }
    .metrics--import { grid-template-columns: 1fr; }
}
