/* ======================================================= */
/* QUARTZ DESIGN SYSTEM - PREMIUM SALES FORECASTING       */
/* ======================================================= */

:root {
    --q-bg: #0a0f1b;
    --q-panel: rgba(30, 41, 59, 0.4);
    --q-panel-border: rgba(148, 163, 184, 0.1);
    --q-panel-glow: rgba(59, 130, 246, 0.05);
    --q-text: #f8fafc;
    --q-text-muted: #94a3b8;
    --q-accent: #3b82f6;
    --q-accent-glow: rgba(59, 130, 246, 0.4);
    --q-success: #10b981;
    --q-warning: #f59e0b;
    --q-danger: #ef4444;
    --q-radius: 12px;
    --q-font-main: 'Inter', sans-serif;
    --q-font-display: 'Outfit', sans-serif;
}

#forecast-view {
    background: var(--q-bg);
    color: var(--q-text);
    font-family: var(--q-font-main);
    display: none;
    height: 100vh;
    overflow: hidden;
    flex-direction: column;
}

#forecast-view.active {
    display: flex;
}

/* Layout */
.quartz-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.scrollable {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--q-panel-border) transparent;
}

.scrollable::-webkit-scrollbar {
    width: 6px;
}

.scrollable::-webkit-scrollbar-thumb {
    background: var(--q-panel-border);
    border-radius: 10px;
}

/* Tree Grid Styles */
.grid-node-expander {
    transition: color 0.2s, transform 0.2s;
}
.grid-node-expander:hover {
    color: var(--q-text) !important;
    transform: scale(1.1);
}

.quartz-panel {
    background: var(--q-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--q-panel-border);
    border-radius: var(--q-radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--q-panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-label {
    font-family: var(--q-font-display);
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--q-text-muted);
}

/* Main Content */
.quartz-main {
    flex: 1;
    padding: 32px;
}

.quartz-content-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* Metrics Grid */
.quartz-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.q-metric-card {
    background: var(--q-panel);
    backdrop-filter: blur(8px);
    border: 1px solid var(--q-panel-border);
    border-radius: var(--q-radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.q-metric-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4), 0 0 20px var(--q-panel-glow);
    border-color: rgba(59, 130, 246, 0.3);
}

.q-metric-card label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--q-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-value {
    font-family: var(--q-font-display);
    font-size: 2rem;
    font-weight: 700;
    color: var(--q-text);
}

.q-metric-card.highlight .card-value {
    color: var(--q-success);
    text-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

/* Detail Panel Components */
.quartz-detail-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 32px;
}

.user-avatar-large {
    width: 64px;
    height: 64px;
    background: var(--q-panel-glow);
    border: 1px solid var(--q-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--q-font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--q-accent);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
}

.user-info-main h2 {
    margin: 0;
    font-family: var(--q-font-display);
    font-size: 1.5rem;
}

.user-role-badge {
    font-size: 0.75rem;
    color: var(--q-text-muted);
}

.quartz-detail-stats {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-bottom: 32px;
}

.qd-stat label, .qd-stat-mini label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--q-text-muted);
    display: block;
    margin-bottom: 8px;
}

.qd-val {
    font-family: var(--q-font-display);
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.qd-stat-row {
    display: flex;
    gap: 20px;
}

.qd-stat-mini {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    padding: 16px;
    border-radius: 8px;
}

.qd-val-mini {
    font-family: var(--q-font-display);
    font-size: 1.25rem;
    font-weight: 700;
}

.quartz-detail-notes {
    margin-bottom: 32px;
}

.quartz-detail-notes label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--q-text-muted);
    margin-bottom: 12px;
}

#quartz-user-note {
    width: 100%;
    height: 120px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--q-panel-border);
    border-radius: 8px;
    padding: 16px;
    color: var(--q-text);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    transition: border-color 0.2s;
}

#quartz-user-note:focus {
    border-color: var(--q-accent);
    outline: none;
}

.quartz-detail-actions {
    margin-top: auto;
}

/* The Grid */
.quartz-table-container {
    overflow-x: auto;
}

.quartz-table {
    width: 100%;
    border-collapse: collapse;
}

.quartz-table th {
    text-align: left;
    padding: 16px;
    font-size: 0.75rem;
    color: var(--q-text-muted);
    border-bottom: 1px solid var(--q-panel-border);
    background: rgba(255, 255, 255, 0.02);
}

/* th.text-right must beat .quartz-table th { text-align: left } (same specificity, later wins) */
.quartz-table th.text-right {
    text-align: right;
}

.quartz-table td {
    padding: 16px;
    border-bottom: 1px solid var(--q-panel-border);
    font-size: 0.9rem;
    color: var(--q-text);
}

.quartz-table tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.quartz-table .highlight-col {
    background: rgba(59, 130, 246, 0.03);
    border-left: 1px solid var(--q-panel-border);
    border-right: 1px solid var(--q-panel-border);
}

/* Forecast grid: hierarchy — depth, grouping, and row rhythm */
#forecast-view #forecast-body tr.forecast-grid-row td {
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

#forecast-view #forecast-body tr.fg-branch td {
    background: rgba(255, 255, 255, 0.035);
}

#forecast-view #forecast-body tr.fg-branch.fg-expanded td {
    background: rgba(59, 130, 246, 0.06);
    border-bottom-color: rgba(59, 130, 246, 0.22);
}

#forecast-view #forecast-body tr.fg-leaf td {
    background: rgba(15, 23, 42, 0.35);
}

#forecast-view #forecast-body tr[class*="fg-depth-"]:not(.fg-depth-0) td:first-child {
    box-shadow: inset 3px 0 0 rgba(59, 130, 246, 0.4);
}

#forecast-view #forecast-body tr.fg-group-end td {
    border-bottom: 2px solid rgba(148, 163, 184, 0.35);
    padding-bottom: calc(0.65rem + 2px);
}

#forecast-view .fg-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 1.25rem;
}

#forecast-view .fg-tree-icon.fg-tree-expander {
    cursor: pointer;
    width: 20px;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--q-text-muted);
    font-size: 0.72rem;
    border-radius: 6px;
    transition: color 0.15s ease, background 0.15s ease;
}

#forecast-view .fg-tree-expander:hover {
    color: var(--q-accent);
    background: rgba(59, 130, 246, 0.12);
}

#forecast-view .fg-tree-leaf {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    min-width: 20px;
    height: 20px;
}

#forecast-view .fg-tree-leaf::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--q-accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

#forecast-view .grid-panel > .panel-header {
    padding-bottom: 14px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

#forecast-view .quartz-table thead th {
    padding-top: 14px;
    padding-bottom: 12px;
}

/* Numeric columns: headers + cells share right edge; tabular figures for digit alignment */
#forecast-view .quartz-table thead th.text-right,
#forecast-view .quartz-table tbody td.text-right,
#forecast-view .quartz-table tfoot td.text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

#forecast-view .quartz-table thead th.highlight-col {
    padding-right: calc(0.75rem + 36px);
}

#forecast-view #forecast-body td.highlight-col {
    position: relative;
    vertical-align: middle;
    padding-right: calc(0.75rem + 36px);
}

#forecast-view #forecast-body td.highlight-col .td-forecast-container {
    display: block;
    text-align: right;
}

#forecast-view #forecast-body td.highlight-col .forecast-edit-btn {
    position: absolute;
    top: 50%;
    right: 0.45rem;
    transform: translateY(-50%);
    margin-left: 0;
}

#forecast-view #forecast-body td.highlight-col .forecast-table-display,
#forecast-view #forecast-body td.highlight-col .locked-val {
    display: inline-block;
    text-align: right;
    min-width: 0;
}

#forecast-view #forecast-footer td.highlight-col {
    padding-right: 0.75rem;
}

#forecast-view #forecast-body tr.forecast-grid-row:hover td {
    background: rgba(255, 255, 255, 0.07);
}

#forecast-view #forecast-body tr.forecast-grid-row.active-row td {
    background: rgba(59, 130, 246, 0.12);
}

#forecast-view #forecast-footer tr.footer-row td {
    border-top: 2px solid rgba(148, 163, 184, 0.4);
    background: rgba(255, 255, 255, 0.06);
    font-weight: 700;
    padding-top: 14px;
    padding-bottom: 14px;
}

.text-right { text-align: right; }

/* Inputs */
.forecast-input {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--q-panel-border);
    border-radius: 4px;
    padding: 6px 10px;
    color: var(--q-text);
    font-family: var(--q-font-display);
    font-weight: 700;
    text-align: right;
    width: 100px;
    transition: border-color 0.2s;
}

.forecast-input:focus {
    border-color: var(--q-accent);
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.forecaster-name-link {
    cursor: pointer;
    transition: color 0.2s, text-decoration 0.2s;
}

.forecaster-name-link:hover {
    color: var(--q-accent);
    text-decoration: underline;
}

.forecast-edit-btn {
    background: transparent;
    border: none;
    color: var(--q-text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s;
    margin-left: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.forecast-edit-btn:hover {
    color: var(--q-accent);
    background: rgba(59, 130, 246, 0.1);
}

.td-forecast-container {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.forecast-table-display {
    font-family: var(--q-font-display);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--q-text);
    min-width: 4.5rem;
    text-align: right;
}

.quartz-detail-forecast {
    margin-bottom: 16px;
}

.quartz-detail-forecast label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--q-text-muted);
    margin-bottom: 10px;
}

.forecast-input-panel {
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box;
    text-align: left;
    padding: 10px 12px !important;
    border-radius: 8px !important;
}

.forecast-panel-hint {
    margin: 8px 0 0;
    font-size: 0.72rem;
    color: var(--q-text-muted);
    line-height: 1.35;
}

.forecast-locked-display {
    font-family: var(--q-font-display);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--q-text);
}

.forecast-locked-display .muted {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--q-text-muted);
}

/* Detail Panel Overlay */
.quartz-detail-panel {
    position: absolute;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border-left: 1px solid var(--q-panel-border);
    z-index: 100;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 32px;
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.5);
}

.quartz-detail-panel.open {
    right: 0;
}

.panel-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--q-text-muted);
}

.panel-close-btn:hover { color: var(--q-text); }

/* Charts */
.quartz-insights-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.chart-container {
    padding: 24px;
    height: 300px;
}

/* Status Pills */
.status-pill {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.pill-win { background: rgba(16, 185, 129, 0.1); color: var(--q-success); border: 1px solid rgba(16, 185, 129, 0.2); }
.pill-commit { background: rgba(59, 130, 246, 0.1); color: var(--q-accent); border: 1px solid rgba(59, 130, 246, 0.2); }

/* Utilities */
.trend-indicator {
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
}
.trend-indicator.up { color: var(--q-success); }
.trend-indicator.down { color: var(--q-danger); }

.progress-mini {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--q-accent);
    box-shadow: 0 0 8px var(--q-accent);
}

.status-badge {
    align-self: flex-start;
    padding: 2px 8px;
    background: rgba(16, 185, 129, 0.15);
    color: var(--q-success);
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

/* Quartz Sidebar & Hierarchy */
.quartz-sidebar {
    width: 280px;
    background: rgba(15, 23, 42, 0.4);
    border-right: 1px solid var(--q-panel-border);
    display: flex;
    flex-direction: column;
}

.hierarchy-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: transparent;
    border: none;
    backdrop-filter: none;
}

.panel-header {
    padding: 24px 20px 16px;
    border-bottom: 1px solid var(--q-panel-border);
}

.panel-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--q-accent);
    margin-bottom: 16px;
}

.search-mini {
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--q-panel-border);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.search-mini:focus-within {
    border-color: var(--q-accent);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
}

.search-mini i {
    font-size: 0.8rem;
    color: var(--q-text-muted);
}

.search-mini input {
    background: transparent;
    border: none;
    color: var(--q-text);
    font-size: 0.85rem;
    width: 100%;
}

.search-mini input:focus {
    outline: none;
}

.hierarchy-tree {
    padding: 16px 0;
}

.tree-node {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    user-select: none;
}

.tree-node:hover {
    background: rgba(255, 255, 255, 0.03);
}

.tree-node.active {
    background: rgba(59, 130, 246, 0.1);
}

.tree-node.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--q-accent);
    box-shadow: 0 0 10px var(--q-accent);
}

.node-expander {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--q-text-muted);
    transition: transform 0.2s;
    margin-right: 4px;
}

.node-expander:hover {
    color: var(--q-text);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.node-content {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.node-avatar {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: var(--q-panel-glow);
    color: var(--q-accent);
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.tree-node.active .node-avatar {
    background: var(--q-accent);
    color: white;
}

.node-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--q-text);
}

.tree-node.active .node-name {
    color: white;
    font-weight: 600;
}

.depth-guide {
    position: absolute;
    left: 28px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 255, 255, 0.05);
}

/* Ensure Forecasting Header is one line */
#forecast-view .view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    padding: 24px 48px; /* Increased padding and vertical spacing */
}

#forecast-view .header-main {
    display: flex;
    align-items: center;
    gap: 24px;
}

#forecast-view .header-main h1 {
    margin: 0;
    font-size: 1.5rem;
    white-space: nowrap;
}

#forecast-view .header-controls {
    display: flex;
    gap: 16px;
    align-items: center;
}

#forecast-view .header-controls .custom-select-wrapper {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 8px;
    min-width: 155px; /* Slightly wider */
    height: 42px;    /* Taller for better vertical balance */
    display: flex;
    align-items: center;
    position: relative;
    transition: all 0.3s ease;
}

#forecast-view .header-controls .custom-select-wrapper:hover {
    background: rgba(30, 41, 59, 0.6);
    border-color: var(--q-accent);
}

#forecast-view .header-controls .mini-select {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    color: var(--q-text);
    padding: 0 32px 0 12px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

#forecast-view .header-controls .custom-select-wrapper::after {
    content: '\f107';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--q-text-muted);
    font-size: 0.8rem;
    /* Global .custom-select-wrapper::after uses an SVG background; clear it so we only show FA */
    background: none;
    background-image: none;
    width: auto;
    height: auto;
}

#forecast-view .header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}
/* Animation */
@keyframes q-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton-pulse {
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0.03) 25%, 
        rgba(255, 255, 255, 0.08) 50%, 
        rgba(255, 255, 255, 0.03) 75%);
    background-size: 200% 100%;
    animation: q-shimmer 2s infinite linear;
    border-radius: 4px;
    display: inline-block;
}

/* Metric Card Loading State */
.q-metric-card.loading .card-value {
    color: transparent !important;
    position: relative;
    overflow: hidden;
    min-height: 2.5rem;
}

.q-metric-card.loading .card-value::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.05) 50%, 
        transparent 100%);
    background-size: 200% 100%;
    animation: q-shimmer 2s infinite linear;
}

/* Detail Panel Loading State */
.quartz-detail-panel.loading .user-info-main h2,
.quartz-detail-panel.loading .qd-val,
.quartz-detail-panel.loading .qd-val-mini {
    color: transparent !important;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.quartz-detail-panel.loading .qd-val::after,
.quartz-detail-panel.loading .qd-val-mini::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.05) 50%, 
        transparent 100%);
    background-size: 200% 100%;
    animation: q-shimmer 2s infinite linear;
}

/* Ensure Grid Loading looks premium */
.loading-row td {
    padding: 32px !important;
    text-align: center;
    color: var(--q-text-muted);
    font-style: italic;
    background: rgba(255, 255, 255, 0.01);
}
