/* ==========================================================================
   BDU HOUSING - PRO CMS WORKSPACE & UNIFIED EDITOR SYSTEM
   Design System: Microsoft Fluent 2 + Gutenberg + Notion + Medium + GOV.UK
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. PRO CMS WORKSPACE LAYOUT (3-COLUMN & FLEXIBLE DASHBOARD BINDINGS)
   -------------------------------------------------------------------------- */
.cms-workspace {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* Header bar inside editor screens */
.cms-workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 16px 24px;
    background: var(--fluent-surface, #ffffff);
    border-radius: var(--fluent-radius, 8px);
    border: 1px solid var(--fluent-border, rgba(0, 0, 0, 0.08));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.cms-workspace-title-group h1 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--fluent-text-primary, #242424);
    margin: 0 0 4px 0;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.01em;
}

.cms-workspace-title-group p {
    color: var(--fluent-text-secondary, #616161);
    font-size: 0.85rem;
    margin: 0;
}

/* Grid Layout for CMS Editing */
.cms-workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 24px;
    align-items: start;
}

@media (max-width: 1024px) {
    .cms-workspace-grid {
        grid-template-columns: 1fr;
    }
}

/* Center Canvas / Editor Main Column */
.cms-editor-canvas {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

/* Sidebar Column (Right) */
.cms-sidebar-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 72px;
    z-index: 90;
}

/* Pro Content Sections Card */
.cms-section-card {
    background: var(--fluent-surface, #ffffff);
    border: 1px solid var(--fluent-border, rgba(0, 0, 0, 0.08));
    border-radius: var(--fluent-radius, 8px);
    padding: 24px 28px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cms-section-card:focus-within {
    border-color: var(--fluent-primary, #0F6CBD);
    box-shadow: 0 0 0 2px rgba(15, 108, 189, 0.1);
}

.cms-section-heading {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--fluent-text-primary, #242424);
    margin: 0 0 18px 0;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--fluent-border, rgba(0, 0, 0, 0.08));
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cms-section-heading i {
    color: var(--fluent-primary, #0F6CBD);
    margin-right: 8px;
}

/* Seamless Title Input (Notion / Medium Style) */
.cms-title-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--fluent-text-primary, #242424);
    padding: 8px 0;
    line-height: 1.3;
    border-bottom: 2px solid transparent;
    transition: border-color 0.2s ease;
}

.cms-title-input:focus {
    border-bottom-color: var(--fluent-primary, #0F6CBD);
}

.cms-title-input::placeholder {
    color: var(--fluent-text-subtle, #8A8A8A);
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   2. CKEDITOR 5 DISTRACTION-FREE & EXPANDED CANVAS (700px~900px MIN HEIGHT)
   -------------------------------------------------------------------------- */
.ck-editor-container {
    width: 100%;
    margin-bottom: 1.25rem;
    font-family: var(--font-family, system-ui, -apple-system, sans-serif);
    position: relative;
    border: 1px solid var(--fluent-border, #cbd5e1);
    border-radius: var(--fluent-radius, 8px);
    background-color: var(--fluent-surface, #ffffff);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.ck-editor-container:focus-within {
    border-color: var(--fluent-primary, #0F6CBD) !important;
    box-shadow: 0 0 0 3px rgba(15, 108, 189, 0.15) !important;
}

/* Custom Header Action Strip */
.ck-custom-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 6px 14px;
    background-color: var(--fluent-bg, #f8fafc);
    border-bottom: 1px solid var(--fluent-border, #e2e8f0);
}

.ck-btn-custom {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--fluent-text-secondary, #475569);
    background: var(--fluent-surface, #ffffff);
    border: 1px solid var(--fluent-border, #cbd5e1);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1.2;
}

.ck-btn-custom:hover {
    background-color: var(--fluent-primary-light, #eef6ff);
    color: var(--fluent-primary, #0F6CBD);
    border-color: var(--fluent-primary, #0F6CBD);
}

/* CKEditor Top Toolbar - Fixed at top of editor container */
.ck-editor-container .ck.ck-editor__top {
    position: relative !important;
    top: 0 !important;
    z-index: 10 !important;
    border: none !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
    border-bottom: 1px solid var(--fluent-border, #e2e8f0) !important;
    border-radius: 0 !important;
    background: var(--fluent-surface, #ffffff) !important;
}

.ck-editor-container .ck.ck-toolbar {
    background: var(--fluent-surface, #ffffff) !important;
    border: none !important;
    padding: 6px 12px !important;
    border-radius: 0 !important;
}

.ck-editor-container .ck.ck-toolbar__items {
    align-items: center;
    gap: 3px;
    flex-wrap: wrap;
}

/* Editable Content Area */
.ck-editor-container .ck-content.ck-editor__editable {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    min-height: 220px;
    max-height: 480px;
    overflow-y: auto;
    padding: 1.25rem 1.5rem !important;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--fluent-text-primary, #1e293b);
    background-color: var(--fluent-surface, #ffffff) !important;
}

/* Long-Form Editor Canvas (Main Article / News Editor) */
.cms-editor-canvas .ck-editor-container .ck-content.ck-editor__editable {
    min-height: 550px;
    max-height: none;
}

/* Compact Editor Mode */
.ck-editor-container.ck-compact .ck-content.ck-editor__editable {
    min-height: 140px;
    max-height: 320px;
    padding: 0.85rem 1rem !important;
    font-size: 0.9rem;
}

.ck-editor-container.ck-compact .ck.ck-editor__top {
    position: relative !important;
    top: 0 !important;
    box-shadow: none !important;
}

/* Editor Status bar (Word count, Character count, Save status indicator) */
.ck-editor-statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background-color: var(--fluent-bg, #f8fafc);
    border-top: 1px solid var(--fluent-border, #e2e8f0);
    font-size: 0.78rem;
    color: var(--fluent-text-secondary, #64748b);
    font-weight: 500;
}

.ck-editor-statusbar-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.ck-editor-save-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: #10B981;
}

.ck-editor-save-badge.saving {
    color: #F59E0B;
}

/* --------------------------------------------------------------------------
   3. STICKY ACTION FOOTER (ALWAYS VISIBLE - NO LONGER NEED SCROLLING)
   -------------------------------------------------------------------------- */
/* Fix parent clipping & positioning when sticky action bar is used inside forms/cards */
.fluent-card.has-sticky-bar,
.fluent-card:has(.cms-sticky-action-bar),
form:has(.cms-sticky-action-bar) {
    overflow: visible !important;
    transform: none !important;
}

.cms-sticky-action-bar {
    position: fixed;
    bottom: 0;
    left: 250px;
    right: 0;
    height: 64px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--fluent-border, rgba(0, 0, 0, 0.12));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 99999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    transition: left 0.25s cubic-bezier(0.16, 1, 0.3, 1), background 0.25s ease;
}

.admin-layout.sidebar-collapsed .cms-sticky-action-bar {
    left: 64px;
}

.cms-sticky-action-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cms-sticky-action-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Make body have bottom padding so sticky bar does not cover footer content */
body.has-sticky-actions .admin-body {
    padding-bottom: 80px;
}

/* --------------------------------------------------------------------------
   4. DARK THEME INTEGRATION
   -------------------------------------------------------------------------- */
[data-theme="dark"] .cms-workspace-header,
[data-theme="dark"] .cms-section-card {
    background-color: #1E293B;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .cms-title-input {
    color: #F8FAFC;
}

[data-theme="dark"] .ck-editor-container {
    background-color: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .ck-custom-header-actions,
[data-theme="dark"] .ck-editor-statusbar {
    background-color: #1E293B;
    border-color: #334155;
}

[data-theme="dark"] .ck-btn-custom {
    background-color: #1E293B;
    color: #94A3B8;
    border-color: #475569;
}

[data-theme="dark"] .ck-btn-custom:hover {
    background-color: #334155;
    color: #38BDF8;
    border-color: #38BDF8;
}

[data-theme="dark"] .ck-editor-container .ck.ck-editor__top {
    background-color: #1E293B !important;
    border-bottom-color: #334155 !important;
}

[data-theme="dark"] .ck-editor-container .ck.ck-toolbar {
    background-color: #1E293B !important;
}

[data-theme="dark"] .ck-editor-container .ck-content.ck-editor__editable {
    background-color: #0F172A !important;
    color: #F8FAFC !important;
}

[data-theme="dark"] .ck.ck-button,
[data-theme="dark"] .ck.ck-dropdown__button {
    color: #CBD5E1 !important;
}

[data-theme="dark"] .ck.ck-button:hover,
[data-theme="dark"] .ck.ck-button.ck-on {
    background: #334155 !important;
    color: #38BDF8 !important;
}

[data-theme="dark"] .cms-sticky-action-bar {
    background: rgba(15, 23, 42, 0.95);
    border-top-color: rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   5. CONTENT TYPOGRAPHY & MEDIA STYLING INSIDE EDITOR & PUBLIC PAGES (.ck-content)
   -------------------------------------------------------------------------- */
.ck-content {
    color: var(--color-text-primary, #1F1F1F);
    font-family: var(--font-family, inherit);
    line-height: 1.7;
    font-size: 0.95rem;
}

.ck-content h1 { font-size: 1.85rem; font-weight: 700; margin: 1.2rem 0 0.6rem; color: var(--color-primary, #0F6CBD); line-height: 1.3; }
.ck-content h2 { font-size: 1.55rem; font-weight: 700; margin: 1rem 0 0.5rem; color: var(--color-text-primary, #1F1F1F); line-height: 1.35; }
.ck-content h3 { font-size: 1.3rem; font-weight: 600; margin: 0.9rem 0 0.4rem; color: var(--color-text-primary, #1F1F1F); line-height: 1.4; }
.ck-content h4 { font-size: 1.15rem; font-weight: 600; margin: 0.8rem 0 0.3rem; color: var(--color-text-primary, #1F1F1F); }

.ck-content p { margin: 0.5rem 0 1rem; color: var(--color-text-secondary, #404040); }
.ck-content a { color: var(--color-primary, #0F6CBD); text-decoration: underline; font-weight: 500; }
.ck-content a:hover { color: var(--color-secondary, #005A9E); }

.ck-content ul, .ck-content ol { padding-left: 1.5rem; margin: 0.6rem 0 1rem; }
.ck-content ul { list-style-type: disc; }
.ck-content ol { list-style-type: decimal; }
.ck-content li { margin-bottom: 0.35rem; color: var(--color-text-secondary, #404040); }

.ck-content blockquote {
    border-left: 4px solid var(--color-primary, #0F6CBD);
    padding: 0.8rem 1.2rem;
    margin: 1.2rem 0;
    background-color: var(--color-bg, #F5F7FA);
    font-style: italic;
    color: var(--color-text-secondary, #404040);
    border-radius: 0 8px 8px 0;
}

.ck-content code {
    background-color: var(--color-bg, #F5F7FA);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 0.88em;
    color: var(--color-danger, #D13438);
}

.ck-content pre {
    background-color: #1E293B;
    color: #F8FAFC;
    padding: 1.2rem;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Fira Code', Consolas, monospace;
    font-size: 0.9em;
}

.ck-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.ck-content figure.image figcaption {
    font-size: 0.85rem;
    color: var(--color-text-tertiary, #6B7280);
    margin-top: 8px;
    font-style: italic;
    text-align: center;
}

.ck-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.2rem 0;
}

.ck-content table th,
.ck-content table td {
    border: 1px solid var(--color-border, #E5E7EB);
    padding: 10px 14px;
}

.ck-content table th {
    background-color: var(--color-bg, #F5F7FA);
    font-weight: 600;
}

/* Fullscreen Mode */
.ck-editor-fullscreen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999 !important;
    background: var(--fluent-surface, #ffffff);
    padding: 1rem 2rem;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.ck-editor-fullscreen-mode .ck-content.ck-editor__editable {
    max-height: none !important;
    min-height: calc(100vh - 140px) !important;
    flex: 1;
}

/* Live Preview Modal Overlay */
.ck-preview-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    box-sizing: border-box;
}

.ck-preview-modal-card {
    background: var(--fluent-surface, #ffffff);
    width: 100%;
    max-width: 960px;
    max-height: 88vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.ck-preview-modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--fluent-border, #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--fluent-bg, #f8fafc);
}

.ck-preview-modal-body {
    padding: 2rem 2.5rem;
    overflow-y: auto;
    flex: 1;
}
