/* =============================================================================
   export-domains.css — Export Domains tool
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Height chain
   ----------------------------------------------------------------------------- */

#content {
    align-items: stretch;
    height: calc(100vh - var(--appheader-height, 90px));
    overflow: hidden;
    flex-wrap: nowrap;
}

#menucontrol {
    display: flex !important;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
}

#maincontent {
    overflow-y: auto;
    height: 100%;
}

/* -----------------------------------------------------------------------------
   Main Panel
   ----------------------------------------------------------------------------- */

.export-domain-panel {
    max-width: 900px;
    padding: 20px 24px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.panel-header h1 {
    margin: 0;
}

/* Admin dataset bar below header */
.admin-dataset-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
}

.admin-dataset-bar .dataset-select-inline {
    flex: 1;
    margin-bottom: 0 !important;
}

/* User dataset bar in header */
.user-dataset-bar {
    flex: 1;
    max-width: 320px;
}

.dataset-select-inline {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 0 !important;
}

/* -----------------------------------------------------------------------------
   No columns message
   ----------------------------------------------------------------------------- */

.no-columns-msg {
    padding: 14px;
    background: var(--row-bg, #f9f9f9);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 5px;
    font-size: 0.88rem;
    color: var(--text-muted, #999);
}

/* -----------------------------------------------------------------------------
   Export Options Box
   ----------------------------------------------------------------------------- */

.export-options-section {
    margin-top: 8px;
    padding: 14px 16px 4px;
    background: var(--row-bg, #f9f9f9);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
}

.export-options-section label {
    margin-top: 0 !important;
}

/* -----------------------------------------------------------------------------
   Summary Box
   ----------------------------------------------------------------------------- */

.export-summary-section {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--row-bg, #f9f9f9);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
}

.export-summary-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted, #aaa);
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.export-summary {
    font-size: 0.88rem;
    color: var(--text-color, #444);
    line-height: 1.5;
}

/* -----------------------------------------------------------------------------
   Actions Box
   ----------------------------------------------------------------------------- */

.form-actions-section {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--row-bg, #f9f9f9);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.form-actions-section .submit-status-text {
    margin-right: auto;
    flex: 1 1 auto;
    min-width: 0;
    margin-top: 0;
}

/* -----------------------------------------------------------------------------
   Status Messages
   ----------------------------------------------------------------------------- */

.submit-status-text {
    font-size: 0.88rem;
    font-weight: 500;
    min-height: 1.4em;
}

.submit-status-text:empty {
    display: none;
}

.submit-status-text.success {
    color: #1a6b35 !important;
    background: #eaf7ee !important;
    border: 1px solid #b6e4c6 !important;
    border-radius: 4px;
    padding: 6px 10px;
}

.submit-status-text.error {
    color: #922020 !important;
    background: #fdf0f0 !important;
    border: 1px solid #f0b8b8 !important;
    border-radius: 4px;
    padding: 6px 10px;
}

.submit-status-text.loading {
    color: var(--text-muted, #888);
}

/* -----------------------------------------------------------------------------
   Preview Table
   ----------------------------------------------------------------------------- */

.preview-area {
    margin-top: 20px;
    overflow-x: auto;
}

/* -----------------------------------------------------------------------------
   User Sidebar
   ----------------------------------------------------------------------------- */

.sidebar-user-panel {
    padding: 14px 12px;
}

.sidebar-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #aaa);
    margin-bottom: 8px;
    display: block;
}

.sidebar-field-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--label-color, #2C5F2D);
    margin-top: 10px;
    margin-bottom: 3px;
    font-family: var(--heading-font-family, sans-serif);
}

.sidebar-dataset-select {
    width: 100%;
    box-sizing: border-box;
}

.sidebar-user-note {
    font-size: 0.82rem;
    color: var(--text-muted, #999);
    margin-top: 14px;
    line-height: 1.5;
    font-style: italic;
}

/* -----------------------------------------------------------------------------
   Admin Drawer — wide, full height, slides in from right
   ----------------------------------------------------------------------------- */

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.drawer-overlay.open {
    opacity: 1;
    pointer-events: all;
}

.admin-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 600px;
    max-width: 95vw;
    background: var(--panel-bg, #fff);
    box-shadow: -4px 0 32px rgba(0, 0, 0, 0.18);
    z-index: 901;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s ease;
}

.admin-drawer.open {
    transform: translateX(0);
}

body.drawer-open {
    overflow: hidden;
}

/* Drawer Header */
.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #ddd);
    flex-shrink: 0;
}

.drawer-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.drawer-close-btn {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted, #888);
    padding: 0 4px;
    transition: color 0.15s;
}

.drawer-close-btn:hover {
    color: var(--text-color, #333);
}

/* Drawer Body — two columns side by side */
.drawer-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

/* Left column: column list */
.drawer-col-list {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color, #e0e0e0);
    overflow: hidden;
}

.drawer-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #aaa);
    padding: 12px 12px 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    gap: 8px;
    flex-shrink: 0;
}

.drawer-hint {
    font-size: 0.7rem;
    font-weight: 400;
    text-transform: none;
    color: var(--text-muted, #bbb);
}

.drawer-search-wrap {
    padding: 4px 10px 8px;
    flex-shrink: 0;
}

/* Column list fills all remaining height in left column */
.drawer-columns-list {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    padding: 0 6px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 1px !important;
    margin-bottom: 0 !important;
    background: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    scrollbar-width: thin;
}

/* Right column: computed + dataset config */
.drawer-col-config {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 0;
}

.drawer-section {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color, #eeeeee);
}

.drawer-field-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--label-color, #2C5F2D);
    margin-top: 12px;
    margin-bottom: 3px;
    font-family: var(--heading-font-family, sans-serif);
}

/* Save row inside dataset section */
.drawer-save-row {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color, #e8e8e8);
}

.drawer-save-row .submit-status-text {
    margin-top: 6px;
    font-size: 0.82rem;
}

/* Drawer Footer */
.drawer-footer {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--border-color, #ddd);
    display: flex;
    justify-content: flex-end;
}

/* -----------------------------------------------------------------------------
   Computed columns help toggle
   ----------------------------------------------------------------------------- */

.help-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    border: 1px solid var(--border-color, #ccc);
    background: none;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted, #999);
    line-height: 1;
    padding: 2px 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.help-toggle-btn:hover,
.help-toggle-btn.active {
    background: var(--primary-color, #0066cc);
    color: #fff;
    border-color: var(--primary-color, #0066cc);
}

/* Collapsible help panel */
.computed-help {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
    margin-bottom: 0;
}

.computed-help.open {
    max-height: 300px;
    margin-bottom: 10px;
}

.computed-help-block {
    background: var(--row-bg, #f5f7fa);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 5px;
    padding: 10px 12px;
    margin-top: 8px;
    font-size: 0.82rem;
    line-height: 1.7;
}

.computed-help-title {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #888);
    margin-bottom: 4px;
}

.computed-help-note {
    color: var(--text-muted, #999);
    font-style: italic;
    font-size: 0.78rem;
}

.computed-help-example {
    font-size: 0.8rem;
    color: var(--text-color, #444);
}

/* -----------------------------------------------------------------------------
   Computed columns (in drawer)
   ----------------------------------------------------------------------------- */

.computed-add-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted, #aaa);
    margin-top: 12px;
    margin-bottom: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color, #eee);
}

.computed-input-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.computed-input-row input {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 0 !important;
}

.computed-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.82rem;
    margin-top: 4px;
}

.computed-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    flex-wrap: nowrap;
    min-width: 0;
    background: var(--row-bg, #f5f7fa);
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 4px;
}

.computed-name {
    font-family: monospace;
    font-size: 0.78rem;
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.computed-remove-btn {
    flex: 0 0 auto;
    background: none;
    border: none;
    color: var(--text-muted, #bbb);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 3px;
    transition: color 0.15s;
}

.computed-remove-btn:hover {
    color: var(--color-danger, #c0392b);
}

/* -----------------------------------------------------------------------------
   Column List Items
   ----------------------------------------------------------------------------- */

.columns-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: default;
    transition: background 0.1s;
    user-select: none;
}

.columns-list-item:hover {
    background: var(--row-hover-bg, #f0f4fc);
}

.columns-list-item[draggable="true"] {
    cursor: grab;
}

.columns-list-item[draggable="true"]:hover {
    background: var(--row-hover-bg, #e8f0fe);
    border-color: var(--border-color, #d0d8ee);
}

.columns-list-item.dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.columns-list-item input[type="checkbox"] {
    flex-shrink: 0;
    margin: 0;
    cursor: pointer;
}

/* Domain column is always required — show as locked */
.columns-list-item input[type="checkbox"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.columns-list-item:has(input:disabled) .columns-list-label-main::after {
    content: ' (always included)';
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted, #aaa);
    text-transform: none;
    font-family: sans-serif;
}

.columns-list-label {
    display: flex;
    flex-direction: column;
    gap: 1px;
    cursor: pointer;
    min-width: 0;
    flex: 1;
}

.columns-list-label-main {
    font-size: 0.88rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.columns-list-label-key {
    font-family: monospace;
    font-size: 0.72rem;
    color: var(--text-muted, #aaa);
    line-height: 1.2;
}

/* -----------------------------------------------------------------------------
   Misc
   ----------------------------------------------------------------------------- */

.label-note {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted, #999);
    text-transform: none;
    margin-left: 4px;
    font-family: var(--default-font-family, sans-serif);
}

.user-session-note {
    font-size: 0.8rem;
    color: var(--text-muted, #999);
    font-style: italic;
    margin-left: 4px;
}

/* -----------------------------------------------------------------------------
   Responsive — narrow screens
   ----------------------------------------------------------------------------- */

@media screen and (max-width: 640px) {
    .admin-drawer {
        width: 95vw;
    }
}

/* Stack vertically when drawer is narrower than 480px */
@media screen and (max-width: 480px) {
    .drawer-body {
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .drawer-col-list {
        width: 100%;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-color, #e0e0e0);
        min-height: 220px;
        max-height: 35vh;
    }

    /* Override the full-height flex so it respects max-height when stacked */
    .drawer-columns-list {
        max-height: none !important;
        flex: 1 1 auto !important;
    }

    .drawer-col-config {
        flex: none;
        overflow-y: visible;
    }
}

/* When drawer body is wide enough, always show two columns side by side */
@media screen and (min-width: 481px) {
    .drawer-body {
        flex-direction: row;
        overflow: hidden;
    }

    .drawer-col-list {
        width: 240px;
        flex-shrink: 0;
        border-right: 1px solid var(--border-color, #e0e0e0);
        overflow: hidden;
    }

    .drawer-col-config {
        flex: 1;
        min-width: 0;
        overflow-y: auto;
    }
}

/* -----------------------------------------------------------------------------
   Dark Mode
   ----------------------------------------------------------------------------- */

body.dark-mode .no-columns-msg,
body.dark-mode .export-options-section,
body.dark-mode .export-summary-section,
body.dark-mode .form-actions-section {
    background: #1e1e1e;
    border-color: #3a3a3a;
}

body.dark-mode .submit-status-text.success {
    color: #6fcf8a !important;
    background: #0d2e18 !important;
    border-color: #1e5c30 !important;
}

body.dark-mode .submit-status-text.error {
    color: #f4a0a0 !important;
    background: #2e0d0d !important;
    border-color: #5c1e1e !important;
}

body.dark-mode .admin-drawer {
    background: #1a1a1a;
}

body.dark-mode .drawer-header,
body.dark-mode .drawer-footer {
    border-color: #3a3a3a;
}

body.dark-mode .drawer-col-list {
    border-right-color: #3a3a3a;
}

body.dark-mode .drawer-section {
    border-bottom-color: #2e2e2e;
}

body.dark-mode .sidebar-search,
body.dark-mode .drawer-search-wrap input {
    background: #2a2a2a;
    color: #ddd;
    border-color: #444;
}

body.dark-mode .columns-list-item:hover,
body.dark-mode .columns-list-item[draggable="true"]:hover {
    background: #2e2e3e;
    border-color: #444;
}

body.dark-mode .computed-item {
    background: #242424;
    border-color: #3a3a3a;
}

body.dark-mode .computed-help-block {
    background: #242424;
    border-color: #3a3a3a;
}

body.dark-mode .help-toggle-btn {
    border-color: #555;
    color: #777;
}

body.dark-mode .columns-list-label-key,
body.dark-mode .drawer-section-title,
body.dark-mode .export-summary-label,
body.dark-mode .sidebar-section-title {
    color: #555;
}

body.dark-mode .export-summary {
    color: #ccc;
}

body.dark-mode .sidebar-user-note {
    color: #666;
}