:root {
    --app-blue: #0d6efd;
    --app-blue-dark: #0a3d91;
    --app-bg: #f5f8fc;
    --app-border: #d9e2ef;
    --app-text: #152033;
    --app-muted: #667085;
}

body {
    min-height: 100vh;
    background: var(--app-bg);
    color: var(--app-text);
}

.app-navbar {
    background: var(--app-blue-dark);
    box-shadow: 0 8px 24px rgba(21, 32, 51, 0.12);
}

.app-main {
    padding: 32px 0;
}

/* Legacy pages without sidebar use container */
.app-main .container { max-width: 1140px; }

.flash-stack {
    margin-bottom: 20px;
}

.page-head {
    margin-bottom: 24px;
}

.page-head h1 {
    margin: 0;
    font-size: 32px;
    font-weight: 700;
}

.app-kicker {
    margin-bottom: 6px;
    color: var(--app-blue);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.login-wrap {
    display: grid;
    min-height: calc(100vh - 64px);
    place-items: center;
}

.login-card {
    width: min(100%, 420px);
    padding: 32px;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(21, 32, 51, 0.08);
}

.stat-card,
.panel,
.data-table-wrap {
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(21, 32, 51, 0.06);
}

.stat-card {
    min-height: 128px;
    padding: 20px;
}

.stat-label,
.panel-label {
    color: var(--app-muted);
    font-size: 14px;
    font-weight: 600;
}

.stat-value {
    margin-top: 12px;
    font-size: 30px;
    font-weight: 750;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.stat-text {
    font-size: 22px;
}

.panel {
    padding: 22px;
}

.panel-number {
    margin-top: 10px;
    font-size: 28px;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.panel-date {
    font-size: 22px;
}

.data-table-wrap {
    overflow: hidden;
}

.data-table {
    margin: 0;
}

.data-table thead th {
    background: #eef4fb;
    color: #31445f;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
}

.text-preview {
    max-width: 520px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.empty-cell {
    padding: 36px !important;
    color: var(--app-muted);
    text-align: center;
}

.traceback-box {
    max-width: 680px;
    max-height: 320px;
    margin-top: 10px;
    padding: 12px;
    overflow: auto;
    background: #0f172a;
    color: #e5e7eb;
    border-radius: 8px;
    font-size: 12px;
}

.settings-form {
    padding: 22px;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(21, 32, 51, 0.06);
}

.settings-section + .settings-section {
    margin-top: 24px;
    padding-top: 22px;
    border-top: 1px solid var(--app-border);
}

.settings-section h2 {
    margin-bottom: 16px;
    color: #24364f;
    font-size: 18px;
    font-weight: 750;
}

.diagnostics-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.connection-actions {
    display: flex;
    min-width: 520px;
    flex-wrap: wrap;
    gap: 6px;
}

.connection-move-form {
    display: flex;
    gap: 6px;
}

.connection-move-form select {
    width: 180px;
}

.workspace-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 180px;
}

.workspace-settings-form {
    display: grid;
    grid-template-columns: minmax(220px, 1.1fr) minmax(220px, 1fr) auto;
    gap: 6px;
    min-width: 600px;
}

.recommendation-list {
    display: grid;
    gap: 14px;
}

.recommendation-card {
    padding: 20px;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(21, 32, 51, 0.06);
}

.recommendation-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.recommendation-card h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 750;
}

.recommendation-meta,
.recommendation-badges,
.recommendation-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.recommendation-meta {
    margin-top: 8px;
    color: var(--app-muted);
    font-size: 14px;
}

.recommendation-meta span {
    padding: 4px 8px;
    background: #eef4fb;
    border-radius: 8px;
}

.recommendation-body {
    margin-top: 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.recommendation-actions {
    margin-top: 18px;
}

.material-actions,
.material-channel-group,
.material-attachments,
.material-action-panel,
.plan-channel-list,
.material-schedule-form,
.max-source-actions,
.max-source-import-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.material-actions {
    min-width: 520px;
}

.material-schedule-form {
    align-items: center;
}

.max-source-actions,
.max-source-import-form {
    align-items: center;
}

.material-schedule-form .form-control {
    width: 190px;
}

.max-source-import-form .form-control {
    width: 82px;
}

.material-action-panel {
    align-items: center;
}

.material-published-badge {
    align-self: center;
    padding: 10px 12px;
}

.material-channel-group {
    align-items: center;
    min-height: 58px;
    padding: 12px;
    background: #f7fbff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.material-channel-group .form-check {
    margin: 0;
}

.material-preview {
    margin-top: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 16px;
    line-height: 1.5;
}

.material-attachments {
    margin-top: 12px;
    flex-direction: column;
}

.material-attachments a {
    overflow-wrap: anywhere;
}

.material-media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 12px;
}

.material-media-item {
    display: block;
    overflow: hidden;
    background: #f7fbff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.material-media-item img,
.material-media-item video {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.material-media-item a,
.material-attachment-link {
    display: block;
    padding: 8px;
    overflow-wrap: anywhere;
    font-size: 13px;
}

.plan-channel-list {
    min-width: 120px;
}

.auto-switch {
    padding: 12px 12px 12px 48px;
    background: #f7fbff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.btn,
.form-control,
.alert {
    border-radius: 8px;
}

code {
    color: #174ea6;
}

.secret-code {
    display: block;
    padding: 12px;
    overflow-wrap: anywhere;
    background: #eef4fb;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.totp-qr-box {
    display: grid;
    place-items: center;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 8px;
}

.totp-qr {
    width: min(100%, 236px);
    aspect-ratio: 1;
    image-rendering: pixelated;
}

.totp-uri-details summary {
    color: var(--app-blue);
    cursor: pointer;
    font-weight: 600;
}

@media (max-width: 575.98px) {
    .app-main {
        padding: 22px 0;
    }

    .page-head h1 {
        font-size: 26px;
    }

    .login-card {
        padding: 24px;
    }
}

/* ── Sidebar layout ── */
:root {
    --sb-w: 240px;
    --sb-bg: #1c2b3a;
    --sb-text: #94a3b8;
    --sb-active-bg: rgba(255,255,255,.08);
    --sb-active-text: #fff;
    --sb-border: rgba(255,255,255,.08);
}

body.has-sidebar { padding-left: var(--sb-w); transition: padding-left .2s; }
body.has-sidebar.sidebar-collapsed { padding-left: 64px; }

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sb-w);
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    z-index: 300;
    overflow: hidden;
    transition: width .2s;
}
.sidebar.collapsed { width: 64px; }

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    height: 64px;
    border-bottom: 1px solid var(--sb-border);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
}
.sidebar-logo-icon {
    flex-shrink: 0;
    width: 32px; height: 32px;
    background: var(--app-blue);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-icon svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.sidebar-logo-text { font-size: 14px; font-weight: 800; color: #fff; overflow: hidden; }

.sidebar-nav { flex: 1; padding: 8px; overflow-y: auto; overflow-x: hidden; }

.sidebar-section {
    font-size: 10px; font-weight: 700;
    color: rgba(255,255,255,.25);
    text-transform: uppercase; letter-spacing: .7px;
    padding: 14px 10px 4px;
    white-space: nowrap; overflow: hidden;
    transition: opacity .15s;
}
.sidebar.collapsed .sidebar-section { opacity: 0; pointer-events: none; }

.sidebar-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 10px;
    border-radius: 8px;
    color: var(--sb-text);
    text-decoration: none;
    font-size: 14px; font-weight: 500;
    white-space: nowrap; overflow: hidden;
    transition: background .12s, color .12s;
    margin-bottom: 2px;
}
.sidebar-item:hover { background: var(--sb-active-bg); color: #fff; }
.sidebar-item.active { background: var(--app-blue); color: #fff; }
.sidebar-item svg { flex-shrink: 0; width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-item span { overflow: hidden; white-space: nowrap; }

.sidebar-collapse-btn {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px;
    border-top: 1px solid var(--sb-border);
    color: var(--sb-text);
    font-size: 13px; font-weight: 500;
    background: none; border-left: none; border-right: none; border-bottom: none;
    cursor: pointer;
    white-space: nowrap; overflow: hidden;
    width: 100%; text-align: left;
    transition: color .12s;
}
.sidebar-collapse-btn:hover { color: #fff; }
.sidebar-collapse-btn svg { flex-shrink: 0; width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.content-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    height: 64px;
}

.topbar-title { flex: 1; font-size: 15px; font-weight: 700; color: var(--app-text); }

.topbar-bell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: 50%;
    color: var(--app-muted);
    cursor: pointer;
    background: #f5f8fc;
    transition: background 0.12s;
    text-decoration: none;
}
.topbar-bell:hover { background: #eef4fb; color: var(--app-text); }
.topbar-bell svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.topbar-badge {
    position: absolute;
    top: 4px; right: 4px;
    min-width: 16px; height: 16px;
    background: #ef4444;
    color: #fff;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    padding: 0 3px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 10px;
    transition: background 0.12s;
    text-decoration: none;
}
.topbar-user:hover { background: #f5f8fc; }

.topbar-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--app-blue-dark);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    flex-shrink: 0;
}

.topbar-user-info { line-height: 1.2; }
.topbar-user-name { font-size: 13px; font-weight: 700; color: var(--app-text); }
.topbar-user-role { font-size: 11px; color: var(--app-muted); }

.content-main { padding: 28px 24px; }

/* ── Edit page layout ── */
.edit-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
}
.edit-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--app-muted);
    text-decoration: none;
    margin-bottom: 6px;
}
.edit-back:hover { color: var(--app-blue); }
.edit-back svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.edit-title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.edit-title { font-size: 22px; font-weight: 800; margin: 0; color: var(--app-text); }

.status-chip {
    display: inline-flex; align-items: center;
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 700; letter-spacing: .2px;
}
.chip-new      { background: #f1f5f9; color: #64748b; }
.chip-editing  { background: #e0f2fe; color: #0284c7; }
.chip-ready    { background: #fef9c3; color: #a16207; }
.chip-scheduled{ background: #ede9fe; color: #7c3aed; }
.chip-published{ background: #dcfce7; color: #16a34a; }
.chip-rejected { background: #fee2e2; color: #dc2626; }

.edit-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    align-items: start;
}

.edit-card {
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}
.edit-card:last-child { margin-bottom: 0; }

.edit-card-label {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .6px;
    color: var(--app-muted);
    margin-bottom: 8px;
    display: flex; align-items: center; justify-content: space-between;
}
.char-counter { font-weight: 400; font-size: 11px; color: #b0bccc; text-transform: none; letter-spacing: 0; }

.edit-input {
    display: block; width: 100%;
    padding: 9px 12px;
    font-size: 14px; color: var(--app-text);
    background: #fff;
    border: 1.5px solid var(--app-border);
    border-radius: 8px;
    outline: none;
    transition: border-color .15s;
}
.edit-input:focus { border-color: var(--app-blue); box-shadow: 0 0 0 3px rgba(13,110,253,.1); }

.edit-textarea {
    display: block; width: 100%;
    padding: 10px 12px;
    font-size: 14px; line-height: 1.6; color: var(--app-text);
    background: #fff;
    border: 1.5px solid var(--app-border);
    border-radius: 8px;
    resize: vertical; min-height: 200px;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
}
.edit-textarea:focus { border-color: var(--app-blue); box-shadow: 0 0 0 3px rgba(13,110,253,.1); }

.edit-select {
    display: block; width: 100%;
    padding: 9px 12px;
    font-size: 14px; color: var(--app-text);
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 12px center;
    border: 1.5px solid var(--app-border);
    border-radius: 8px;
    -webkit-appearance: none; appearance: none;
    outline: none;
    cursor: pointer;
    transition: border-color .15s;
}
.edit-select:focus { border-color: var(--app-blue); box-shadow: 0 0 0 3px rgba(13,110,253,.1); }

.edit-meta-row { margin-bottom: 14px; }
.edit-meta-row:last-child { margin-bottom: 0; }

.edit-source {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    background: #f8fafc; border: 1.5px solid var(--app-border);
    border-radius: 8px; font-size: 13px; color: var(--app-muted);
}
.edit-source svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }

.channel-toggles { display: flex; gap: 8px; flex-wrap: wrap; }
.channel-toggle {
    display: flex; align-items: center; justify-content: center;
    padding: 7px 18px;
    border: 1.5px solid var(--app-border);
    border-radius: 8px;
    font-size: 13px; font-weight: 700;
    color: var(--app-muted);
    cursor: pointer;
    transition: all .15s;
    user-select: none;
}
.channel-toggle input { display: none; }
.channel-toggle.active { background: var(--app-blue); border-color: var(--app-blue); color: #fff; }
.channel-toggle:hover:not(.active) { border-color: var(--app-blue); color: var(--app-blue); }

.edit-actions-card .btn { font-weight: 600; padding: 10px 16px; }
.edit-actions-card > .btn + form,
.edit-actions-card > form + form,
.edit-actions-card > form + .btn { margin-top: 8px; }
.edit-actions-card > .btn:not(:first-child) { margin-top: 8px; }
.edit-actions-card { display: flex; flex-direction: column; gap: 8px; }

.channel-pub-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 0; border-bottom: 1px solid var(--app-border);
    font-size: 13px; margin-bottom: 6px;
}
.channel-pub-name { font-weight: 700; color: var(--app-text); }
.channel-pub-done { color: #16a34a; font-size: 12px; }

/* Dropzone redesign */
.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 2px dashed var(--app-border);
    border-radius: 10px; padding: 24px 16px;
    text-align: center; cursor: pointer;
    transition: border-color .15s, background .15s;
    background: #fafcff; min-height: 110px;
}
.dropzone:hover, .dropzone.dz-over { border-color: var(--app-blue); background: #f0f6ff; }
.dz-hint { font-size: 14px; font-weight: 600; color: #5a6c83; margin-top: 8px; }
.dz-link { color: var(--app-blue); text-decoration: underline; }
.dz-sub { font-size: 12px; color: #b0bccc; margin-top: 4px; }

/* Media grid */
.media-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.media-thumb {
    position: relative; width: 80px; height: 68px;
    border-radius: 8px; overflow: hidden;
    border: 1.5px solid var(--app-border);
    background: #f5f8fc;
    display: flex; align-items: center; justify-content: center;
    transition: opacity .2s;
}
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-file svg { width: 28px; height: 28px; stroke: var(--app-muted); fill: none; stroke-width: 1.5; }
.media-del {
    position: absolute; top: 2px; right: 2px;
    width: 20px; height: 20px;
    background: rgba(0,0,0,.5); color: #fff;
    border: none; border-radius: 50%;
    font-size: 13px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
}
.media-del:hover { background: rgba(200,0,0,.85); }

/* Mobile: sidebar becomes bottom nav */
@media (max-width: 991.98px) {
    .sidebar { display: none; }
    body.has-sidebar { padding-left: 0; }
    .topbar { padding: 0 16px; }
    .content-main { padding: 16px; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
    .edit-layout { grid-template-columns: 1fr; }
}

/* ── Dropzone ── */
.dropzone {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
    border: 2px dashed var(--app-border);
    border-radius: 10px;
    padding: 28px 16px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    min-height: 160px;
    background: #fafcff;
}
.dropzone:hover { border-color: var(--app-blue); background: #f0f6ff; }

/* ── Existing photos strip in editor ── */
.existing-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.existing-photo {
    position: relative;
    width: 80px; height: 64px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid var(--app-border);
    background: #f5f8fc;
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.2s;
}
.existing-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.existing-photo-del {
    position: absolute; top: 2px; right: 2px;
    width: 20px; height: 20px;
    background: rgba(0,0,0,0.55); color: #fff;
    border: none; border-radius: 50%;
    font-size: 14px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
}
.existing-photo-del:hover { background: rgba(200,0,0,0.8); }

/* ── Bottom navigation (mobile) ── */
.bottom-nav {
    display: none;
}

@media (max-width: 991.98px) {
    .app-navbar { display: none; }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        z-index: 1000;
        background: var(--app-blue-dark);
        border-top: 1px solid rgba(255,255,255,0.08);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .app-main {
        padding-bottom: calc(72px + env(safe-area-inset-bottom));
    }
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 4px 8px;
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    gap: 3px;
    transition: color 0.15s;
}

.bottom-nav-item.active,
.bottom-nav-item:hover { color: #fff; }

.bottom-nav-icon {
    width: 24px; height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Org tabs & status pills ── */
.queue-filters { margin-bottom: 16px; }

.org-tabs, .status-pills {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.org-tabs::-webkit-scrollbar,
.status-pills::-webkit-scrollbar { display: none; }

.status-pills { margin-top: 8px; }

.org-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #fff;
    border: 1.5px solid var(--app-border);
    border-radius: 20px;
    color: var(--app-text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.15s;
}
.org-tab:hover { border-color: #a0b4cc; color: var(--app-text); }
.org-tab.active { background: var(--app-blue); border-color: var(--app-blue); color: #fff; }

.org-tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px; height: 20px;
    padding: 0 5px;
    background: rgba(0,0,0,0.1);
    border-radius: 10px;
    font-size: 11px;
}
.org-tab.active .org-tab-count { background: rgba(255,255,255,0.22); }

.status-pill {
    padding: 4px 12px;
    background: transparent;
    border: 1.5px solid var(--app-border);
    border-radius: 16px;
    color: var(--app-muted);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    transition: all 0.15s;
}
.status-pill:hover { border-color: #a0b4cc; color: var(--app-text); }
.status-pill.active { background: var(--app-text); border-color: var(--app-text); color: #fff; }

/* ── Material list ── */
.mlist { display: flex; flex-direction: column; gap: 8px; }

.mitem {
    background: #fff;
    border: 1.5px solid var(--app-border);
    border-radius: 12px;
    padding: 14px 16px 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: box-shadow .15s, border-color .15s;
}
.mitem:hover { box-shadow: 0 4px 14px rgba(21,32,51,.08); border-color: #b8c8df; }

.mitem-body {
    flex: 1; min-width: 0;
    text-decoration: none; color: inherit;
    display: block;
}
.mitem-body:hover { color: inherit; }

.mitem-org {
    font-size: 12px;
    font-weight: 600;
    color: var(--app-muted);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mitem-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--app-text);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mitem-preview {
    font-size: 13px;
    color: var(--app-muted);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
}
.mitem-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.mitem-meta .status-chip { font-size: 11px; padding: 3px 8px; }
.mitem-meta-tag {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 12px; font-weight: 600;
    color: #5a6c83; background: #f1f5f9;
    padding: 2px 8px; border-radius: 10px;
}
.mitem-meta-tag svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }
.mitem-meta-date { font-size: 12px; color: var(--app-muted); }
.mitem-channel-badge {
    font-size: 11px; font-weight: 700;
    padding: 2px 8px; border-radius: 10px;
    background: #dcfce7; color: #16a34a;
}

.mitem-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

@media (max-width: 600px) {
    .mitem { align-items: flex-start; flex-direction: column; }
    .mitem-actions { flex-direction: row; width: 100%; }
    .mitem-actions .btn { flex: 1; }
    .mitem-title { white-space: normal; }
}

/* ── AI edit button ── */
.ai-edit-btn {
    background: none; border: none; padding: 0;
    font-size: 11px; font-weight: 700;
    color: var(--app-blue); cursor: pointer;
    text-transform: none; letter-spacing: 0;
    transition: opacity .15s;
}
.ai-edit-btn:hover { opacity: .7; }
.ai-edit-btn:disabled { opacity: .4; cursor: default; }

/* ── AI modal ── */
.ai-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(21,32,51,.5);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.ai-modal {
    background: #fff;
    border-radius: 14px;
    width: 100%; max-width: 860px;
    max-height: 90vh;
    display: flex; flex-direction: column;
    box-shadow: 0 24px 60px rgba(21,32,51,.2);
}
.ai-modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px 16px;
    border-bottom: 1px solid var(--app-border);
    font-weight: 700; font-size: 16px;
}
.ai-modal-close {
    background: none; border: none; font-size: 22px; line-height: 1;
    color: var(--app-muted); cursor: pointer; padding: 0 4px;
}
.ai-modal-close:hover { color: var(--app-text); }
.ai-modal-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.ai-modal-footer {
    display: flex; gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--app-border);
}

.ai-loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; padding: 40px; color: var(--app-muted); font-size: 14px;
}
.ai-spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--app-border);
    border-top-color: var(--app-blue);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ai-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ai-compare-col { display: flex; flex-direction: column; gap: 6px; }
.ai-compare-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--app-muted); }
.ai-compare-text {
    flex: 1;
    background: #f8fafc;
    border: 1.5px solid var(--app-border);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 14px; line-height: 1.6;
    white-space: pre-wrap; color: var(--app-text);
}
.ai-compare-new { border-color: #86efac; background: #f0fdf4; }
.ai-error { color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 12px 16px; font-size: 14px; }

@media (max-width: 600px) {
    .ai-compare { grid-template-columns: 1fr; }
}

.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--app-muted);
}
.empty-state svg { width: 40px; height: 40px; stroke: #d0dae8; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty-title { font-size: 16px; font-weight: 700; color: #8494aa; margin-top: 12px; }
.empty-sub { font-size: 13px; margin-top: 4px; }

/* ── Editor ── */
.editor-back {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--app-blue);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 14px;
}

.editor-org {
    font-size: 11px;
    font-weight: 700;
    color: var(--app-blue);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 14px;
}

.editor-card {
    background: #fff;
    border: 1.5px solid var(--app-border);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: 0 2px 6px rgba(21,32,51,0.04);
}

.editor-field-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--app-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
}

.editor-title-input {
    width: 100%;
    font-size: 17px;
    font-weight: 700;
    border: none;
    background: transparent;
    color: var(--app-text);
    resize: none;
    outline: none;
    padding: 0;
    line-height: 1.3;
    overflow: hidden;
}

.editor-body-input {
    width: 100%;
    font-size: 15px;
    line-height: 1.6;
    border: none;
    background: transparent;
    color: var(--app-text);
    resize: none;
    outline: none;
    padding: 0;
    min-height: 160px;
    overflow: hidden;
}

/* Photos strip in editor */
.editor-photos {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.editor-photos::-webkit-scrollbar { display: none; }

.editor-photo {
    position: relative;
    flex: 0 0 auto;
    width: 110px; height: 82px;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid var(--app-border);
}
.editor-photo.removed { opacity: 0.3; }

.editor-photo img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}

.editor-photo-del {
    position: absolute;
    top: 3px; right: 3px;
    width: 22px; height: 22px;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s;
}
.editor-photo-del:hover { background: rgba(200,0,0,0.75); }

.editor-photo-link {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 82px; height: 82px;
    border-radius: 8px;
    border: 1.5px solid var(--app-border);
    background: #f7fbff;
    position: relative;
    font-size: 28px;
}

.editor-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: #f7fbff;
    border: 1.5px dashed var(--app-border);
    border-radius: 10px;
    color: var(--app-blue);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 10px;
}
.editor-upload-btn:hover { background: #eef4fb; border-color: var(--app-blue); }

/* Sticky action bar */
.editor-bottom-bar {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1.5px solid var(--app-border);
    padding: 10px 0 10px;
    display: flex;
    gap: 8px;
    z-index: 100;
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
}

@media (max-width: 991.98px) {
    .editor-bottom-bar {
        bottom: calc(58px + env(safe-area-inset-bottom));
    }
}

.editor-bottom-bar .btn-publish { flex: 2; }
.editor-bottom-bar .btn-save   { flex: 1; }

details.editor-card > summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--app-muted);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
details.editor-card > summary::before {
    content: '›';
    font-size: 18px;
    transition: transform 0.2s;
    display: inline-block;
}
details.editor-card[open] > summary::before { transform: rotate(90deg); }
details.editor-card > summary + * { margin-top: 14px; }

/* ── Organizations page ─────────────────────────────────────────────────────── */

.org-cards {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.org-card {
    background: #fff;
    border: 1.5px solid var(--app-border);
    border-radius: 12px;
    overflow: hidden;
}

.org-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--app-border);
    background: var(--app-bg);
}

.org-card__name {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 700;
    color: var(--app-text);
}

.org-card__icon {
    width: 20px;
    height: 20px;
    color: var(--app-muted);
    flex-shrink: 0;
}

.org-card__head-actions { flex-shrink: 0; }

/* Connection list inside org card */
.conn-list {
    display: flex;
    flex-direction: column;
}

.conn-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--app-border);
}

.conn-item:last-child { border-bottom: none; }

.conn-item__dot {
    padding-top: 4px;
    flex-shrink: 0;
}

.conn-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.conn-dot--on  { background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
.conn-dot--off { background: #94a3b8; }

.conn-item__info {
    flex: 1;
    min-width: 0;
}

.conn-item__name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
}

.conn-item__route {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}

.conn-arrow {
    width: 20px;
    height: 10px;
    color: var(--app-muted);
    flex-shrink: 0;
}

.conn-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    font-family: monospace;
    white-space: nowrap;
}
.conn-chip--vk       { background: #e8f0fd; color: #1a56c4; }
.conn-chip--max      { background: #e8f5e9; color: #1b6f2b; }
.conn-chip--interval { background: #f1f5f9; color: var(--app-muted); font-weight: 500; font-family: inherit; }
.conn-chip--auto     { background: #dcfce7; color: #15803d; font-family: inherit; }

.conn-item__last,
.conn-item__error {
    font-size: 12px;
    color: var(--app-muted);
    margin-top: 4px;
}
.conn-item__error { color: #dc2626; }

.conn-item__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    padding-top: 2px;
}

.btn-xs {
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 6px;
    font-weight: 600;
    line-height: 1.5;
}

/* Empty state within org card */
.conn-empty {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px;
    color: var(--app-muted);
    font-size: 13.5px;
}
.conn-empty svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.org-card__footer {
    padding: 12px 20px;
    border-top: 1px dashed var(--app-border);
    background: #fafcff;
}

/* Section divider in modal */
.conn-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--app-muted);
    padding: 4px 0 2px;
    border-bottom: 1px solid var(--app-border);
}
.conn-section-label svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Empty state for organizations page */
.empty-state-icon {
    width: 64px;
    height: 64px;
    color: #cbd5e1;
    margin-bottom: 8px;
}
