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

:root {
    --sidebar-width: 220px;
    --preview-width: 380px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #64748b;
    --sidebar-active-bg: #334155;
    --sidebar-border: #334155;
    --accent: #3b82f6;
    --accent-dark: #004a87;
    --green: #008000;
    --danger: #ef4444;
    --surface: #ffffff;
    --border: #e2e8f0;
    --muted: #64748b;
    --text: #1e293b;
    --text-light: #475569;
    --bg: #f1f5f9;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
}

html, body { height: 100%; font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 4px 1fr 4px var(--preview-width);
    height: 100vh;
    overflow: hidden;
}

/* Column resize handles */
.resize-handle {
    background: var(--border);
    cursor: col-resize;
    position: relative;
    z-index: 2;
    transition: background .15s;
    flex-shrink: 0;
}
.resize-handle::after {
    content: '';
    position: absolute;
    inset: 0 -4px;
}
.resize-handle:hover, .resize-handle.is-dragging { background: var(--accent); }

/* Sidebar */
.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--sidebar-border);
}
.sidebar-header {
    padding: 14px 14px 10px;
    border-bottom: 1px solid var(--sidebar-border);
    display: flex; align-items: center; gap: 6px;
}
.sidebar-header h1 { font-size: 13px; font-weight: 700; color: #f1f5f9; letter-spacing: .02em; flex: 1; }
.sidebar-collapse-btn {
    background: none; border: none; color: var(--sidebar-muted); cursor: pointer;
    padding: 2px 5px; font-size: 13px; line-height: 1; border-radius: 4px; flex-shrink: 0;
}
.sidebar-collapse-btn:hover { color: #f1f5f9; background: var(--sidebar-active-bg); }
.sidebar.is-collapsed .sidebar-collapse-btn { margin: 0 auto; }
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-tab {
    flex: 1; padding: 8px; font-size: 11px; font-weight: 600; color: var(--sidebar-muted);
    background: none; border: none; cursor: pointer; text-align: center; text-transform: uppercase; letter-spacing: .06em;
}
.sidebar-tab.is-active { color: #f1f5f9; border-bottom: 2px solid var(--accent); }
.sidebar-body { flex: 1; overflow-y: auto; padding: 8px; }

/* Article list */
.article-item {
    display: block; padding: 8px 10px; border-radius: var(--radius); cursor: pointer;
    margin-bottom: 2px; border: 1px solid transparent; text-decoration: none;
}
.article-item:hover { background: var(--sidebar-active-bg); }
.article-item.is-active { background: var(--sidebar-active-bg); border-color: var(--accent); }
.article-item-title { font-size: 12px; font-weight: 600; color: #f1f5f9; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.article-item-date { font-size: 11px; color: var(--sidebar-muted); display: block; margin-top: 2px; }
.sidebar-new-btn {
    display: block; width: 100%; margin-top: 8px; padding: 7px;
    background: none; border: 1px dashed var(--sidebar-border); border-radius: var(--radius);
    color: var(--sidebar-muted); font-size: 12px; cursor: pointer; text-align: center;
}
.sidebar-new-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Editor column */
.editor-col {
    display: flex; flex-direction: column; overflow: hidden; background: var(--bg);
}
.editor-topbar {
    display: flex; align-items: center; gap: 8px; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.editor-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* Preview column */
.preview-col {
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--surface); border-left: 1px solid var(--border);
}
.preview-topbar {
    display: flex; align-items: center; gap: 6px; padding: 10px 12px;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.preview-body { flex: 1; overflow: hidden; padding: 0; display: flex; flex-direction: column; }
.preview-iframe { width: 100%; border: none; display: block; flex: 1; min-height: 0; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 6px 12px; border-radius: var(--radius); border: 1px solid transparent;
    font-size: 13px; font-weight: 600; cursor: pointer; line-height: 1;
}
.btn-primary { background: var(--accent-dark); color: #fff; border-color: var(--accent-dark); }
.btn-primary:hover { background: #003a6e; }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-light:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .85; }
.btn-tab { background: none; border: none; padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; border-radius: 0; }
.btn-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.field input, .field textarea, .field select {
    padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 13px; color: var(--text); background: var(--surface); width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.field input.input-error, .field textarea.input-error, .field select.input-error {
    border-color: #d33;
}
.field input.input-error:focus, .field textarea.input-error:focus, .field select.input-error:focus {
    border-color: #d33; box-shadow: 0 0 0 3px rgba(221,51,51,.15);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* Block cards */
.blocks-container { display: flex; flex-direction: column; gap: 4px; }
.block-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; transition: border-color .15s;
}
.block-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
/* Block holds an image not yet hosted on stentec.com — flag it to be re-uploaded. */
.block-card.has-external-image { border-color: #ff8800; box-shadow: 0 0 0 2px rgba(255,136,0,.18); }
.block-card.has-external-image.is-active { border-color: #ff8800; box-shadow: 0 0 0 3px rgba(255,136,0,.28); }
/* Block uses an auto-replaced image (managed by a rule) — thin blue border. */
.block-card.has-replaced-image { border-color: #3b82f6; }
.block-card.has-replaced-image.is-active { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.12); }

/* Image auto-replace rule list (profile modal) */
.replace-rule-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.replace-rule { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.replace-rule-img { height: 60px; width: auto; max-width: 110px; background: #f1f5f9; border: 1px solid var(--border); border-radius: 3px; object-fit: contain; flex-shrink: 0; }
.replace-rule-arrow { color: var(--muted); flex-shrink: 0; }
.replace-rule-url { flex: 1; font-size: 11px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.replace-rule-del { flex-shrink: 0; padding: 2px 8px; }
.block-card-header {
    display: flex; align-items: center; gap: 8px; padding: 9px 12px;
    cursor: pointer; user-select: none;
}
.block-card-header:hover { background: var(--bg); }
.block-card-icon { font-size: 14px; flex-shrink: 0; }
.block-card-summary { flex: 1; font-size: 12px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-card-type { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.block-card-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #6b7280; background: #eef2f7; border: 1px solid #d8e0ea; border-radius: 999px; padding: 1px 7px; flex-shrink: 0; }
.block-card-drag { color: var(--border); cursor: grab; font-size: 16px; padding: 0 4px; flex-shrink: 0; }
.block-card-body { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }

/* Add block button */
.add-block-btn {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px; border: 1px dashed var(--border); border-radius: var(--radius);
    background: none; color: var(--muted); font-size: 12px; cursor: pointer; width: 100%;
}
.add-block-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Block type picker */
.block-type-picker {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
    padding: 10px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.block-type-option {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 8px 4px; border: 1px solid var(--border); border-radius: var(--radius);
    background: none; cursor: pointer; font-size: 11px; color: var(--text-light);
}
.block-type-option:hover { border-color: var(--accent); background: #eff6ff; color: var(--accent); }
.block-type-option span:first-child { font-size: 18px; }

/* Image picker modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100;
    display: flex; align-items: center; justify-content: center;
}
.modal-dialog {
    background: var(--surface); border-radius: var(--radius); width: 640px; height: 80vh; max-height: 720px;
    display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-search { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.modal-search input { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }
.modal-grid {
    flex: 1; min-height: 0; overflow-y: auto; padding: 12px;
    display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 194px;
    align-content: start; gap: 8px;
}
.modal-image-card {
    position: relative;
    height: 194px;
    border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden;
    cursor: pointer; background: none; padding: 0; text-align: left;
}
.modal-image-card:hover { border-color: var(--accent); }
.modal-image-card img { width: 100%; height: 130px; object-fit: contain; background: #f1f5f9; display: block; }
.modal-image-card-label { padding: 4px 6px; font-size: 10px; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-image-card-category { padding: 0 6px 5px; font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-image-card-move { width: calc(100% - 12px); margin: 0 6px 6px; padding: 3px 4px; border: 1px solid var(--border); border-radius: 3px; background: var(--surface); color: var(--text-light); font-size: 10px; cursor: pointer; }
.modal-image-delete {
    position: absolute; top: 4px; right: 4px; z-index: 2;
    display: flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 4px;
    background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 12px; line-height: 1;
    opacity: 0.75; transition: opacity 0.12s, background 0.12s;
}
.modal-image-card:hover .modal-image-delete { opacity: 1; }
.modal-image-delete:hover { background: #b00020; }

/* Image picker inline control */
.image-picker-control { display: flex; align-items: center; gap: 6px; }
.image-picker-thumb { width: auto; height: 60px; max-width: 160px; object-fit: contain; background: #f1f5f9; border-radius: 4px; border: 1px solid var(--border); }
.image-picker-placeholder { width: 54px; height: 54px; border: 1px dashed var(--border); border-radius: 4px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 16px; cursor: pointer; }
.image-picker-name { font-size: 12px; color: var(--text-light); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* HTML output panels */
.output-panels { border-top: 1px solid var(--border); }
.output-panel summary { padding: 8px 12px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.output-panel summary:hover { background: var(--bg); }
.output-panel textarea { width: 100%; height: fit-content; max-height: 45vh; padding: 10px; border: none; border-top: 1px solid var(--border); font: 11px/1.5 monospace; color: var(--text); resize: vertical; }

/* Flash message */
.flash { padding: 8px 12px; border-radius: var(--radius); font-size: 12px; font-weight: 600; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* Quill overrides */
.ql-container { font-family: Arial, Helvetica, sans-serif; font-size: 14px; }
.ql-toolbar { border-color: var(--border) !important; border-radius: var(--radius) var(--radius) 0 0; }
.ql-container.ql-snow { border-color: var(--border) !important; border-radius: 0 0 var(--radius) var(--radius); }
.ql-editor { min-height: 120px; }
.ql-blue-title { color: var(--accent-dark) !important; font-weight: 700; font-size: 22px; }
.ql-green-accent { color: var(--green) !important; font-style: italic; font-weight: 700; }

/* Sidebar image grid */
.image-grid-small { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.image-thumb-card { border: 1px solid var(--sidebar-border); border-radius: 4px; overflow: hidden; cursor: pointer; }
.image-thumb-card img { width: 100%; height: 55px; object-fit: contain; background: #f1f5f9; display: block; }
.image-thumb-label { padding: 3px 5px; font-size: 9px; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.image-thumb-meta { padding: 0 5px 3px; font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.image-filter-row { display: flex; gap: 6px; margin-top: 8px; }
.image-category-select { min-width: 0; width: 100%; padding: 5px 7px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: 11px; color: var(--text); }
.image-thumb-category { width: calc(100% - 8px); margin: 0 4px 4px; padding: 2px 4px; border: 1px solid var(--sidebar-border); border-radius: 3px; background: var(--surface); color: var(--text-light); font-size: 9px; cursor: pointer; }
.upload-form { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; }
.upload-form input[type=file] { font-size: 11px; color: var(--sidebar-muted); }

/* Line-height picker label */
.ql-lineHeight .ql-picker-label::before { content: 'Line H'; }
.ql-lineHeight .ql-picker-item[data-value=""]::before { content: 'Default'; }
.ql-lineHeight .ql-picker-item::before { content: attr(data-value); }
.ql-lineHeight { width: 72px !important; }

/* Muted text */
.text-muted { color: var(--muted); font-size: 12px; }
.sortable-ghost { opacity: .4; }

/* Sidebar profile footer */
.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 8px; flex-shrink: 0; }
.profile-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; background: none; border: none; cursor: pointer; border-radius: var(--radius); }
.profile-btn:hover { background: var(--sidebar-active-bg); }
.profile-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.profile-email { font-size: 11px; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Profile modal */
.profile-dialog { max-width: 380px; }
.profile-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; overflow-y: auto; }
.profile-signed-in { font-size: 13px; color: var(--text-light); }
.profile-section { display: flex; flex-direction: column; gap: 8px; }
.profile-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.profile-section input { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }
.profile-msg-ok { font-size: 12px; color: #166534; }
.profile-msg-err { font-size: 12px; color: #b00020; }

/* Article locking */
.article-lock-avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: #d97706; color: #fff; font-size: 9px; font-weight: 700; flex: 0 0 auto;
}
.lock-banner {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 14px; background: #fff4e5; border-bottom: 1px solid #f0c987;
    color: #92400e; font-size: 13px;
}
.lock-banner button { margin-left: auto; }
.editor-body.is-readonly { pointer-events: none; opacity: .55; user-select: none; }
