/* ==========================================================================
   Predictive Maintenance Advisor – Frontend Styles
   ========================================================================== */

/* ── CSS Variables ───────────────────────────────────────────────────────── */
.pma-wrapper {
    --pma-high:        #e53935;
    --pma-high-bg:     #fff5f5;
    --pma-high-border: #ffcdd2;
    --pma-medium:      #f59e0b;
    --pma-medium-bg:   #fffbeb;
    --pma-medium-border: #fde68a;
    --pma-low:         #22c55e;
    --pma-low-bg:      #f0fdf4;
    --pma-low-border:  #bbf7d0;
    --pma-anomaly:     #f97316;
    --pma-primary:     #3b82f6;
    --pma-primary-dark:#2563eb;
    --pma-text:        #1e293b;
    --pma-text-muted:  #64748b;
    --pma-border:      #e2e8f0;
    --pma-bg:          #f8fafc;
    --pma-white:       #ffffff;
    --pma-radius:      12px;
    --pma-shadow:      0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.05);

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--pma-text);
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.pma-card {
    background: var(--pma-white);
    border: 1px solid var(--pma-border);
    border-radius: var(--pma-radius);
    padding: 28px 32px;
    margin-bottom: 24px;
    box-shadow: var(--pma-shadow);
}

/* ── Upload card header ───────────────────────────────────────────────────── */
.pma-card-header {
    text-align: center;
    margin-bottom: 28px;
}
.pma-card-header .pma-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 8px;
}
.pma-card-header h2 {
    margin: 0 0 8px;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--pma-text);
}
.pma-card-header p {
    margin: 0;
    color: var(--pma-text-muted);
    font-size: .95rem;
}

/* ── Drop zone ───────────────────────────────────────────────────────────── */
.pma-drop-zone {
    border: 2px dashed var(--pma-border);
    border-radius: 10px;
    padding: 40px 24px;
    text-align: center;
    background: var(--pma-bg);
    transition: border-color .2s, background .2s;
    cursor: pointer;
    margin-bottom: 20px;
}
.pma-drop-zone.pma-drag-over {
    border-color: var(--pma-primary);
    background: #eff6ff;
}
.pma-drop-zone.pma-has-file {
    border-color: var(--pma-low);
    background: var(--pma-low-bg);
}
.pma-drop-icon {
    font-size: 42px;
    margin-bottom: 12px;
}
.pma-drop-text {
    margin: 0 0 12px;
    color: var(--pma-text-muted);
    font-size: .9rem;
}
.pma-file-name {
    margin: 12px 0 0;
    font-size: .85rem;
    color: var(--pma-text-muted);
    font-style: italic;
}

/* ── Required columns note ───────────────────────────────────────────────── */
.pma-required-cols {
    background: #f1f5f9;
    border-left: 3px solid var(--pma-primary);
    border-radius: 4px;
    padding: 10px 14px;
    font-size: .82rem;
    color: var(--pma-text-muted);
    margin-bottom: 20px;
    line-height: 1.6;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.pma-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 22px;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background .18s, transform .1s;
    line-height: 1;
}
.pma-btn:active { transform: scale(.98); }

.pma-btn-primary {
    background: var(--pma-primary);
    color: #fff;
    width: 100%;
    justify-content: center;
    font-size: 1rem;
    padding: 14px 22px;
}
.pma-btn-primary:hover { background: var(--pma-primary-dark); }
.pma-btn-primary:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
}

.pma-btn-secondary {
    background: #e2e8f0;
    color: var(--pma-text);
}
.pma-btn-secondary:hover { background: #cbd5e1; }

.pma-btn-outline {
    background: transparent;
    color: var(--pma-text-muted);
    border: 1px solid var(--pma-border);
}
.pma-btn-outline:hover { background: var(--pma-bg); }

/* ── Loading ─────────────────────────────────────────────────────────────── */
.pma-loading {
    text-align: center;
    padding: 40px 20px;
    background: var(--pma-white);
    border: 1px solid var(--pma-border);
    border-radius: var(--pma-radius);
    margin-bottom: 24px;
    box-shadow: var(--pma-shadow);
}

.pma-spinner {
    width: 52px;
    height: 52px;
    border: 4px solid #e2e8f0;
    border-top-color: var(--pma-primary);
    border-radius: 50%;
    animation: pma-spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes pma-spin {
    to { transform: rotate(360deg); }
}

.pma-loading p {
    margin: 0 0 12px;
    font-size: 1rem;
    color: var(--pma-text);
    font-weight: 500;
}

.pma-progress-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
}
.pma-progress-dots span {
    width: 8px;
    height: 8px;
    background: var(--pma-primary);
    border-radius: 50%;
    animation: pma-bounce 1.2s ease-in-out infinite;
}
.pma-progress-dots span:nth-child(2) { animation-delay: .2s; }
.pma-progress-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes pma-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: .4; }
    40%           { transform: scale(1);   opacity: 1; }
}

/* ── Error banner ────────────────────────────────────────────────────────── */
.pma-error-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: #fff5f5;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--pma-high);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 20px;
    font-size: .92rem;
    color: #7f1d1d;
}
.pma-error-banner .pma-error-icon { font-size: 18px; flex-shrink: 0; }
.pma-error-banner #pma-error-message { flex: 1; line-height: 1.5; }
.pma-error-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 14px;
    padding: 0;
    flex-shrink: 0;
}

/* ── Summary bar ─────────────────────────────────────────────────────────── */
.pma-summary-bar {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.pma-summary-pill {
    flex: 1;
    min-width: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: .85rem;
    border: 1px solid transparent;
}
.pma-pill-count {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
}
.pma-pill-high   { background: var(--pma-high-bg);   border-color: var(--pma-high-border);   color: var(--pma-high); }
.pma-pill-medium { background: var(--pma-medium-bg); border-color: var(--pma-medium-border); color: #92400e; }
.pma-pill-low    { background: var(--pma-low-bg);    border-color: var(--pma-low-border);    color: #166534; }
.pma-pill-anomaly { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }

/* ── Chart ───────────────────────────────────────────────────────────────── */
.pma-chart-card h3 { margin: 0 0 16px; font-size: 1.05rem; }
.pma-chart-wrap {
    display: flex;
    justify-content: center;
    max-height: 300px;
}
.pma-chart-wrap canvas { max-width: 300px !important; }

/* ── Risk sections ───────────────────────────────────────────────────────── */
.pma-risk-section h3 { margin: 0 0 18px; }
.pma-risk-badge {
    font-size: 1rem;
    font-weight: 700;
}
.pma-badge-high   { color: var(--pma-high); }
.pma-badge-medium { color: #92400e; }
.pma-badge-low    { color: #166534; }
.pma-badge-anomaly { color: var(--pma-anomaly); }
.pma-badge-recs   { color: #1d4ed8; }

/* ── Machine grid / card ─────────────────────────────────────────────────── */
.pma-machine-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.pma-machine-card {
    border: 1px solid var(--pma-border);
    border-radius: 10px;
    padding: 16px 18px;
    background: var(--pma-bg);
    transition: box-shadow .15s;
}
.pma-machine-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.1); }

.pma-machine-id {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.pma-risk-tag {
    font-size: .72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.pma-tag-high   { background: var(--pma-high-bg);   color: var(--pma-high);   border: 1px solid var(--pma-high-border); }
.pma-tag-medium { background: var(--pma-medium-bg); color: #92400e;           border: 1px solid var(--pma-medium-border); }
.pma-tag-low    { background: var(--pma-low-bg);    color: #166534;           border: 1px solid var(--pma-low-border); }

.pma-machine-urgency {
    font-size: .78rem;
    color: var(--pma-text-muted);
    margin: 0 0 10px;
}
.pma-machine-urgency strong { color: var(--pma-text); }

.pma-machine-reasons {
    margin: 0 0 10px;
    padding: 0;
    list-style: none;
    font-size: .82rem;
}
.pma-machine-reasons li::before { content: "• "; color: var(--pma-primary); font-weight: 700; }

.pma-machine-action {
    font-size: .82rem;
    background: var(--pma-white);
    border: 1px solid var(--pma-border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--pma-text-muted);
    line-height: 1.45;
}
.pma-machine-action strong { color: var(--pma-text); display: block; margin-bottom: 2px; }

/* ── Anomalies ───────────────────────────────────────────────────────────── */
.pma-anomaly-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.pma-anomaly-item {
    border: 1px solid #fed7aa;
    background: #fff7ed;
    border-radius: 8px;
    padding: 12px 16px;
}
.pma-anomaly-item .pma-anomaly-machine {
    font-weight: 700;
    font-size: .92rem;
    margin-bottom: 4px;
}
.pma-anomaly-item .pma-anomaly-desc {
    font-size: .85rem;
    color: var(--pma-text-muted);
    line-height: 1.45;
}
.pma-anomaly-item .pma-anomaly-date {
    font-size: .78rem;
    color: var(--pma-anomaly);
    margin-top: 4px;
}

/* ── Recommendations ─────────────────────────────────────────────────────── */
.pma-recs-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.pma-recs-list li {
    background: #eff6ff;
    border-left: 3px solid var(--pma-primary);
    border-radius: 4px;
    padding: 10px 14px;
    font-size: .88rem;
    line-height: 1.5;
    color: var(--pma-text);
}

/* ── Result actions ──────────────────────────────────────────────────────── */
.pma-result-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .pma-card { padding: 20px 18px; }
    .pma-summary-bar { flex-direction: column; }
    .pma-result-actions { flex-direction: column; }
    .pma-btn-primary, .pma-result-actions .pma-btn { width: 100%; justify-content: center; }
}

/* ── Sample download strip ───────────────────────────────────────────────── */
.pma-sample-download {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: .87rem;
    color: var(--pma-text-muted);
    flex-wrap: wrap;
}
.pma-sample-icon { font-size: 16px; flex-shrink: 0; }
.pma-sample-link {
    color: var(--pma-primary);
    font-weight: 600;
    text-decoration: none;
    margin-left: auto;
    white-space: nowrap;
}
.pma-sample-link:hover { text-decoration: underline; }

/* ── Quota bar ───────────────────────────────────────────────────────────── */
.pma-quota-bar {
    background: #f8fafc;
    border: 1px solid var(--pma-border);
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 22px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.pma-quota-item {
    flex: 1;
    min-width: 160px;
}
.pma-quota-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--pma-text);
}
.pma-quota-nums {
    font-weight: 700;
    color: var(--pma-text-muted);
    font-size: .8rem;
}
.pma-quota-track {
    background: #e2e8f0;
    border-radius: 20px;
    height: 8px;
    overflow: hidden;
}
.pma-quota-fill {
    height: 100%;
    border-radius: 20px;
    background: linear-gradient(90deg, var(--pma-primary), #6366f1);
    transition: width .4s ease;
    min-width: 4px;
}
.pma-quota-fill.pma-quota-warn  { background: linear-gradient(90deg, var(--pma-medium), #f97316); }
.pma-quota-fill.pma-quota-full  { background: linear-gradient(90deg, var(--pma-high), #dc2626); }

/* Quota exceeded message */
.pma-quota-exceeded-msg {
    margin: 12px 0 0;
    background: var(--pma-high-bg);
    border: 1px solid var(--pma-high-border);
    border-radius: 8px;
    padding: 10px 14px;
    color: #7f1d1d;
    font-size: .88rem;
    text-align: center;
}

/* ── PDF button override (primary style) ─────────────────────────────────── */
#pma-download-btn {
    background: #7c3aed;
    color: #fff;
}
#pma-download-btn:hover { background: #6d28d9; }
#pma-download-btn:disabled { background: #94a3b8; cursor: not-allowed; }

/* ── Fleet health bar ────────────────────────────────────────────────────── */
.pma-fleet-health-bar {
    border-radius: 10px;
    padding: 13px 18px;
    font-size: .92rem;
    margin-bottom: 20px;
    border: 1px solid transparent;
}
.pma-health-critical   { background:#fff5f5; border-color:#fecaca; color:#7f1d1d; }
.pma-health-attention  { background:#fffbeb; border-color:#fde68a; color:#78350f; }
.pma-health-acceptable { background:#f0fdf4; border-color:#bbf7d0; color:#14532d; }
.pma-health-good       { background:#f0fdf4; border-color:#bbf7d0; color:#14532d; }

/* ── Machine card v3 (with meta row + stats row) ─────────────────────────── */
.pma-mc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}
.pma-mc-id {
    font-size: .98rem;
    font-weight: 700;
}
.pma-mc-meta {
    font-size: .8rem;
    color: var(--pma-text-muted);
    margin-bottom: 6px;
}
.pma-mc-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: .78rem;
    color: var(--pma-text-muted);
    background: var(--pma-bg);
    border-radius: 6px;
    padding: 6px 10px;
    margin-bottom: 10px;
}
.pma-mc-stats span { white-space: nowrap; }

/* ── Downtime table ──────────────────────────────────────────────────────── */
.pma-dt-note {
    font-size: .82rem;
    color: var(--pma-text-muted);
    background: #fffbeb;
    border-left: 3px solid var(--pma-medium);
    padding: 8px 12px;
    border-radius: 4px;
    margin-bottom: 14px;
}
.pma-downtime-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .86rem;
    margin-bottom: 12px;
}
.pma-downtime-table th {
    background: #f1f5f9;
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--pma-text);
    border-bottom: 2px solid var(--pma-border);
}
.pma-downtime-table td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--pma-border);
    vertical-align: middle;
}
.pma-downtime-table tr:last-child td { border-bottom: none; }
.pma-downtime-table tr:nth-child(even) td { background: #f8fafc; }

.pma-dt-bar {
    background: #e2e8f0;
    border-radius: 20px;
    height: 10px;
    min-width: 80px;
    overflow: hidden;
}
.pma-dt-fill {
    height: 100%;
    border-radius: 20px;
    background: linear-gradient(90deg, #1e40af, #3b82f6);
    transition: width .4s ease;
    min-width: 4px;
}

.pma-dt-insight {
    font-size: .84rem;
    font-style: italic;
    color: var(--pma-text-muted);
    background: #eff6ff;
    border-radius: 6px;
    padding: 8px 12px;
    margin-top: 4px;
}
.pma-dt-top {
    display: inline-block;
    font-size: .78rem;
    background: #fef3c7;
    color: #92400e;
    padding: 3px 10px;
    border-radius: 20px;
    margin-top: 8px;
    font-weight: 600;
}

/* ── Anomaly type label ───────────────────────────────────────────────────── */
.pma-anomaly-type {
    display: inline-block;
    font-size: .75rem;
    background: #fff7ed;
    color: var(--pma-anomaly);
    border: 1px solid #fed7aa;
    padding: 1px 8px;
    border-radius: 20px;
    margin-bottom: 5px;
    font-weight: 600;
}
.pma-anom-sev {
    font-size: .73rem;
    font-weight: 700;
    margin-left: 6px;
}

/* Downtime badge color */
.pma-badge-downtime { color: #1d4ed8; }
