/**
 * misac.table.css — MISAC DataTable styles
 * Overrides for AG-Grid Alpine theme + toolbar + picker modal + print.
 */

/* ── AG-Grid header alignment ─────────────────────────────────────────────── */
/* Center all headers globally */
.misac-table-grid .ag-header-cell-label,
.misac-table-grid .ag-header-group-cell-label {
    justify-content: center;
}
/* Override AG-Grid's built-in right-align so amount headers stay centered */
.misac-table-grid .ag-right-aligned-header .ag-header-cell-label {
    flex-direction: row;
    justify-content: center;
}
.ag-center-aligned-header .ag-header-cell-label { justify-content: center; }

/* ── Brand tokens (inherit from master misac.css) ─────────────────────────── */
:root {
    --mt-accent:       var(--m-accent, #2272b5);
    --mt-accent2:      var(--m-accent2, #ab217f);
    --mt-accent-light: var(--m-table-row-hover, rgba(34, 114, 181, 0.12));
    --mt-accent-ring:  var(--m-accent-ring, rgba(34, 114, 181, 0.25));
}

/* ── Container ───────────────────────────────────────────────────────────── */
.misac-table-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
/* Sidebar-open layout: main area + sidebar side-by-side */
.misac-table-container.mt-pivot-sidebar-open {
    flex-direction: row;
    align-items: flex-start;
}
.mt-pivot-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ── Pivot Configurator Sidebar ──────────────────────────────────────────── */
.mt-pivot-sidebar {
    width: 240px;
    min-width: 200px;
    flex-shrink: 0;
    background: var(--m-surface, #fff);
    border: 1px solid var(--m-border, #dee2e6);
    border-radius: 6px;
    padding: 10px 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.mt-pivot-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 12.5px;
    color: var(--m-text, #1a1a2e);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--m-border, #dee2e6);
}
.mt-pivot-sidebar-apply,
.mt-pivot-sidebar-cancel {
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 1px 4px;
    border-radius: 3px;
    font-weight: 700;
}
.mt-pivot-sidebar-apply  { color: #2e7d32; }
.mt-pivot-sidebar-apply:hover  { background: #e8f5e9; color: #1b5e20; }
.mt-pivot-sidebar-cancel { color: #888; }
.mt-pivot-sidebar-cancel:hover { background: #fdecea; color: #c00; }
.mt-pivot-zone { display: flex; flex-direction: column; gap: 4px; }
.mt-pivot-zone-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    color: #777;
    letter-spacing: 0.4px;
}
.mt-pivot-chips {
    min-height: 28px;
    border: 1px dashed var(--m-border, #ccc);
    border-radius: 4px;
    padding: 3px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    background: var(--m-surface-alt, #f8f9fa);
    transition: border-color 0.15s, background 0.15s;
}
.mt-pivot-drop-active .mt-pivot-chips {
    border-color: var(--mt-accent, #2272b5);
    background: rgba(34,114,181,0.06);
}
.mt-pivot-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--mt-accent, #2272b5);
    color: #fff;
    border-radius: 3px;
    padding: 2px 5px;
    font-size: 11px;
    cursor: grab;
    user-select: none;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mt-pivot-zone-available .mt-pivot-chip { background: #6c757d; cursor: grab; }
.mt-pivot-chip-dragging { opacity: 0.4; }
.mt-pivot-chip-remove {
    font-weight: 700;
    font-size: 11px;
    opacity: 0.7;
    cursor: pointer;
    flex-shrink: 0;
}
.mt-pivot-chip-remove:hover { opacity: 1; }
.mt-pivot-chip-agg {
    background: rgba(255,255,255,0.22);
    border-radius: 2px;
    padding: 0 3px;
    font-size: 10px;
    cursor: pointer;
    flex-shrink: 0;
}
.mt-pivot-chip-agg:hover { background: rgba(255,255,255,0.38); }
.mt-pivot-display-opts {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-top: 4px;
    border-top: 1px solid var(--m-border, #dee2e6);
}
.mt-pivot-display-opt {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    cursor: pointer;
    color: var(--m-text, #1a1a2e);
}
.mt-pivot-display-opt input[type=checkbox] { cursor: pointer; margin: 0; }

/* ── Pivot filter button on chip ─────────────────────────────────────────── */
.mt-pivot-chip-filter {
    background: rgba(255,255,255,0.18);
    border-radius: 2px;
    padding: 0 3px;
    font-size: 10px;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.75;
}
.mt-pivot-chip-filter:hover { opacity: 1; background: rgba(255,255,255,0.35); }
.mt-pivot-chip-filter-active { opacity: 1; background: #ff9800; color: #fff; }

/* ── Pivot filter dropdown ───────────────────────────────────────────────── */
.mt-pivot-filter-dd {
    position: fixed;
    z-index: 9999;
    background: var(--m-surface, #fff);
    border: 1px solid var(--m-border, #ccc);
    border-radius: 5px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.18);
    min-width: 180px;
    max-width: 220px;
    font-size: 12px;
    overflow: hidden;
}
.mt-pivot-filter-dd-header {
    padding: 6px 10px;
    font-weight: 700;
    background: var(--m-surface-alt, #f0f4f8);
    border-bottom: 1px solid var(--m-border, #dee2e6);
    font-size: 11.5px;
    color: var(--m-text, #1a1a2e);
}
.mt-pivot-filter-dd-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}
.mt-pivot-filter-dd-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    cursor: pointer;
    color: var(--m-text, #1a1a2e);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mt-pivot-filter-dd-row:hover { background: var(--m-surface-alt, #f0f4f8); }
.mt-pivot-filter-dd-row input[type=checkbox] { cursor: pointer; margin: 0; flex-shrink: 0; }
.mt-pivot-filter-dd-footer {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-top: 1px solid var(--m-border, #dee2e6);
    background: var(--m-surface-alt, #f0f4f8);
}
.mt-pivot-filter-dd-action {
    font-size: 11px;
    cursor: pointer;
    color: var(--mt-accent, #2272b5);
    text-decoration: underline;
}
.mt-pivot-filter-dd-apply {
    margin-left: auto;
    padding: 2px 10px;
    background: var(--mt-accent, #2272b5);
    color: #fff;
    border: none;
    border-radius: 3px;
    font-size: 11.5px;
    cursor: pointer;
}
.mt-pivot-filter-dd-apply:hover { opacity: 0.88; }

/* ── Pivot group header / subtotal rows ──────────────────────────────────── */
.misac-pivot-group-header   { cursor: default; }
.misac-pivot-group-subtotal { cursor: default; }

/* ── Toolbar (search + export buttons) ───────────────────────────────────── */
.misac-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.misac-table-create-btn {
    margin-right: 8px;
    white-space: nowrap;
    font-size: 0.75rem;
    padding: 3px 8px;
    line-height: 1.4;
}

.misac-table-search {
    flex: 1;
    min-width: 140px;
    max-width: 300px;
}

.misac-table-search-input {
    width: 100%;
    padding: 4px 8px;
    font-size: 0.8rem;
    border: 1px solid var(--m-input-border, #ced4da);
    border-radius: 4px;
    outline: none;
    background: var(--m-input-bg, #fff);
    color: var(--m-text, #1e293b);
}

.misac-table-search-input:focus {
    border-color: var(--mt-accent);
    box-shadow: 0 0 0 2px var(--mt-accent-ring);
}

.misac-table-export-btns {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.misac-table-export-btns .btn {
    font-size: 0.75rem;
    padding: 3px 8px;
    line-height: 1.4;
}

.misac-table-orient-btn {
    min-width: 28px;
    padding: 3px 6px !important;
    opacity: 0.7;
}
.misac-table-orient-btn:hover {
    opacity: 1;
}

/* ── AG-Grid grid wrapper ─────────────────────────────────────────────────── */
.misac-table-grid {
    width: 100%;
    /* height is set inline from config */
}

/* ── AG-Grid Alpine theme overrides ──────────────────────────────────────── */

/* Header: brand-tinted background */
.misac-table-grid.ag-theme-alpine .ag-header {
    background-color: var(--m-table-header-bg, #eef4fb);
    border-bottom: 2px solid var(--mt-accent);
}

.misac-table-grid.ag-theme-alpine .ag-header-cell-text {
    font-weight: 600;
    font-size: 0.78rem;
    color: var(--mt-accent);
    white-space: normal; /* allow header text to wrap */
    line-height: 1.3;
}

/* Rows: compact height, alternating stripe */
.misac-table-grid.ag-theme-alpine .ag-row {
    font-size: 0.78rem;
    color: var(--m-text, #374151);
}

.misac-table-grid.ag-theme-alpine .ag-row-odd {
    background-color: var(--m-table-row-odd, #f8fafc);
}

.misac-table-grid.ag-theme-alpine .ag-row-even {
    background-color: var(--m-table-row-even, #ffffff);
}

.misac-table-grid.ag-theme-alpine .ag-row:hover {
    background-color: var(--mt-accent-light) !important;
}

/* Pinned bottom (footer / totals row) */
.misac-table-grid.ag-theme-alpine .ag-row-pinned {
    font-weight: 700;
    background-color: var(--m-table-pinned-bg, #eef4fb) !important;
    border-top: 2px solid var(--mt-accent);
}

/* Cells: compact padding, aligned with rowHeight: 32 */
.misac-table-grid.ag-theme-alpine .ag-cell {
    padding: 0 8px;
    line-height: 32px;
}

/* Header: match compact style */
.misac-table-grid.ag-theme-alpine .ag-header-cell,
.misac-table-grid.ag-theme-alpine .ag-header-group-cell {
    padding: 0 8px;
}

/* Images inside cells */
.misac-table-grid .ag-cell img {
    vertical-align: middle;
    border-radius: 3px;
}

/* Badges inside cells (Bootstrap badge compatibility) */
.misac-table-grid .ag-cell .badge {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    vertical-align: middle;
}

/* Action column buttons — compact */
.misac-table-grid .ag-cell .btn-action,
.misac-table-grid .ag-cell .btn-action-dt-row {
    padding: 2px 5px;
    font-size: 0.7rem;
    line-height: 1.2;
    margin: 1px;
}

/* Context menus inside cells */
.misac-table-grid .ag-cell .menuzord {
    margin: 0;
    padding: 0;
}

/* Form inside action cell (delete form) */
.misac-table-grid .ag-cell form {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 0;
}

/* Pagination bar */
.misac-table-grid.ag-theme-alpine .ag-paging-panel {
    font-size: 0.78rem;
    padding: 4px 8px;
    border-top: 1px solid #dee2e6;
}

/* ── Picker modal adjustments ─────────────────────────────────────────────── */

/* Make the modal wider on large screens */
#misac-tbl-picker-modal .modal-xl,
[id^="misac-tbl-picker-"] .modal-xl {
    max-width: min(95vw, 1200px);
}

/* Tight modal header */
[id^="misac-tbl-picker-"] .modal-header {
    padding: 8px 16px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

[id^="misac-tbl-picker-"] .modal-body {
    padding: 8px;
}

[id^="misac-tbl-picker-"] .modal-footer {
    padding: 6px 12px;
    border-top: 1px solid #dee2e6;
}

/* Highlight selected row in picker */
[id^="misac-tbl-picker-"] .ag-row-selected {
    background-color: var(--mt-accent-light) !important;
    outline: 1px solid var(--mt-accent);
    outline-offset: -1px;
}

/* ── Picker loading / error states ───────────────────────────────────────── */

/* Loading spinner shown while AG-Grid + data fetch are in progress */
.misac-picker-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 50px 20px;
    color: #6c757d;
    font-size: 0.9rem;
}

/* CSS-only spinning ring — no image dependency */
.misac-picker-spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 3px solid #dee2e6;
    border-top-color: var(--mt-accent);
    border-radius: 50%;
    flex-shrink: 0;
    animation: misac-spin 0.7s linear infinite;
}

@keyframes misac-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error message shown when fetch fails */
.misac-picker-error {
    color: #dc3545;
    font-size: 0.88rem;
}

/* ── Print ────────────────────────────────────────────────────────────────── */
@media print {
    /* Hide toolbar and browser chrome during print */
    .misac-table-toolbar {
        display: none !important;
    }

    /* AG-Grid print layout removes scrollbars and shows all rows */
    .misac-table-grid.ag-theme-alpine {
        height: auto !important;
    }

    .misac-table-grid.ag-theme-alpine .ag-header {
        background-color: #e8ecf0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .misac-table-grid.ag-theme-alpine .ag-row-odd {
        background-color: #f5f5f5 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Hide action/menu columns when printing */
    .no-print {
        display: none !important;
    }
}

/* ── Row action column ────────────────────────────────────────────────────── */

/* Cell wrapper: keeps icon buttons + ⋮ toggle on one line */
.misac-action-cell {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

/* Icon action buttons (always visible, one per icon_action item) */
.misac-action-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 0.75rem;
    color: #4a5568;
    border-radius: 3px;
    text-decoration: none;
    transition: background 0.1s, color 0.1s;
    flex-shrink: 0;
}

.misac-action-icon-btn:hover,
.misac-action-icon-btn:focus {
    background: #e2e8f0;
    color: #1a202c;
    text-decoration: none;
    outline: none;
}

/* ⋮ context menu trigger button */
.misac-action-ctx-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 0.75rem;
    color: #4a5568;
    background: none;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
    flex-shrink: 0;
}

.misac-action-ctx-toggle:hover,
.misac-action-ctx-toggle:focus {
    background: #e2e8f0;
    color: #1a202c;
    outline: none;
}

/* ── Shared context menu popup (single DOM element, reused across all rows) ─ */

.misac-ctx-menu {
    display: none;
    position: fixed;
    z-index: 10000;
    background: var(--m-surface, #fff);
    border: 1px solid var(--m-border, #dde1e7);
    border-radius: 5px;
    box-shadow: var(--m-shadow-lg, 0 4px 16px rgba(0, 0, 0, 0.13));
    min-width: 150px;
    padding: 4px 0;
    font-size: 0.78rem;
    animation: misac-ctx-in 0.08s ease;
}

@keyframes misac-ctx-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.misac-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    color: var(--m-text, #374151);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    border-bottom: dashed thin var(--m-border-light, rgba(0, 0, 0, 0.2));
}

.misac-ctx-item:hover {
    background: var(--mt-accent-light);
    color: var(--mt-accent);
    text-decoration: none;
}

.misac-ctx-item .fa {
    width: 14px;
    text-align: center;
    flex-shrink: 0;
    color: #6b7280;
}

.misac-ctx-item:hover .fa {
    color: #374151;
}

/* ── Column chooser panel ─────────────────────────────────────────────────── */

.misac-col-chooser {
    display: none;
    position: fixed;
    z-index: 10001;
    background: var(--m-surface, #fff);
    border: 1px solid var(--m-border, #dde1e7);
    border-radius: 5px;
    box-shadow: var(--m-shadow-lg, 0 4px 16px rgba(0, 0, 0, 0.13));
    min-width: 170px;
    max-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px 0 6px;
    font-size: 0.8rem;
    animation: misac-ctx-in 0.08s ease;
}

.misac-col-chooser-title {
    padding: 6px 12px 5px;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--mt-accent);
    border-bottom: 1px solid #eef0f3;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.misac-col-chooser-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 12px;
    cursor: pointer;
    color: var(--m-text, #374151);
    font-weight: normal;
    margin: 0;
    user-select: none;
    transition: background 0.08s;
}

.misac-col-chooser-item:hover {
    background: var(--mt-accent-light);
    color: var(--mt-accent);
}

.misac-col-chooser-item input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--mt-accent);
    cursor: pointer;
}

/* ── Drag-range cell selection ────────────────────────────────────────────── */

/* Highlighted cells inside a drag-selected range */
.misac-range-cell {
    background-color: rgba(34, 114, 181, 0.18) !important;
    outline: 1px solid rgba(34, 114, 181, 0.45);
    outline-offset: -1px;
}

/* ── Bulk action bar ──────────────────────────────────────────────────────── */

.misac-bulk-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: #2d3748;
    color: #fff;
    border-radius: 0 0 5px 5px;
    font-size: 0.8rem;
    transform: translateY(100%);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: transform 0.2s ease, opacity 0.2s ease, max-height 0.2s ease,
    padding 0.2s ease;
    padding-top: 0;
    padding-bottom: 0;
}

.misac-bulk-bar.active {
    transform: translateY(0);
    opacity: 1;
    max-height: 60px;
    padding-top: 8px;
    padding-bottom: 8px;
}

.misac-bulk-count {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.15);
    padding: 3px 10px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 0.78rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.misac-bulk-count::before {
    content: '\2713'; /* ✓ */
    font-weight: bold;
}

.misac-bulk-actions {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    flex: 1;
}

.misac-bulk-actions .btn {
    font-size: 0.75rem;
    padding: 3px 10px;
}

.misac-bulk-clear {
    margin-left: auto;
    font-size: 0.75rem !important;
    padding: 3px 10px !important;
    flex-shrink: 0;
}

@media print {
    .misac-bulk-bar {
        display: none !important;
    }
}

/* ── Subtotal rows ─────────────────────────────────────────────────────────── */

.misac-subtotal-row .ag-cell {
    font-weight: bold;
    font-style: italic;
    color: #1a5276;
}
