/* ============================================
   Maestro Connector — Frontend Styles v4
   Prefix: .maestro-
   ============================================ */

.maestro-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1e293b;
}

/* ---- Header & Title ---- */
.maestro-header {
    margin-bottom: 28px;
}

.maestro-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.maestro-title-row h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
}

.maestro-title-row h2 span {
    font-weight: 400;
    color: #64748b;
}

.maestro-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
}

.maestro-btn-icon:hover {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #2563eb;
}

/* ---- Enterprise Bar ---- */
.maestro-enterprise-bar {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 12px;
}

.maestro-sel-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.maestro-sel-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #64748b;
}

.maestro-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.maestro-enterprise-bar select {
    width: 100%;
    max-width: 400px;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: #1e293b;
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: auto;
}

.maestro-enterprise-bar select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* ---- Mode Tabs ---- */
.maestro-mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    background: #fff;
}

.maestro-mode-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    background: #fff;
    color: #64748b;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.maestro-mode-tab:first-child {
    border-right: 1px solid #e2e8f0;
}

.maestro-mode-tab:hover {
    background: #f8fafc;
    color: #334155;
}

.maestro-mode-tab.active {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: #fff;
    font-weight: 600;
}

.maestro-mode-tab svg {
    flex-shrink: 0;
}

/* ---- Sub-Navigation Buttons ---- */
.maestro-subnav,
.maestro-stat-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.maestro-subnav-btn {
    padding: 8px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #475569;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.maestro-subnav-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #1e293b;
}

.maestro-subnav-btn.active {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #2563eb;
    font-weight: 600;
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

/* ---- Project Sub-Nav ---- */
.maestro-subnav-project {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
}

.maestro-project-search-bar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.maestro-project-search-bar .maestro-autocomplete {
    max-width: 500px;
}

.maestro-stat-buttons {
    margin-bottom: 0;
}

/* ---- Top N Bar ---- */
.maestro-topn-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    padding: 8px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.maestro-topn-bar label {
    font-size: 13px;
    color: #64748b;
    font-weight: 500;
}

.maestro-topn-bar select {
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    color: #1e293b;
}

/* ---- Badge ---- */
.maestro-badge {
    font-size: 11px;
    color: #64748b;
    background: #e2e8f0;
    padding: 1px 7px;
    border-radius: 8px;
    font-weight: 600;
}

/* ---- Autocomplete ---- */
.maestro-autocomplete {
    position: relative;
}

.maestro-autocomplete input {
    width: 100%;
    padding: 10px 36px 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: #1e293b;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.maestro-autocomplete input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.maestro-autocomplete input:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

.maestro-ac-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    display: flex;
    align-items: center;
    pointer-events: none;
}

.maestro-ac-clear {
    pointer-events: all;
    cursor: pointer;
    color: #64748b;
    padding: 2px;
    border-radius: 4px;
    transition: color 0.15s;
}

.maestro-ac-clear:hover { color: #dc2626; }

.maestro-ac-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.maestro-ac-item {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid #f1f5f9;
}

.maestro-ac-item:last-child { border-bottom: none; }

.maestro-ac-item:hover,
.maestro-ac-item.maestro-ac-active { background: #eff6ff; }

.maestro-ac-code {
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
}

.maestro-ac-code mark,
.maestro-ac-desc mark {
    background: #fef08a;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.maestro-ac-desc {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.maestro-ac-empty {
    padding: 16px 14px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
}

.maestro-ac-info {
    padding: 10px 14px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
    border-top: 1px solid #f1f5f9;
}

/* Tag projet selectionne */
.maestro-selected-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #1d4ed8;
    max-width: 100%;
}

.maestro-selected-tag span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.maestro-tag-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: #3b82f6;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    border-radius: 4px;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.maestro-tag-remove:hover {
    background: #dbeafe;
    color: #dc2626;
}

/* ---- Loading ---- */
.maestro-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 20px;
    color: #64748b;
    font-size: 14px;
}

.maestro-spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: maestro-spin 0.7s linear infinite;
}

@keyframes maestro-spin {
    to { transform: rotate(360deg); }
}

/* ---- Error ---- */
.maestro-error {
    padding: 12px 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 14px;
    margin-bottom: 16px;
}

/* ====== EXECUTIVE DASHBOARD ====== */

.maestro-dash-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.maestro-kpi-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px;
    transition: box-shadow 0.15s;
}

.maestro-kpi-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.maestro-kpi-icon {
    font-size: 24px;
    line-height: 1;
    flex-shrink: 0;
}

.maestro-kpi-content {
    min-width: 0;
}

.maestro-kpi-value {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.maestro-kpi-label {
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
    margin-top: 2px;
}

/* Dashboard Charts Row */
.maestro-dash-charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.maestro-dash-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 16px;
}

.maestro-dash-card h3 {
    margin: 0 0 16px 0;
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
}

.maestro-dash-charts-row .maestro-dash-card {
    margin-bottom: 0;
}

.maestro-dash-chart-container {
    position: relative;
    max-height: 280px;
}

.maestro-dash-chart-container.maestro-dash-chart-tall {
    max-height: 450px;
    height: 400px;
}

/* Dashboard Alerts Row */
.maestro-dash-alerts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.maestro-dash-alerts-row .maestro-dash-card {
    margin-bottom: 0;
}

.maestro-dash-alert h3 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.maestro-alert-icon {
    font-size: 18px;
}

.maestro-dash-table-wrap {
    overflow-x: auto;
    max-height: 320px;
    overflow-y: auto;
}

/* ---- Result Panel ---- */
.maestro-results {
    animation: maestro-fadeIn 0.25s ease;
}

@keyframes maestro-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.maestro-result-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    gap: 12px;
    flex-wrap: wrap;
}

.maestro-result-banner-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.maestro-result-sep { opacity: 0.5; }

.maestro-result-project { font-size: 16px; }

.maestro-result-stat {
    background: rgba(255, 255, 255, 0.18);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
}

/* ---- Summary Cards ---- */
.maestro-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.maestro-summary-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    transition: box-shadow 0.15s;
}

.maestro-summary-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.maestro-summary-card .maestro-sc-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #64748b;
    margin-bottom: 6px;
    font-weight: 600;
}

.maestro-summary-card .maestro-sc-value {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
}

.maestro-summary-card .maestro-sc-value.positive { color: #16a34a; }
.maestro-summary-card .maestro-sc-value.negative { color: #dc2626; }

/* ---- Chart ---- */
.maestro-chart-wrap {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    max-height: 420px;
    position: relative;
}

/* ---- Tables ---- */
.maestro-table-wrap {
    overflow-x: auto;
    margin-bottom: 24px;
}

.maestro-table-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.maestro-count-badge {
    font-size: 12px;
    color: #64748b;
    background: #f1f5f9;
    padding: 3px 10px;
    border-radius: 10px;
    font-weight: 500;
}

.maestro-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.maestro-table thead th {
    background: #f8fafc;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.maestro-table thead th.num { text-align: right; }

.maestro-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.maestro-table tbody td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.maestro-table tbody tr:last-child td { border-bottom: none; }
.maestro-table tbody tr:hover { background: #f8fafc; }

/* Small table (for dashboard alerts) */
.maestro-table-sm { font-size: 12px; }
.maestro-table-sm thead th { padding: 8px 10px; font-size: 11px; }
.maestro-table-sm tbody td { padding: 7px 10px; }

/* Colors */
.maestro-positive { color: #16a34a; }
.maestro-negative { color: #dc2626; }
.maestro-warning { color: #d97706; }

/* ---- Health Badges ---- */
.maestro-health {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.maestro-health-green { background: #dcfce7; color: #15803d; }
.maestro-health-yellow { background: #fef9c3; color: #a16207; }
.maestro-health-red { background: #fee2e2; color: #b91c1c; }

/* ---- Empty State ---- */
.maestro-empty {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
    font-size: 14px;
}

.maestro-empty-icon { margin-bottom: 16px; }

.maestro-empty p {
    margin: 0;
    max-width: 380px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.5;
}

/* ---- Pulse animation ---- */
.maestro-pulse {
    animation: maestro-pulseAnim 0.75s ease 2;
}

@keyframes maestro-pulseAnim {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.25); border-radius: 8px; }
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .maestro-dash-kpis {
        grid-template-columns: repeat(2, 1fr);
    }

    .maestro-dash-charts-row,
    .maestro-dash-alerts-row {
        grid-template-columns: 1fr;
    }

    .maestro-result-banner {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    .maestro-container { padding: 12px; }

    .maestro-dash-kpis {
        grid-template-columns: 1fr 1fr;
    }

    .maestro-kpi-card { padding: 12px; }
    .maestro-kpi-value { font-size: 15px; }

    .maestro-subnav,
    .maestro-stat-buttons {
        flex-direction: column;
    }

    .maestro-subnav-btn { width: 100%; text-align: center; }

    .maestro-summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ====== LEGENDE ====== */
.maestro-legend {
    margin-top: 40px;
    padding: 24px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}

.maestro-legend h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
}

.maestro-legend h4::before {
    content: "\2139\FE0F";
    font-size: 18px;
}

.maestro-legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 16px;
}

.maestro-legend-section h5 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding-bottom: 6px;
    border-bottom: 2px solid #e2e8f0;
}

.maestro-legend-section ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.maestro-legend-section li {
    font-size: 13px;
    color: #475569;
    line-height: 1.6;
    padding: 3px 0;
}

.maestro-legend-section li strong {
    color: #1e293b;
}

.maestro-legend-section .maestro-health {
    vertical-align: middle;
}

.maestro-legend-note {
    margin: 0;
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.6;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.maestro-legend-note em {
    font-style: normal;
    font-weight: 600;
    color: #64748b;
}

@media (max-width: 768px) {
    .maestro-legend-grid {
        grid-template-columns: 1fr;
    }
}
