/* ============================================================================
   DASHBOARD STYLES (global, non-scoped)
   ============================================================================
   Ported from the Praxis dashboard.css and adapted to the Calendar casino app
   (purple accent, Font Awesome icons). This is a GLOBAL stylesheet (linked from
   App.razor) — NOT a scoped .razor.css — so it can:
     - size the grid row height / default widget sizes so content is not clipped
     - let per-widget popovers overflow the widget card (no clipping)
     - break the dashboard out of TabLayout's centered .tab-content-inner cap so
       the grid uses the full page width
     - size the widget header toolbar icons to match Praxis
     - drive the top-left drag/move grip, the company/date header controls and
       the super-user SQL debug modal

   The dashboard uses a 12-column CSS Grid; widgets span columns/rows.
   ============================================================================ */

/* ============================================================================
   FULL-PAGE WIDTH (gap 9)
   ============================================================================
   TabLayout centers page content in `.tab-content-inner { max-width: 1500px }`.
   When the dashboard is on the page we want the grid to fill the full content
   width. A full-bleed override expands the inner wrapper back out to the padded
   `.tab-content` width whenever it contains a `.dashboard-viewer`.
   ============================================================================ */

.tab-content-inner:has(.dashboard-viewer) {
    max-width: none;
    width: 100%;
}

/* The page wrapper itself should also stretch. */
.dashboard-page {
    width: 100%;
}

/* ============================================================================
   DASHBOARD VIEWER + HEADER
   ============================================================================ */

.dashboard-viewer {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Dashboard header with title and action buttons */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.dashboard-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dashboard-title h4 {
    margin: 0;
    font-weight: 600;
    color: #2c3e50;
    font-size: 1.15rem;
}

.dashboard-title > i {
    color: #6f42c1;
    font-size: 1.25rem;
}

.layout-name {
    color: #868e96;
    font-size: 0.9em;
}

.dashboard-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Buttons in dashboard header need position:relative for badge positioning */
.dashboard-actions .dashboard-btn,
.dashboard-actions .btn {
    position: relative;
}

/* Company count badge styling for dashboard header button */
.dashboard-actions .company-count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #6f42c1;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Date range label styling for dashboard header button */
.dashboard-actions .date-range-label {
    font-size: 0.75rem;
    margin-left: 4px;
}

/* Generic dashboard header button (Refresh All / Edit / Remove All / Add Widget) */
.dashboard-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid #ced4da;
    background: #fff;
    color: #495057;
    border-radius: 8px;
    padding: 0.4rem 0.85rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.dashboard-btn:hover {
    background: #f1f3f5;
}

.dashboard-btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.dashboard-btn.active,
.dashboard-btn.has-selection {
    background: #e7d9fb;
    border-color: #6f42c1;
    color: #6f42c1;
}

.dashboard-btn-primary {
    background: #6f42c1;
    border-color: #6f42c1;
    color: #fff;
}

.dashboard-btn-primary:hover {
    background: #5a32a3;
}

.dashboard-btn-danger {
    border-color: #f1aeb5;
    color: #dc3545;
}

.dashboard-btn-danger:hover {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
}

/* Global company / date selector wrappers in the header */
.global-company-selector,
.global-date-selector {
    position: relative;
}

/* ============================================================================
   WIDGET GRID (gap 1 — row height / default sizes so content is not clipped)
   ============================================================================
   12-column grid. grid-auto-rows uses minmax(110px, auto) so a default-sized
   KPI/chart/table renders its full content (Praxis used 100px; Calendar widgets
   carry a slightly taller header toolbar so 110px keeps a default 4x4 readable).
   ============================================================================ */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: minmax(110px, auto);
    gap: 16px;
    align-items: stretch;
}

.dashboard-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    color: #6c757d;
}

.dashboard-empty-icon,
.dashboard-empty > i {
    font-size: 3rem;
    color: #b9a4e0;
    margin-bottom: 1rem;
}

.dashboard-empty h4,
.dashboard-empty h5 {
    color: #495057;
    margin-bottom: 10px;
}

/* Responsive: collapse columns on smaller screens */
@media (max-width: 1200px) and (min-width: 769px) {
    .dashboard-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid-item,
    .widget-container {
        grid-column: 1 / -1 !important;
    }

    .dashboard-header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .dashboard-actions {
        justify-content: center;
    }
}

/* ============================================================================
   WIDGET CONTAINER
   ============================================================================
   IMPORTANT (gap 2): overflow is VISIBLE so per-widget popovers (info / filter /
   company / source) can overflow the card instead of being clipped. The body
   itself scrolls; the card does not hide overflow. popup-open raises z-index so
   an open popover sits above sibling widgets.
   ============================================================================ */

.widget-container {
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: visible;
    display: flex;
    flex-direction: column;
    min-height: 180px;
    height: 100%;
    transition: box-shadow 0.2s ease;
    position: relative;
    z-index: 1;
    align-self: stretch;
}

.widget-container.popup-open {
    z-index: 100;
}

.widget-container:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.widget-container.loading {
    opacity: 0.85;
}

.widget-container.error {
    border-color: #f1aeb5;
}

/* Widget being dragged / drop target */
.dashboard-grid-item.dragging .widget-container,
.widget-container.dragging {
    opacity: 0.55;
}

.dashboard-grid-item.drop-target .widget-container,
.widget-container.drop-target {
    border: 2px dashed #6f42c1;
    background: #f5f3fb;
}

/* ============================================================================
   DRAG-RESIZE HANDLES (edit mode) — replace the old +/- resize buttons.
   Ported from the Praxis WidgetContainer resize handles: a right edge (width),
   a bottom edge (height) and a corner (both). The handles are only rendered
   when the widget is Editable (edit mode).
   ============================================================================ */

.widget-resize-handle {
    position: absolute;
    z-index: 25;
    opacity: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.widget-container:hover .widget-resize-handle {
    opacity: 1;
}

.widget-resize-right {
    top: 12px;
    bottom: 12px;
    right: -3px;
    width: 8px;
    cursor: ew-resize;
}

.widget-resize-bottom {
    left: 12px;
    right: 12px;
    bottom: -3px;
    height: 8px;
    cursor: ns-resize;
}

.widget-resize-corner {
    right: -2px;
    bottom: -2px;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 0 50%, #b9a6e6 50% 60%, transparent 60% 70%, #b9a6e6 70% 80%, transparent 80%);
    border-bottom-right-radius: 10px;
}

.widget-resize-right:hover,
.widget-resize-bottom:hover {
    background-color: #6f42c1;
    border-radius: 4px;
}

.widget-resize-corner:hover {
    background: linear-gradient(135deg, transparent 0 45%, #6f42c1 45% 60%, transparent 60% 70%, #6f42c1 70% 85%, transparent 85%);
}

/* ============================================================================
   WIDGET HEADER + DRAG GRIP (gaps 7 + 10)
   ============================================================================ */

.widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #eef0f2;
    background: #fafbfc;
    position: relative;
    transition: background 0.2s ease;
}

/* Drag/move grip — top-left of the header (Praxis layout) */
.widget-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 8px;
    cursor: grab;
    color: #adb5bd;
    border-radius: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.widget-drag-handle:hover {
    background: #eee;
    color: #6f42c1;
}

.widget-drag-handle:active {
    cursor: grabbing;
    background: #e0e0e0;
    color: #5a32a3;
}

.widget-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9rem;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* The active date-range suffix in the title (gap 8) */
.widget-header-title .widget-title-range {
    font-weight: 500;
    color: #868e96;
    font-size: 0.82rem;
}

.widget-header-icon,
.widget-icon {
    color: #6f42c1;
    flex-shrink: 0;
}

.widget-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
}

/* HEADER TOOLBAR ICON BUTTONS (gap 10 — match Praxis sizing) */
.widget-action-btn,
.widget-icon-btn {
    background: none;
    border: none;
    padding: 5px 8px;
    cursor: pointer;
    color: #6c757d;
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1;
    position: relative;
    transition: all 0.2s ease;
}

.widget-action-btn:hover,
.widget-icon-btn:hover {
    background: #eef0f2;
    color: #343a40;
}

.widget-action-btn.active,
.widget-icon-btn.active {
    background: #f1ecfb;
    color: #6f42c1;
}

.widget-action-btn.active:hover,
.widget-icon-btn.active:hover {
    background: #e7d9fb;
    color: #5a32a3;
}

.widget-remove-btn:hover,
.widget-remove:hover {
    background: #fde2e2;
    color: #dc3545;
}

/* SQL/data-source debug button accent (super user) */
.widget-action-btn.sql-debug-btn,
.widget-icon-btn.sql-debug-btn {
    color: #2e7d32;
}

.widget-action-btn.sql-debug-btn:hover,
.widget-icon-btn.sql-debug-btn:hover {
    background: #e8f5e9;
    color: #1b5e20;
}

.widget-action-btn.sql-debug-btn.active,
.widget-icon-btn.sql-debug-btn.active {
    background: #c8e6c9;
    color: #1b5e20;
}

/* Casino scope dropdown in the widget header */
.widget-casino-select {
    max-width: 150px;
    font-size: 0.75rem;
    margin-right: 4px;
}

/* Per-widget company count badge */
.widget-company-badge,
.company-count-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #6f42c1;
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    border-radius: 8px;
    text-align: center;
    padding: 0 4px;
}

/* ============================================================================
   WIDGET BODY + FOOTER
   ============================================================================ */

.widget-body {
    flex: 1;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 0;
    overflow: auto;
}

.widget-footer {
    padding: 7px 14px;
    border-top: 1px solid #eef0f2;
    font-size: 0.72rem;
    color: #999;
    text-align: right;
}

.widget-loading,
.widget-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex: 1;
    padding: 20px;
    text-align: center;
    color: #868e96;
}

.widget-error {
    color: #dc3545;
}

.widget-error i {
    font-size: 1.8rem;
}

/* ============================================================================
   WIDGET POPOVERS (info / data source) — overflow the card (gap 2)
   ============================================================================ */

.widget-popover {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1001;
    width: 300px;
    max-width: 90vw;
    background: #fff;
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    animation: dashSlideDown 0.18s ease;
}

@keyframes dashSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.widget-popover-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: #fafbfc;
    border-bottom: 1px solid #eef0f2;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.82rem;
}

.widget-popover-body {
    padding: 12px;
    max-height: 340px;
    overflow-y: auto;
}

.info-row {
    margin-bottom: 0.6rem;
}

.info-row:last-child {
    margin-bottom: 0;
}

.info-row label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: #868e96;
    margin-bottom: 0.15rem;
}

.info-row p {
    margin: 0;
    font-size: 0.82rem;
    color: #495057;
}

.widget-source-name {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: #2c3e50;
    word-break: break-word;
}

/* When near the bottom of the viewport, popovers open upward */
.widget-container.popup-upward .widget-popover {
    top: auto;
    bottom: calc(100% + 8px);
    animation: dashSlideUp 0.18s ease;
}

@keyframes dashSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================================
   SUPER-USER SQL DEBUG MODAL (gap 3)
   ============================================================================
   Centered, movable modal showing the resolved executed query. Mirrors the
   Praxis SQL debug modal (dark code block, copy button, query-mode badge).
   ============================================================================ */

.sql-debug-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: dashFadeIn 0.15s ease;
}

@keyframes dashFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sql-debug-modal {
    /* Fixed + centered with a -50% transform baseline so makeSqlModalDraggable
       can offset the modal by dragging its header (faithful Praxis parity:
       Praxis positions this modal the same way). */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100001;
    width: 720px;
    max-width: 92vw;
    max-height: 82vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sql-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    font-weight: 600;
    background: linear-gradient(135deg, #2c1a4d, #16213e);
    color: #fff;
    user-select: none;
}

.sql-modal-header span {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sql-modal-header i {
    color: #8bc34a;
}

.sql-modal-close {
    background: none;
    border: none;
    padding: 6px 10px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
    font-size: 1.05rem;
    transition: all 0.2s ease;
}

.sql-modal-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.sql-modal-body {
    padding: 18px;
    overflow-y: auto;
    flex: 1;
}

.sql-section {
    margin-bottom: 14px;
}

.sql-section:last-child {
    margin-bottom: 0;
}

.sql-section label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.sql-section p {
    margin: 0;
    font-size: 0.88rem;
    color: #343a40;
}

.query-mode-badge .badge {
    font-size: 0.78rem;
}

.sql-query-text {
    background: #1a1a2e;
    color: #7fdbca;
    padding: 14px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 420px;
    overflow-y: auto;
    margin: 0;
    line-height: 1.5;
}

.sql-copy-btn {
    border: 1px solid #6f42c1;
    color: #6f42c1;
    background: transparent;
    padding: 2px 8px;
    font-size: 0.74rem;
    border-radius: 5px;
    cursor: pointer;
}

.sql-copy-btn:hover {
    background: #6f42c1;
    color: #fff;
}

/* ============================================================================
   STATUS MESSAGE (toast)
   ============================================================================ */

.dashboard-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    z-index: 100002;
    color: #fff;
    animation: dashSlideIn 0.3s ease;
}

.dashboard-status.success { background: #4caf50; }
.dashboard-status.error { background: #dc3545; }

@keyframes dashSlideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
