/* ── Reset & Base ── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e4e7ec;
    --border-2: #d0d5dd;
    --text: #101828;
    --text-2: #344054;
    --muted: #667085;
    --muted-2: #98a2b3;
    --accent: #2563eb;
    --accent-h: #1d4ed8;
    --accent-lite: #eff6ff;
    --green: #12b76a;
    --green-lite: #ecfdf3;
    --red: #f04438;
    --red-lite: #fef3f2;
    --amber: #f79009;
    --amber-lite: #fffaeb;
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 224px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.1), 0 1px 2px rgba(16, 24, 40, 0.06);
}

body {
    font-family:
        "Inter",
        -apple-system,
        BlinkMacSystemFont,
        sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}
button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    background: none;
}
input,
textarea {
    font-family: inherit;
    font-size: 14px;
}
.hidden {
    display: none !important;
}

/* ── Screens ── */
.screen {
    width: 100%;
    min-height: 100vh;
}

/* ── Login ── */
.screen-login {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 360px;
    text-align: center;
    box-shadow: var(--shadow);
}
.login-logo {
    margin-bottom: 0.5rem;
}
.login-wordmark {
    font-family: "DM Serif Display", serif;
    font-size: 2rem;
    color: var(--text);
    letter-spacing: -0.5px;
}
.login-sub {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-left: 4px;
    vertical-align: super;
}
.login-desc {
    color: var(--muted);
    margin-bottom: 2rem;
    font-size: 0.875rem;
}
.btn-github {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: #24292f;
    color: #fff;
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.btn-github:hover {
    background: #3d444d;
}

/* ── App Shell ── */
.screen-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    transition:
        width 0.2s,
        min-width 0.2s;
}
.sidebar.collapsed {
    width: 56px;
    min-width: 56px;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-wordmark {
    font-family: "DM Serif Display", serif;
    font-size: 1.1rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-press {
    color: var(--accent);
    font-size: 0.65rem;
    font-family: "Inter", sans-serif;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    vertical-align: super;
    margin-left: 2px;
}
.sidebar-toggle {
    color: var(--muted);
    padding: 4px;
    border-radius: 4px;
    flex-shrink: 0;
}
.sidebar-toggle:hover {
    background: var(--surface-2);
    color: var(--text);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.nav-section {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted-2);
    padding: 0 0.5rem;
    margin-bottom: 4px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.625rem;
    border-radius: 6px;
    color: var(--text-2);
    font-weight: 500;
    font-size: 0.8125rem;
    transition:
        background 0.1s,
        color 0.1s;
    white-space: nowrap;
    overflow: hidden;
}
.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.nav-item.active {
    background: var(--accent-lite);
    color: var(--accent);
}
.nav-item svg {
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.user-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}
.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
}
.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.user-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    truncate: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}
.user-role {
    font-size: 0.7rem;
    color: var(--muted);
    white-space: nowrap;
}
.btn-icon {
    padding: 4px;
    border-radius: 4px;
    color: var(--muted);
    flex-shrink: 0;
}
.btn-icon:hover {
    background: var(--surface-2);
    color: var(--red);
}

/* ── Main Content ── */
.main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ── Views ── */
.view {
    flex: 1;
    padding: 2rem 2.5rem;
    max-width: 1100px;
    width: 100%;
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    gap: 1rem;
}
.view-title {
    font-family: "DM Serif Display", serif;
    font-size: 1.5rem;
    color: var(--text);
    font-weight: 400;
}
.view-meta {
    font-size: 0.8125rem;
    color: var(--muted);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 500;
    transition:
        background 0.15s,
        border-color 0.15s,
        color 0.15s;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--accent-h);
}
.btn-outline {
    background: var(--surface);
    color: var(--text-2);
    border: 1px solid var(--border-2);
}
.btn-outline:hover {
    background: var(--surface-2);
}
.btn-ghost {
    background: transparent;
    color: var(--muted);
}
.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}
.btn-danger {
    background: var(--red-lite);
    color: var(--red);
}
.btn-danger:hover {
    background: var(--red);
    color: #fff;
}
.btn-sm {
    padding: 0.3rem 0.625rem;
    font-size: 0.75rem;
}

/* ── Source Health ── */
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.health-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.health-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.health-source-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-dot.ok {
    background: var(--green);
    box-shadow: 0 0 0 3px var(--green-lite);
}
.status-dot.blocked {
    background: var(--red);
    box-shadow: 0 0 0 3px var(--red-lite);
}
.status-dot.error {
    background: var(--amber);
    box-shadow: 0 0 0 3px var(--amber-lite);
}
.status-dot.pending {
    background: var(--muted-2);
}
.health-fetched {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
}
.health-fetched-label {
    font-size: 0.75rem;
    color: var(--muted);
}
.health-last {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.5rem;
}

.failed-ingest-banner {
    background: var(--red-lite);
    border: 1px solid #fda29b;
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.banner-content {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--red);
}
.banner-content strong {
    font-weight: 600;
    margin-right: 0.25rem;
}
.banner-content span {
    color: var(--text-2);
    font-size: 0.8125rem;
}

/* ── Article Lists ── */
.article-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.article-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s;
}
.article-row:hover {
    border-color: var(--border-2);
}
.article-row.pinned {
    border-left: 3px solid var(--accent);
}
.article-row.hidden-article {
    opacity: 0.5;
}

.article-row-main {
    flex: 1;
    min-width: 0;
}
.article-row-title {
    font-weight: 500;
    color: var(--text);
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.article-row-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

.source-badge {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.source-badge.primary {
    background: var(--accent-lite);
    color: var(--accent);
}
.source-badge.warning {
    background: var(--amber-lite);
    color: var(--amber);
}
.source-badge.success {
    background: var(--green-lite);
    color: var(--green);
}
.source-badge.info {
    background: #eff8ff;
    color: #0086c9;
}
.source-badge.secondary {
    background: var(--surface-2);
    color: var(--muted);
}

.article-date {
    font-size: 0.75rem;
    color: var(--muted);
}

.article-row-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.status-chip {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    text-transform: capitalize;
}
.status-chip.published {
    background: var(--green-lite);
    color: var(--green);
}
.status-chip.draft {
    background: var(--surface-2);
    color: var(--muted);
}
.status-chip.scheduled {
    background: var(--amber-lite);
    color: var(--amber);
}

/* Icon buttons in rows */
.icon-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--muted);
    transition:
        background 0.1s,
        color 0.1s;
}
.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}
.icon-btn.active {
    color: var(--accent);
}
.icon-btn.danger:hover {
    background: var(--red-lite);
    color: var(--red);
}

/* ── Ingest ── */
.ingest-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-width: 600px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}
.toggle-group {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    padding: 3px;
    border-radius: 6px;
    width: fit-content;
}
.toggle-btn {
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
}
.toggle-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}
.ingest-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.ingest-status {
    font-size: 0.8125rem;
    color: var(--muted);
}
.ingest-status.running {
    color: var(--accent);
}
.ingest-status.success {
    color: var(--green);
}
.ingest-status.error {
    color: var(--red);
}

/* ── Form Fields ── */
.field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.field-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-2);
}
.field-optional {
    font-weight: 400;
    color: var(--muted);
}
.input {
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    color: var(--text);
    background: var(--surface);
    outline: none;
    width: 100%;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}
.input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.input-sm {
    padding: 0.35rem 0.625rem;
    font-size: 0.8125rem;
}
.input-textarea {
    min-height: 140px;
    resize: vertical;
}
.input-textarea-sm {
    min-height: 72px;
    resize: vertical;
}
.toggle {
    width: 36px;
    height: 20px;
    appearance: none;
    background: var(--border-2);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
}
.toggle:checked {
    background: var(--accent);
}
.toggle::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: left 0.2s;
    box-shadow: var(--shadow-sm);
}
.toggle:checked::after {
    left: 18px;
}

/* ── Editor ── */
.editor-header {
    justify-content: space-between;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
    padding-top: 1rem;
    padding-left: 2.5rem;
    padding-right: 2.5rem;
    margin-left: -2.5rem;
    margin-right: -2.5rem;
    width: calc(100% + 5rem);
}
.editor-actions {
    display: flex;
    gap: 0.5rem;
}
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 2rem;
    padding-top: 1.5rem;
}
.editor-main {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
}
.editor-title-input {
    border: none;
    outline: none;
    font-family: "DM Serif Display", serif;
    font-size: 2rem;
    color: var(--text);
    background: transparent;
    width: 100%;
    padding: 0.5rem 0;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s;
}
.editor-title-input:focus {
    border-color: var(--border);
}
.editor-title-input::placeholder {
    color: var(--muted-2);
}
.editor-summary-input {
    border: none;
    outline: none;
    font-size: 1rem;
    color: var(--muted);
    background: transparent;
    width: 100%;
    padding: 0.5rem 0 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}
.editor-summary-input::placeholder {
    color: var(--muted-2);
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    flex-wrap: wrap;
    position: sticky;
    top: 61px;
    background: var(--bg);
    z-index: 9;
}
.toolbar-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-2);
    transition: background 0.1s;
}
.toolbar-btn:hover {
    background: var(--surface-2);
}
.toolbar-btn.is-active {
    background: var(--accent-lite);
    color: var(--accent);
}
.toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 2px;
}

.editor-body {
    min-height: 400px;
    padding: 1.25rem 0;
    outline: none;
    font-size: 0.9375rem;
    line-height: 1.75;
    color: var(--text);
}
/* Tiptap styles */
.editor-body .ProseMirror {
    outline: none;
}
.editor-body .ProseMirror p {
    margin-bottom: 1rem;
}
.editor-body .ProseMirror h2 {
    font-family: "DM Serif Display", serif;
    font-size: 1.35rem;
    font-weight: 400;
    margin: 1.75rem 0 0.75rem;
}
.editor-body .ProseMirror h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 1.5rem 0 0.5rem;
}
.editor-body .ProseMirror ul,
.editor-body .ProseMirror ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}
.editor-body .ProseMirror li {
    margin-bottom: 0.25rem;
}
.editor-body .ProseMirror blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    color: var(--muted);
    margin: 1.25rem 0;
}
.editor-body .ProseMirror code {
    background: var(--surface-2);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: "SF Mono", "Fira Code", monospace;
}
.editor-body .ProseMirror pre {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
}
.editor-body .ProseMirror pre code {
    background: none;
    padding: 0;
}
.editor-body .ProseMirror img {
    max-width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.editor-body .ProseMirror hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}
.editor-body .ProseMirror a {
    color: var(--accent);
    text-decoration: underline;
}
.editor-body .ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    color: var(--muted-2);
    pointer-events: none;
    float: left;
    height: 0;
}

/* Editor sidebar panels */
.editor-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.editor-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.panel-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--muted);
}
.meta-row span:last-child {
    color: var(--text-2);
    font-weight: 500;
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 0.625rem 1.125rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 500;
    z-index: 1000;
    box-shadow: var(--shadow);
    white-space: nowrap;
}
.toast.success {
    background: var(--green);
}
.toast.error {
    background: var(--red);
}

/* ── Empty states ── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}
.empty-state svg {
    margin-bottom: 0.75rem;
    opacity: 0.4;
}
.empty-state p {
    font-size: 0.875rem;
}

/* ── Loading ── */
.loading-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    color: var(--muted);
    font-size: 0.8125rem;
    animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}
