/* Shared theme support for the independent admin layouts. Dark keeps its palette. */
html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

.admin-console { background: var(--bg-primary); }
.admin-console, .admin-login { --admin-action-bg: #7032b6; }
.admin-login .btn-submit { background: var(--admin-action-bg); }
.admin-console #admin-sidebar > nav { flex: 1; }
.admin-skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 1000;
    padding: 12px 18px;
    border: 2px solid var(--focus-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-main);
    transform: translateY(-180%);
}
.admin-skip-link:focus { transform: none; }
#admin-main:focus { outline: none; }
.admin-chart-note { margin: 14px 0; color: var(--text-muted); font-size: .9rem; }
.admin-chart-data summary { min-height: 44px; padding: 10px 0; cursor: pointer; }
.admin-chart-data caption { text-align: left; padding: 8px 0; color: var(--text-muted); }
.admin-chart-data .admin-table th { text-transform: none; letter-spacing: normal; }
.admin-chart-data [tabindex]:focus-visible { outline: 3px solid var(--focus-color); outline-offset: 3px; }
.admin-console :is(main, main > form, .admin-card, .editor-container, .preview-panel, .kpi-details, .dashboard-row-2, .dashboard-row-3, .kpi-grid, .form-group) { min-width: 0; }
.admin-console :is(.header-title, .admin-table-container, .chart-container, .form-control) { min-width: 0; max-width: 100%; }
.admin-console .chart-container canvas { max-width: 100%; }
.admin-console .admin-table-container { width: 100%; }
.admin-console .panel-header { flex-wrap: wrap; gap: 12px; }
.admin-console :is(.panel-header h2, .kpi-label, .preview-content) { overflow-wrap: anywhere; }
.admin-console .kpi-content { gap: 12px; }
.admin-console .kpi-icon-wrap { flex-shrink: 0; }
.admin-console .header-actions { flex-wrap: wrap; justify-content: flex-end; }
.admin-console .header-actions .theme-switcher { flex-shrink: 0; }
.admin-console :is(.header-title, .owner-card-heading > *, .owner-list h3, .session-id) {
    overflow-wrap: anywhere;
    min-width: 0;
}
.admin-console .admin-table-container:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 3px;
}
.admin-console .journey-header { flex-wrap: wrap; gap: 16px; }
.admin-console :is(.journey-summary-left, .journey-summary-left > div) { min-width: 0; }
.admin-console .journey-summary-right { flex-wrap: wrap; gap: 12px; }
.admin-console .session-meta { flex-wrap: wrap; gap: 8px 18px; overflow-wrap: anywhere; }
.admin-console .session-indicator { flex-shrink: 0; }

/* Shared action sizing for every admin layout, including links and form buttons. */
.admin-console :is(.btn-btn, .owner-button, .inquiry-filters a),
.admin-login .btn-submit {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    align-self: center;
    flex-shrink: 0;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    min-width: 80px;
    max-width: 100%;
    padding: 8px 16px;
    border-radius: 10px;
    font-family: inherit;
    font-size: .9rem;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.admin-console :is(.btn-btn, .owner-button)[hidden] { display: none !important; }
.admin-console .sidebar-footer > .btn-btn { width: 100%; }
.admin-console .admin-table .btn-btn { padding: 8px 12px; font-size: .8rem; white-space: nowrap; }
.admin-console .btn-btn:disabled, .admin-console .owner-button:disabled { cursor: not-allowed; }
.admin-console .owner-button { background: var(--admin-action-bg); border-color: var(--admin-action-bg); color: #fff !important; }
.admin-console .owner-button:hover { filter: brightness(1.1); }
.admin-console .owner-button-secondary { background: transparent; border-color: var(--border); color: var(--text-main) !important; }
.admin-console .owner-button-secondary:hover { background: var(--bg-surface-hover); }
.admin-console .owner-button-danger { background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .3); color: var(--error) !important; }
.admin-console .owner-button-danger:hover { background: rgba(239, 68, 68, .3); }
html:not([data-theme="light"]) .admin-console :is(.btn-btn-danger, .owner-button-danger) { color: #ffb4bc !important; }
.admin-console .inquiry-filters a[aria-current="page"] { background: var(--admin-action-bg); border-color: var(--admin-action-bg); color: #fff; }
.admin-console .header-actions [data-generate-article] { width: 210px; }
.admin-console :is(#article-schedule-panel, #article-job-actions) .btn-btn { min-width: 128px; }
.admin-console .admin-row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.admin-console .admin-row-actions form { display: flex; margin: 0; }
.admin-console .admin-row-actions .btn-btn { flex: 0 0 80px; width: 80px; height: 40px; }
.admin-console .article-view { border-color: var(--accent); color: var(--accent); }
.admin-console .admin-category {
    display: inline-block;
    min-width: 140px;
    max-width: 200px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-surface-hover);
    font-size: .8rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: normal;
    overflow-wrap: anywhere;
    vertical-align: middle;
}
.admin-login { background: var(--bg-grad); overflow-x: hidden; overflow-y: auto; }
.admin-login-atmosphere { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.admin-login .login-container { min-width: 0; }
.admin-login .logo { overflow-wrap: anywhere; }
.admin-login .theme-switcher {
    display: flex;
    justify-content: flex-end;
    margin: 0 0 18px;
    text-transform: none;
    letter-spacing: normal;
}
.admin-login .theme-switcher select { font-family: inherit; }
.admin-console :is(a, button, input, textarea, select, summary):focus-visible,
.admin-login :is(a, button, input, select):focus-visible {
    outline: 3px solid var(--primary, var(--accent));
    outline-offset: 3px;
}

/* These names are used by admin_base and its child templates. */
html[data-theme="dark"]:has(.admin-console) {
    --border: hsla(240, 10%, 25%, 0.4);
}
html[data-theme="light"]:has(.admin-console) {
    --bg-primary: #f5f5fa;
    --bg-sidebar: #ffffff;
    --bg-surface: #ffffff;
    --bg-surface-hover: #ececf5;
    --border: #c9c7d7;
    --primary: #7032b6;
    --primary-glow: rgba(112, 50, 182, .12);
    --accent: #006a80;
    --accent-glow: rgba(0, 106, 128, .12);
    --success: #176540;
    --success-glow: rgba(23, 101, 64, .10);
    --warning: #815100;
    --error: #b42335;
    --text-main: #222135;
    --text-muted: #55536a;
    --text-subtle: #625f76;
}

html[data-theme="light"] .admin-console {
    --owner-muted: var(--text-muted);
    --owner-border: var(--border);
    --owner-accent: var(--primary);
}
html[data-theme="light"] .admin-console .admin-card {
    box-shadow: 0 8px 28px rgba(38, 30, 62, .06);
}
html[data-theme="light"] .admin-console .admin-card:hover {
    box-shadow: 0 10px 30px rgba(38, 30, 62, .09);
}
html[data-theme="light"] .admin-console .admin-table tr:hover td,
html[data-theme="light"] .admin-console .journey-header:hover,
html[data-theme="light"] .admin-console .journey-card[open] .journey-header {
    background: var(--bg-surface-hover);
}
html[data-theme="light"] .admin-console :is(.journey-header, .journey-body, .preview-panel) {
    background: var(--bg-surface);
}
html[data-theme="light"] .admin-console :is(.form-control, #gen-topic, #generator-modal select) {
    background: var(--bg-primary) !important;
    color: var(--text-main) !important;
}
html[data-theme="light"] .admin-console :is(.preview-content, .preview-content h1, .preview-content h2, .preview-content h3),
html[data-theme="light"] .admin-console #generator-modal h3,
html[data-theme="light"] .admin-console #loader-title {
    color: var(--text-main) !important;
}
html[data-theme="light"] .admin-console .preview-content :is(blockquote, code) {
    background: var(--bg-surface-hover);
}
html[data-theme="light"] .admin-console #loader-overlay { background: rgba(245, 245, 250, .97) !important; }
html[data-theme="light"] .admin-console .business-error,
html[data-theme="light"] .admin-console .inquiry-status-spam { color: var(--error); }
html[data-theme="light"] .admin-console :is(.inquiry-status-flagged, .inquiry-alert, .inquiry-flags) { color: var(--warning); }
html[data-theme="light"] .admin-console :is(.inquiry-status-resolved, .inquiry-alert-success, .inquiry-check) { color: var(--success); }
html[data-theme="light"] .admin-console .inquiry-review { color: var(--primary); }
html[data-theme="light"] .admin-console .inquiry-filters a[aria-current="page"] { color: #ffffff; }

/* Owner/community administration uses the owner's shared components. */
html[data-theme="light"] .admin-console :is(.owner-card, .owner-field input:not([type="checkbox"]), .owner-field textarea, .owner-field select) {
    color: var(--text-main);
    background: var(--bg-surface);
    border-color: var(--border);
}
html[data-theme="light"] .admin-console .owner-notice {
    color: #17553e;
    background: #edf8f2;
    border-color: #8cb7a3;
}
html[data-theme="light"] .admin-console .owner-notice-error { color: #8c2236; background: #fff0f3; border-color: #c58d9a; }
html[data-theme="light"] .admin-console .owner-notice-info { color: #4c3b7d; background: #f1edf9; border-color: #aaa0c8; }
html[data-theme="light"] .admin-console .owner-badge { color: var(--text-main); border-color: var(--border); }
html[data-theme="light"] .admin-console .owner-button-secondary {
    color: var(--text-main) !important;
    border-color: var(--border);
}
html[data-theme="light"] .admin-console .owner-button-secondary:hover { background: var(--bg-surface-hover); }
html[data-theme="light"] .admin-console .owner-button-danger { color: var(--error) !important; border-color: #b98791; }
html[data-theme="light"] .admin-console .owner-button-danger:hover { background: #fff0f3; }

/* Standalone sign-in has its own token names and no admin_base inheritance. */
html[data-theme="light"]:has(.admin-login) {
    --bg-grad: linear-gradient(135deg, #f5f5fa 0%, #f2edf8 50%, #faf1f6 100%);
    --accent: #7032b6;
    --accent-glow: rgba(112, 50, 182, .14);
    --card-bg: #ffffff;
    --card-border: #c9c7d7;
    --input-bg: #f8f7fc;
    --input-border: #aaa6bd;
    --text-main: #222135;
    --text-muted: #55536a;
    --error: #b42335;
}
html[data-theme="light"] .admin-login .form-input:focus { background: #ffffff; }
html[data-theme="light"] .admin-login .form-input::placeholder { color: #6b667d; opacity: 1; }
html[data-theme="light"] .admin-login .login-card { box-shadow: 0 20px 50px rgba(54, 34, 79, .10); }
html[data-theme="light"] .admin-login .logo span { text-shadow: none; }
html[data-theme="light"] .admin-login .glow-circle { opacity: .10; }

@media (max-width: 1200px) {
    .admin-console :is(.dashboard-row-2, .dashboard-row-3) { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1024px) {
    .admin-console .editor-container { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 992px) {
    .admin-console .sidebar-menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); padding: 12px; }
    .admin-console .sidebar-brand { padding: 16px 24px; }
    .admin-console .sidebar-footer { flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 24px; }
    .admin-console .sidebar-footer > .btn-btn { width: auto; }
    .admin-console .sidebar-footer form { min-width: 130px; }
}
@media (max-width: 640px) {
    .admin-console main > header { align-items: flex-start; flex-direction: column; gap: 18px; }
    .admin-console .header-actions { justify-content: flex-start; }
    .admin-console :is(.admin-card, .preview-panel) { padding: 20px; }
    .admin-console .editor-container .admin-card > div[style*="display: grid"] { grid-template-columns: minmax(0, 1fr) !important; }
    .admin-console .editor-container .admin-card > div:last-child,
    .admin-console .editor-container .admin-card > div:last-child > div:last-child,
    .admin-console .editor-container .preview-panel > h2,
    .admin-console .editor-container div:has(> #image-prompt) { flex-wrap: wrap; gap: 12px; }
    .admin-console #image-prompt { flex: 1 1 150px; }
    .admin-login .login-card { padding: 32px 24px; }
}
@media (prefers-reduced-motion: reduce) {
    .admin-login .glow-circle, .admin-login .login-card { animation: none; }
    .admin-console *, .admin-login * { transition: none !important; scroll-behavior: auto !important; }
}
