@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,400;0,700;1,400&display=swap');

:root {
    --accent: #ff9933;
    --accent-light: #fff3e0;
    --text: #1a1a1a;
    --text-muted: #888;
    --border: #e8e8e8;
    --bg: #ffffff;
    --bg-subtle: #f7f7f7;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

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

/* ── Layout ─────────────────────────────────── */

.page {
    max-width: 960px;
    margin: 0 auto;
    padding: 40px 24px;
}

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

.page-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-logo {
    height: 32px;
    width: 32px;
    object-fit: contain;
    border-radius: 6px;
}

.title-edit-input {
    font-size: inherit;
    font-weight: inherit;
    font-family: inherit;
    border: none;
    border-bottom: 2px solid var(--primary);
    outline: none;
    background: transparent;
    padding: 0;
    min-width: 120px;
    width: auto;
}

.page-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 12px;
    transition: color 0.15s;
    user-select: none;
}

.page-back:hover {
    color: var(--text);
}

/* ── Buttons ─────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}

.btn:hover {
    opacity: 0.85;
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

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

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text);
    border: 1px solid var(--border);
}

/* ── Badges ──────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.badge-draft {
    background: #efefef;
    color: #777;
}

.badge-writing {
    background: #f5f0e0;
    color: #7a5c1e;
}

.badge-ready_to_record {
    background: #f2ede8;
    color: #8a4a2f;
}

.badge-recorded {
    background: #eeeaf5;
    color: #5a4580;
}

.badge-ready {
    background: #e4efe8;
    color: #2d6b45;
}

.badge-published {
    background: #e4efe8;
    color: #2d6b45;
}

.badge-regular {
    background: #e8eef5;
    color: #2c4f7a;
}

.badge-exclusive {
    background: #eeeaf5;
    color: #5a4580;
}

/* ── Table ───────────────────────────────────── */

.table-section {
    margin-bottom: 20px;
}

.table-section-title {
    font-size: 13px;
    font-weight: 600;
    color: #000;
    margin: 0;
    padding: 7px 6px 6px 13px;
    border: 1px solid #f97316;
    background: #f9731608;
    border-radius: 6px 6px 0 0;
}

.table-section-title--collapsible {
  cursor: pointer;
  user-select: none;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
}

.table-section-title--collapsible:hover { color: var(--primary); }

.table-section-chevron {
  font-size: 10px;
  margin-left: 4px;
  color: var(--text-muted);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 10px 12px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

tbody tr.row-set-header td {
    background: var(--bg-subtle);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
}

tbody tr.row-episode:hover td {
    background: #fafafa;
    cursor: pointer;
}

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

.col-date {
    color: var(--text-muted);
}

.date-compact {
    display: none;
}

table.dashboard-table {
    table-layout: fixed;
    width: 100%;
    border: 1px solid var(--border);
    border-top: 0;
}


/* ── Empty state ─────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-muted);
}

.empty-state p {
    margin: 0 0 20px;
    font-size: 15px;
}

/* ── Wizard ──────────────────────────────────── */

.wizard-steps {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 24px;
    font-size: 13px;
    color: var(--text-muted);
}

.wizard-step.active {
    color: var(--text);
    font-weight: 600;
}

.wizard-step.done {
    color: var(--accent);
}

.wizard-step-sep {
    color: var(--border);
}

.wizard-card {
    max-width: 540px;
}

.wizard-actions {
    display: flex;
    gap: 8px;
    margin-top: 28px;
}

/* ── Form fields ─────────────────────────────── */

.field-group {
    margin-bottom: 20px;
}

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
}

.field-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    outline: none;
}

.field-input:focus {
    border-color: var(--accent);
}

.field-readonly {
    background: var(--bg-subtle);
    color: var(--text-muted);
    cursor: default;
}

.req-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    vertical-align: middle;
    margin-left: 4px;
    margin-bottom: 1px;
}

.req-dot-missing {
    background: #f97316;
}

.req-dot-ok {
    background: #22c55e;
}

.section-missing-badge {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: #f97316;
    border-radius: 999px;
    padding: 1px 7px;
    margin-left: 6px;
}

.req-empty-note {
    font-size: 12px;
    color: #f97316;
    font-style: italic;
}

.field-textarea {
    min-height: 100px;
    resize: vertical;
}

.field-preview {
    margin: 6px 0 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
    min-height: 20px;
}

.field-path {
    margin: 0;
    font-size: 13px;
    color: var(--text-muted);
    font-family: monospace;
    word-break: break-all;
}

.field-error {
    margin: 10px 0 0;
    font-size: 13px;
    color: #dc2626;
    min-height: 18px;
}

/* ── Type toggle ─────────────────────────────── */

.type-toggle {
    display: flex;
    gap: 6px;
}

.type-btn {
    background: var(--bg-subtle);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.type-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Folder status ───────────────────────────── */

.folder-status {
    margin: 6px 0 0;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.folder-ok {
    color: #15803d;
}

.folder-missing {
    color: var(--text-muted);
}

.folder-error {
    color: #dc2626;
}

/* ── Existing set notice ─────────────────────── */

.existing-set-notice {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}

.existing-set-notice p {
    margin: 0 0 6px;
}

.existing-set-notice ul {
    margin: 0;
    padding-left: 16px;
}

.existing-set-notice li {
    margin-bottom: 4px;
}

/* ── Small button variant ────────────────────── */

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

.btn-icon {
    padding: 4px 7px;
    font-size: 13px;
    line-height: 1;
    min-width: 28px;
    text-align: center;
    text-decoration: none;
}

.btn-disabled {
    opacity: 0.35;
    pointer-events: none;
}

/* ── Detail page ─────────────────────────────── */

.detail-layout {
    display: flex;
    gap: 40px;
    align-items: flex-start;
}

.detail-main {
    flex: 1;
    min-width: 0;
}

.detail-sidebar {
    flex-shrink: 0;
    width: 240px;
    position: sticky;
    top: 24px;
}

.files-card {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.files-card .detail-section-title {
    margin-bottom: 8px;
}

.files-card-path {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 10px;
    line-height: 1.5;
}

.files-card #btn-open-finder {
    margin-bottom: 8px;
}

.files-card .field-error {
    margin: 4px 0 8px;
    font-size: 12px;
}

.detail-set-label {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.detail-form {
    max-width: 620px;
    margin-bottom: 48px;
}

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

.field-narrow {
    width: 120px;
    flex-shrink: 0;
}

.field-grow {
    flex: 1;
}

.field-medium {
    max-width: 280px;
}

.field-textarea-tall {
    min-height: 140px;
}

.field-hint {
    margin: 5px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.detail-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
}

/* ── Split button ──────────────────────────────── */

.split-btn {
    position: relative;
    display: inline-flex;
    border-radius: 6px;
    overflow: visible;
}

.split-btn__main {
    border-radius: 6px 0 0 6px;
    border-right: 1px solid rgba(0, 0, 0, 0.15);
}

.split-btn__chevron {
    border-radius: 0 6px 6px 0;
    padding: 0 8px;
    font-size: 11px;
}

.split-btn__dropdown {
    display: none;
    position: fixed;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    min-width: 180px;
    overflow: hidden;
}

.split-btn__dropdown.open {
    display: block;
}

.split-btn__dropdown button {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    color: var(--text);
    white-space: nowrap;
}

.split-btn__dropdown button:hover {
    background: var(--bg-subtle);
}

.split-btn__dropdown button:disabled {
    opacity: 0.5;
    cursor: default;
}

.save-feedback {
    font-size: 14px;
    color: #15803d;
    font-weight: 500;
}

.detail-actions .field-error {
    margin: 0;
}

.stale-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 8px 12px;
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 6px;
    font-size: 13px;
    color: #713f12;
}

.stale-bar-text {
    flex: 1;
}

.stale-bar-dismiss {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #713f12;
    padding: 0 4px;
    line-height: 1;
}

/* ── Detail sections (platforms, log) ────────── */

.detail-section {
    margin-bottom: 40px;
    max-width: 620px;
}

.detail-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 12px;
}

.platform-table {
    width: 100%;
    border-collapse: collapse;
}

.platform-table td {
    padding: 9px 12px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

td.platform-name {
    font-weight: 500;
    width: 45%;
    padding-right: 0;
}

.badge-platform-not-scheduled {
    background: #f0f0f0;
    color: #888;
}

.badge-platform-completed {
    background: #dcfce7;
    color: #15803d;
}

.badge-platform-error {
    background: #fee2e2;
    color: #dc2626;
}

.badge-stale {
    background: #fef9c3;
    color: #854d0e;
}

.platform-btn-cell {
    text-align: right;
    white-space: nowrap;
}

.platform-post-link {
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 400;
}

.platform-post-link:hover {
    text-decoration: underline;
}

.platform-meta {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-ig-extra td {
    padding: 2px 8px 6px;
    border-bottom: 1px solid var(--border);
    border-top: none;
}

.sidebar-ig-extra + tr td, .platform-table tr:has(+ .sidebar-ig-extra) td {
    border-bottom: none;
}

.sidebar-checkbox-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
}

.sidebar-checkbox-label input[type="checkbox"] {
    width: 11px;
    height: 11px;
    cursor: pointer;
}

.sidebar-checkbox-label input[type="checkbox"]:disabled {
    cursor: not-allowed;
}

.sidebar-checkbox-label:has(input:disabled) {
    opacity: 0.5;
}

/* ── Action log ──────────────────────────────── */

.action-log-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-log-entry {
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: 0 10px;
    font-size: 13px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    align-items: start;
}

.action-log-entry:last-child {
    border-bottom: none;
}

.action-log-icon {
    font-size: 13px;
    margin-top: 1px;
}

.action-log-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: baseline;
    margin-bottom: 2px;
}

.action-log-platform {
    font-weight: 600;
}

.action-log-action {
    color: var(--text-muted);
}

.action-log-time {
    color: var(--text-muted);
    font-size: 12px;
    margin-left: auto;
}

.action-log-message {
    grid-column: 2;
    color: var(--text-muted);
    font-size: 12px;
    word-break: break-word;
}

/* ── Platform codes ─────────────────────────── */

.platform-codes {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.platform-code-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.platform-code-label {
    font-size: 13px;
    color: var(--text-muted);
    width: 100px;
    flex-shrink: 0;
}

.platform-code-input {
    flex: 1;
}

/* ── Tags ────────────────────────────────────── */

.tag-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px 2px 10px;
    background: #6b7280;
    color: #fff;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}

.tag-chip-remove {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
}

.tag-chip-remove:hover {
    color: #fff;
}

.tag-search-wrap {
    position: relative;
}

.tag-search-input {
    font-size: 12px;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    width: 140px;
}

.tag-autocomplete {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    min-width: 160px;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    overflow: hidden;
}

.tag-autocomplete-item {
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.tag-autocomplete-item:hover,
.tag-autocomplete-item.active {
    background: var(--color-hover, #f3f4f6);
}

.tag-autocomplete-item.create {
    color: #2563eb;
    border-top: 1px solid var(--color-border, #e5e7eb);
}


/* ── File status ─────────────────────────────── */

.file-status-list {
    margin-top: 8px;
}

.file-status-list-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.file-status-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    padding: 3px 0;
}

.file-status-icon {
    font-size: 13px;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.file-ok {
    color: #15803d;
}

.file-missing {
    color: #dc2626;
}

.file-pending {
    color: #d97706;
}

.file-status-label {
    width: 150px;
    flex-shrink: 0;
    color: var(--text);
}

.file-status-filename {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.file-note-display {
    font-size: 12px;
    color: #d97706;
    padding: 2px 0 2px 26px;
}

.file-note-input {
    display: block;
    width: 100%;
    margin-top: 4px;
    margin-left: 26px;
    width: calc(100% - 26px);
    font-size: 12px;
    padding: 3px 6px;
    border: 1px solid #d97706;
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.file-generate-link {
    font-size: 11px;
    color: var(--accent);
    text-decoration: none;
    margin-left: 4px;
}

.file-generate-link:hover {
    text-decoration: underline;
}

/* ── Drag-and-drop reordering ────────────────── */

.drag-handle {
    cursor: grab;
    color: #bbb;
    font-size: 14px;
    padding: 0 6px;
    user-select: none;
}

.row-draggable {
    cursor: default;
}

.row-draggable.dragging {
    opacity: 0.4;
}

.drop-indicator td {
    padding: 0;
    height: 3px;
    background: var(--accent);
}

/* ── Reorder confirmation modal ──────────────── */

.reorder-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.reorder-modal-box {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    max-width: 560px;
    width: 100%;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.reorder-modal-box h3 {
    margin: 0 0 12px;
    font-size: 15px;
}

.reorder-changes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 16px;
}

.reorder-changes-table th {
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid #e5e5e5;
    color: #888;
    font-weight: 500;
}

.reorder-changes-table td {
    padding: 4px 8px;
    border-bottom: 1px solid #f0f0f0;
}

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

/* ── Caption preview ─────────────────────────── */

.caption-preview-text {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 13px;
    min-height: 200px;
    width: 100%;
    box-sizing: border-box;
}

.platform-extra-row td {
    padding: 4px 0 8px 0;
    font-size: 13px;
}

/* ── Inline field (checkbox + label) ─────────── */

.field-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

/* ── Quill rich text editor ──────────────────── */

.rich-editor-wrap {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.rich-editor-wrap .ql-toolbar {
    border: none;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle);
    font-family: inherit;
    padding: 6px 8px;
}

.rich-editor-wrap .ql-container {
    border: none;
    font-family: inherit;
    font-size: 14px;
}

.rich-editor-wrap .ql-editor {
    min-height: 120px;
    padding: 10px 12px;
    line-height: 1.6;
}

.rich-editor-wrap .ql-editor.ql-blank::before {
    color: var(--text-muted);
    font-style: normal;
}

.rich-editor-toolbar-extra {
    position: absolute;
    top: 5px;
    right: 8px;
    z-index: 1;
}

.rich-editor-source {
    font-family: 'DM Mono', 'Fira Mono', monospace;
    font-size: 13px;
    line-height: 1.6;
    min-height: 120px;
    resize: none;
    overflow: hidden;
    border: none;
    border-radius: 0;
}

.rich-editor-source:focus {
    border-color: transparent;
}

/* ── Template editor ─────────────────────────── */

.template-layout {
    display: flex;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    min-height: 500px;
}

.template-nav {
    flex-shrink: 0;
    width: 220px;
    border-right: 1px solid var(--border);
    background: var(--bg-subtle);
    display: flex;
    flex-direction: column;
}

.template-nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    text-align: left;
    padding: 11px 16px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.template-format-badge {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.template-format-html {
    background: #dbeafe;
    color: #1d4ed8;
}

.template-format-text {
    background: #f0f0f0;
    color: #666;
}

.template-nav-item:hover {
    background: var(--bg);
}

.template-nav-item.active {
    background: var(--bg);
    color: var(--accent);
    font-weight: 600;
}

.template-editor {
    flex: 1;
    padding: 24px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.template-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.template-editor-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.template-editor-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.template-textarea {
    font-family: 'DM Mono', 'Fira Mono', monospace;
    font-size: 13px;
    line-height: 1.6;
    min-height: 200px;
    resize: none;
    overflow: hidden;
}

.code-editor-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
}

.code-editor-preview {
    width: 100%;
    min-height: 300px;
    max-height: 70vh;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

#editor-mount .cm-editor {
    border-radius: 6px;
    min-height: 300px;
    max-height: 70vh;
}

.template-vars {
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}

.template-vars-toggle {
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    list-style: none;
    user-select: none;
}

.template-vars-toggle:hover {
    color: var(--text);
}

.template-vars-body {
    padding: 0 12px 12px;
    border-top: 1px solid var(--border);
}

.template-vars-table {
    width: 100%;
    border-collapse: collapse;
}

.template-vars-table td {
    padding: 4px 8px 4px 0;
    border: none;
    font-size: 12px;
    vertical-align: top;
}

.var-pill {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 11px;
    white-space: nowrap;
}

.var-desc {
    color: var(--text-muted);
}

.save-ok {
    font-size: 13px;
    color: #15803d;
}

.save-error {
    font-size: 13px;
    color: #dc2626;
}

/* ── Field label row (label + button inline) ─── */

.field-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.field-label-row .field-label {
    margin-bottom: 0;
}

/* ── Summary suggestion ──────────────────────── */

.suggestion-box {
    margin-top: 10px;
    padding: 12px 14px;
    background: var(--accent-light);
    border: 1px solid #ffd699;
    border-radius: 6px;
}

.suggestion-text {
    margin: 0 0 10px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
}

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

.suggestion-guidance {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #ffd699;
}

.suggestion-guidance .field-input {
    flex: 1;
    font-size: 13px;
}

/* ── Word count ──────────────────────────────── */

.word-count {
    margin: 4px 0 0;
    font-size: 12px;
    text-align: right;
}

.word-count-under {
    color: var(--text-muted);
}

.word-count-ok {
    color: #15803d;
}

.word-count-over {
    color: #c26000;
}

/* ── AI check ───────────────────────────────── */

.ai-check-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-check-item {
    display: grid;
    grid-template-columns: 48px 1fr 36px;
    gap: 10px;
    align-items: start;
    padding: 10px 12px;
    background: #fff8f0;
    border: 1px solid #fde8c8;
    border-radius: 6px;
    font-size: 13px;
}

.ai-check-timestamp {
    font-variant-numeric: tabular-nums;
    color: #c26000;
    font-weight: 600;
    padding-top: 2px;
}

.ai-check-sentences {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-check-original {
    color: var(--text-muted);
}

.ai-check-repeat {
    color: var(--text);
}

.ai-check-similarity {
    text-align: right;
    color: var(--text-muted);
    font-size: 11px;
    padding-top: 2px;
}

/* ── Fully planned banner ────────────────────── */

.fully-planned-banner {
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 8px;
    color: #15803d;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 14px;
}

/* ── Collapsible sections ────────────────────── */

.collapsible-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-subtle);
    border: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.section-toggle:hover {
    background: #f0f0f0;
}

.section-chevron {
    font-size: 10px;
    color: var(--text-muted);
}

.section-body {
    padding: 20px 16px;
    border-top: 1px solid var(--border);
}

.section-body .detail-form {
    max-width: 100%;
    margin-bottom: 0;
}

/* ── Platform blocks ─────────────────────────── */

.platform-block {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.platform-block:last-child {
    margin-bottom: 0;
}

.platform-block-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    background: var(--bg-subtle);
    border: none;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
}

.platform-block-toggle:hover {
    background: #f0f0f0;
}

.platform-block-name {
    font-size: 14px;
    font-weight: 600;
    flex: 1;
}

.platform-block-body {
    border-top: 1px solid var(--border);
}

.platform-block-pre {
    border-bottom: 1px solid var(--border);
}

.platform-block-note {
    margin: 0;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.platform-block-preview {
    padding: 12px 16px;
}


.platform-block-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-subtle);
    gap: 12px;
}

.platform-block-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.platform-block-files {
    padding: 10px 16px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}

.approval-label {
    font-size: 13px;
    white-space: nowrap;
}

/* ── Button group ────────────────────────────── */
.btn-group {
    display: flex;
}

.btn-group .btn {
    border-radius: 0;
    border-right-width: 0;
}

.btn-group .btn:first-child {
    border-radius: 6px 0 0 6px;
}

.btn-group .btn:last-child {
    border-radius: 0 6px 6px 0;
    border-right-width: 1px;
}

/* ── Sources ─────────────────────────────────── */

.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
    margin-top: 8px;
}

.subject-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px 10px 12px;
    cursor: pointer;
    position: relative;
    transition: box-shadow 0.15s;
}

.subject-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

@keyframes subject-flash {
  0%   { background: #fef3c7; }
  100% { background: inherit; }
}

.subject-flash {
  animation: subject-flash 1.2s ease-out forwards;
}

.priority-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0;
}

.priority-divider::before,
.priority-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.priority-divider-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    white-space: nowrap;
}

.priority-divider-row td {
    padding: 10px 0 4px;
}

.priority-divider-cell {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.subject-card.priority-1 {
    border-left: 3px solid #f97316;
}

.subject-card.priority-3 {
    opacity: 0.6;
}

.subject-episode-type-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.episode-type-chip {
    display: inline-block;
    border-radius: 99px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 600;
}

.episode-type-regular {
    background: #dbeafe;
    color: #1d4ed8;
}

.episode-type-extra {
    background: #f3e8ff;
    color: #7e22ce;
}

.episode-type-none {
    background: none;
    color: var(--text-muted);
    font-weight: 400;
}

.subject-card-top {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.subjects-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.subjects-table th {
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding: 0 10px 8px;
    border-bottom: 1px solid var(--border);
}

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

.subject-row:hover td {
    background: var(--bg-alt, #f9f9f9);
}

.subject-priority-select {
    font-size: 11px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    outline: none;
}

.subject-card.priority-1 .subject-priority-select {
    color: #f97316;
}

.subject-card.priority-3 .subject-priority-select {
    color: #9ca3af;
}

.subject-card-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.subject-card-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.subject-card-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.subject-delete-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    opacity: 0;
    transition: opacity 0.15s;
}

.subject-card:hover .subject-delete-btn {
    opacity: 1;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.btn-icon:hover {
    color: #dc2626;
    background: #fee2e2;
}

.sources-table {
    width: 100%;
    border-collapse: collapse;
}

.sources-table th {
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
}

.sources-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.sources-table .source-row:hover td {
    background: #fafafa;
}

.sources-table .source-row.dragging {
    opacity: 0.4;
}

.sources-table .source-row.drag-over td {
    border-top: 2px solid var(--primary);
}

.source-title {
    font-weight: 500;
    font-size: 14px;
}

.source-domain {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.source-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.source-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.source-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 7px;
    border-radius: 99px;
    background: #e0e7ef;
    color: #4a5568;
}

.source-tag-removable {
    cursor: default;
}

.source-tag-remove {
    cursor: pointer;
    opacity: 0.5;
    font-size: 13px;
    line-height: 1;
}

.source-tag-remove:hover {
    opacity: 1;
}

.source-tags-editor .source-tags {
    margin-bottom: 6px;
}

.source-tag-input {
    font-size: 13px;
    padding: 5px 8px;
}

.source-notes-section {
    margin-top: 20px;
    margin-bottom: 16px;
}

.source-notes-textarea {
    width: 100%;
    min-height: 120px;
    resize: vertical;
    overflow: auto;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.6;
    padding: 8px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-alt, #fafafa);
}

.source-notes-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.source-notes-status {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
    display: block;
}

.section-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.back-to-top-btn {
    position: fixed;
    bottom: 32px;
    right: 32px;
    background: var(--text);
    color: #fff;
    border: none;
    border-radius: 99px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateY(8px);
    z-index: 100;
}

.back-to-top-btn--visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top-btn:hover {
    opacity: 0.85;
}

.notes-section {
    margin-top: 28px;
}

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

.notes-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.research-feed {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notes-empty {
    cursor: pointer;
}

.notes-empty:hover {
    color: var(--text);
}

.note-block {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 8px;
}

.note-textarea {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    overflow: hidden;
    min-height: 48px;
}

.annotation-block {
    background: #fff;
    border-left: 3px solid var(--primary);
}

.annotation-block-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.annotation-block-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.annotation-group {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.annotation-group-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    padding: 6px 12px;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
}

.annotation-group .annotation-block {
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
}

.annotation-group .annotation-block:last-child {
    border-bottom: none;
}

.annotation-source-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
}

.annotation-block-quote {
    margin: 0;
    padding: 6px 10px;
    background: #f0f4ff;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text);
    font-style: italic;
    line-height: 1.5;
}

.annotation-note-textarea {
    min-height: 32px;
    font-size: 13px;
    color: var(--text-muted);
}

.source-modal-tabs {
    display: flex;
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 7px;
    padding: 3px;
    margin-bottom: 16px;
    gap: 3px;
}

.source-modal-tab {
    flex: 1;
    background: none;
    border: none;
    border-radius: 5px;
    padding: 7px 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    transition: background 0.15s, color 0.15s;
}

.source-modal-tab.active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.source-image-full {
    max-width: 100%;
    border-radius: 6px;
    display: block;
}

.source-video-embed {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
}

.source-video-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.source-detail-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
    align-items: start;
}

.source-meta-bar {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.source-url-link {
    color: var(--text-muted);
    text-decoration: none;
}

.source-url-link:hover {
    text-decoration: underline;
}

.source-personal-note {
    background: #fefce8;
    border-left: 3px solid #f97316;
    padding: 8px 12px;
    border-radius: 0 4px 4px 0;
    font-size: 13px;
    margin-bottom: 14px;
}

.source-text {
    font-family: 'Merriweather', Georgia, serif;
    font-size: 16px;
    line-height: 1.9;
    color: #1a1a1a;
    max-width: 68ch;
    user-select: text;
}

.source-text p {
    margin: 0 0 14px;
}

.source-text .source-heading {
    font-weight: 700;
    margin: 24px 0 6px;
}

.source-detail-sidebar {
    position: sticky;
    top: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
}

.source-sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 12px;
}

.annotation-card {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.annotation-highlight {
    background: #fef08a66;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
    transition: background 0.15s;
}

.annotation-highlight.annotation-linked-hover {
    background: #fef08a;
}

.annotation-card.annotation-linked-hover {
    background: #fefce8;
}

.annotation-quote {
    margin: 0 0 4px;
    padding-left: 8px;
    border-left: 3px solid #f97316;
    font-size: 13px;
    color: #333;
    font-style: italic;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.annotation-quote--preview {
    -webkit-line-clamp: unset;
    overflow: visible;
}

.annotation-quote--expanded {
    -webkit-line-clamp: unset;
    overflow: visible;
}

.annotation-card .annotation-quote {
    cursor: pointer;
}

.annotation-note {
    font-size: 12px;
    color: var(--text-muted);
    margin: 4px 0 0;
}

.annotation-delete-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    opacity: 0;
    transition: opacity 0.15s;
}

.annotation-card:hover .annotation-delete-btn {
    opacity: 1;
}

/* ── Utility ─────────────────────────────────── */

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

/* ── Sync toast ──────────────────────────────── */

.sync-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1a1a1a;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9999;
  white-space: nowrap;
}

.sync-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Ingest page ─────────────────────────────── */

.ingest-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: var(--bg);
}

.ingest-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 24px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ingest-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.05em;
}

.ingest-btn {
    width: 100%;
}

.ingest-offline-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  color: #92400e;
  font-size: 13px;
  padding: 8px 12px;
  text-align: center;
}

.ingest-queue-badge {
  font-size: 12px;
  color: #888;
  margin: 6px 0 0;
  text-align: center;
}

.ingest-error {
    color: #dc2626;
    font-size: 13px;
    min-height: 18px;
    margin: 0;
}

.ingest-check {
    font-size: 48px;
    color: #16a34a;
    margin-bottom: 12px;
}

.ingest-success-msg {
    color: var(--text-muted);
    font-size: 15px;
    line-height: 1.5;
    margin: 0;
}

/* ── Inbox section (sources page) ────────────── */

.inbox-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
}

.inbox-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

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

.inbox-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 10px;
    padding: 1px 7px;
    margin-left: 4px;
}

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

.inbox-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.inbox-item-text {
    flex: 1;
    min-width: 0;
}

.inbox-item-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inbox-item-url {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Mobile (≤ 640px) ────────────────────────── */

@media (max-width: 640px) {

    /* Global layout */
    .page {
        padding: 16px 14px;
    }

    .page-header {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 20px;
    }

    .page-header h1 {
        font-size: 18px;
        flex: 1 1 100%;
    }

    /* Dashboard table: horizontal scroll with natural column sizing */
    .table-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -14px;
        padding: 0 14px;
    }

    table.dashboard-table {
        table-layout: auto;
        font-size: 13px;
        min-width: 0;
    }

    table.dashboard-table colgroup {
        display: none;
    }

    tbody td {
        padding: 8px 8px;
        white-space: nowrap;
    }

    .col-title {
        white-space: normal;
        min-width: 140px;
    }

    .col-type, .col-author {
        display: none;
    }

    .date-full {
        display: none;
    }

    .date-compact {
        display: inline;
    }

    /* Sources page: always show cards, hide view toggle entirely */
    #view-toggle {
        display: none;
    }

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

    /* Subject cards: always show delete button (no hover on touch) */
    .subject-delete-btn {
        opacity: 1;
    }

    /* Sources page header: search full width */
    #subject-search {
        width: 100% !important;
        flex: 1 1 100%;
        order: 3;
    }

    /* Inbox items: stack on narrow screens */
    .inbox-item {
        flex-wrap: wrap;
    }

    .inbox-assign-select {
        width: 100% !important;
    }
}
