/* === Dashboard Selector === */
.dashboard-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.dashboard-selector select {
    min-width: 180px;
}
.dashboard-selector .icon-btn {
    padding: 0.3rem 0.5rem;
}
.dashboard-selector .icon-btn svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    display: block;
}
.dashboard-selector .icon-btn:hover svg {
    color: var(--danger);
}

/* === Dashboard Tabs === */
.dashboard-tab-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.dashboard-tabs {
    display: flex;
    align-items: center;
    overflow-x: auto;
    padding-bottom: 0;
    flex: 1 1 auto;
    min-width: 0;
    gap: 0.5rem;
}
.dashboard-tabs-row {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    height: 100%;
}
.dashboard-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.dashboard-tab.active {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--accent);
}
.dashboard-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.dashboard-tab.drag-over {
    border-color: var(--accent);
}
.dashboard-tab.dragging {
    opacity: 0.6;
}
.dashboard-tab-add {
    border-style: dashed;
    color: var(--text-muted);
}
.tab-delete {
    margin-left: 0.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.tab-delete:hover {
    color: var(--danger);
}
.tabs-error {
    padding: 0.5rem 0.75rem;
    border: 1px dashed var(--danger);
    color: var(--danger);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

/* === Tile Toolbar === */
.tile-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-left: 0;
    flex: 0 0 auto;
}
.dashboard-tab-row .tile-toolbar {
    justify-content: flex-end;
}
.tile-toolbar .btn {
    line-height: 1;
}

/* === Grid === */
.grid-stack {
    min-height: 200px;
}
.grid-stack-item-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
/* Subtle resize handle, bottom-right only */
.grid-stack-item > .ui-resizable-handle {
    background-image: none;
}
.grid-stack-item > .ui-resizable-n,
.grid-stack-item > .ui-resizable-s,
.grid-stack-item > .ui-resizable-e,
.grid-stack-item > .ui-resizable-w,
.grid-stack-item > .ui-resizable-ne,
.grid-stack-item > .ui-resizable-nw,
.grid-stack-item > .ui-resizable-sw {
    display: none !important;
}
.grid-stack-item > .ui-resizable-se {
    width: 14px;
    height: 14px;
    right: 2px;
    bottom: 2px;
    opacity: 0.6;
    transform: none;
    cursor: se-resize;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="%239aa0a6" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" viewBox="0 0 14 14"><path d="M3 11h8M11 3v8M6 11l5-5"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
}

/* === Tile === */
.tile {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.tile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    min-height: 44px;
    flex-shrink: 0;
}
.tile-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.tile-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}
.tile-alert-triggered {
    border-color: var(--danger);
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
}
.tile-alert-triggered .tile-header {
    border-bottom-color: rgba(239, 68, 68, 0.35);
}
.tile-alert-badge {
    margin-left: 0.5rem;
    padding: 0.1rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    align-self: center;
}
.tile-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all var(--transition);
}
.tile-action-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.tile-body {
    flex: 1;
    padding: 1rem;
    overflow: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.tile-prompt {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* === Tile: Number Display === */
.tile-number {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
}
.tile-number .number-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    max-width: 100%;
    text-align: center;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.tile-number .number-compare {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
}
.tile-number .number-up {
    color: var(--success);
}
.tile-number .number-down {
    color: var(--danger);
}

.tile-kpi {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    text-align: center;
}
.kpi-value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    max-width: 100%;
    text-align: center;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.kpi-delta {
    margin-top: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
}
.kpi-up {
    color: var(--success);
}
.kpi-down {
    color: var(--danger);
}
.kpi-label {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* === Tile: Table Display === */
.tile-table-wrap {
    flex: 1;
    overflow: auto;
}

.tile-chart {
    flex: 1;
    min-height: 0;
}
.tile-chart canvas {
    width: 100% !important;
    height: 100% !important;
}
.tile-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.tile-table th {
    text-align: left;
    padding: 0.4rem 0.6rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    white-space: nowrap;
}
.tile-table td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid var(--border);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tile-table tr:hover td {
    background: var(--bg-hover);
}

/* === Tile: Chart Display === */
.tile-chart {
    flex: 1;
    position: relative;
    min-height: 0;
}
.tile-chart canvas {
    width: 100% !important;
    height: 100% !important;
}

/* === Tile: Loading/Error === */
.tile-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 0.5rem;
    color: var(--text-secondary);
}
.tile-error {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem;
}

.tile-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 0.35rem;
    padding: 1rem;
    min-height: 120px;
    color: var(--text-muted);
    text-align: center;
}

.tile-empty-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.tile-empty-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* === Tile: Prompt Input === */
.tile-prompt-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 1rem;
    padding: 1rem;
}
.tile-prompt-input textarea {
    width: 100%;
    min-height: 60px;
    resize: vertical;
}
.tile-prompt-input .btn {
    align-self: flex-end;
}

@media (max-width: 600px) {
    .tile-header {
        padding: 0.6rem 0.75rem;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .tile-title {
        white-space: normal;
    }

    .tile-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .tile-body {
        padding: 0.75rem;
    }

    .tile-table {
        font-size: 0.75rem;
    }

    .tile-table th,
    .tile-table td {
        padding: 0.35rem 0.45rem;
    }
}

/* === Conversation Panel === */
.conversation-panel {
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    flex-shrink: 0;
}
.conversation-history {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 0.5rem;
}
.conv-msg {
    padding: 0.4rem 0;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border);
}
.conv-msg:last-child {
    border-bottom: none;
}
.conv-msg-user {
    color: var(--accent);
}
.conv-msg-ai {
    color: var(--text-secondary);
}
.conversation-input {
    display: flex;
    gap: 0.5rem;
}
.conversation-input input {
    flex: 1;
    font-size: 0.85rem;
}

.adhoc-input-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.adhoc-input-row textarea {
    flex: 1;
}

.adhoc-result-block {
    margin-top: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
}
.adhoc-result-title {
    font-weight: 600;
    margin-bottom: 0.35rem;
}

/* Force tabs + toolbar inline row (override any downstream rules) */
#view-dashboard .dashboard-tab-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
#view-dashboard .dashboard-tabs {
    min-width: 0;
    flex: 1 1 auto;
}
#view-dashboard .tile-toolbar {
    flex: 0 0 auto;
    justify-content: flex-end;
}

/* Force tabs visible + toolbar right aligned (override) */
#dashboard-tabs { display: flex !important; }
#view-dashboard .dashboard-tabs { min-width: 0; }
#view-dashboard .tile-toolbar { justify-content: flex-end !important; }

/* Force tab row layout */
.dashboard-tab-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

/* Ensure tabs and toolbar are side by side */
.dashboard-tab-row > .dashboard-tabs,
.dashboard-tab-row > .tile-toolbar {
    flex-shrink: 0;
}
.dashboard-tab-row > .dashboard-tabs {
    flex: 1 1 auto;
    min-width: 0;
}
.dashboard-tab-row > .tile-toolbar {
    flex: 0 0 auto;
}
