/* ============================================================
   AUDIT.CSS — Decision Audit Trail & Provenance Dashboard
   Phase 5: Timeline styles, entry cards, expand/collapse,
   tier badges, compliance export, admin dashboard.
   ============================================================ */

/* ─── Loading State ──────────────────────────────────────── */

.audit-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: #6b7280;
    font-size: 14px;
}

.audit-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #F97216;
    border-radius: 50%;
    animation: auditSpin 0.8s linear infinite;
}

@keyframes auditSpin {
    to { transform: rotate(360deg); }
}

/* ─── Empty State ────────────────────────────────────────── */

.audit-empty {
    text-align: center;
    padding: 60px 20px;
    color: #6b7280;
}

.audit-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.audit-empty h4 {
    font-size: 16px;
    color: #374151;
    margin-bottom: 8px;
}

.audit-empty p {
    font-size: 13px;
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ─── Audit Trail Container ──────────────────────────────── */

.audit-trail {
    padding: 0 0 40px;
}

.audit-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e7eb;
}

.audit-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0;
}

.audit-header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.audit-summary-stats {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.audit-stat {
    font-size: 12px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}

.audit-stat-icon {
    font-size: 10px;
}

/* ─── Timeline ───────────────────────────────────────────── */

.audit-timeline {
    position: relative;
    padding-left: 32px;
}

.audit-timeline::before {
    content: '';
    position: absolute;
    left: 11px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e5e7eb;
}

/* ─── Timeline Entry ─────────────────────────────────────── */

.audit-entry {
    position: relative;
    display: flex;
    gap: 0;
    margin-bottom: 20px;
}

.audit-marker {
    position: absolute;
    left: -32px;
    top: 2px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    background: #fff;
    z-index: 1;
}

.audit-entry-ai .audit-marker {
    color: #F97216;
}

.audit-entry-gate .audit-marker {
    color: #F97216;
    font-size: 14px;
}

.audit-content {
    flex: 1;
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px 18px;
    transition: border-color 0.2s;
}

.audit-content:hover {
    border-color: #d1d5db;
}

.audit-entry-gate .audit-content {
    background: #faf5ff;
    border-color: #e9d5ff;
}

.audit-entry-gate .audit-content:hover {
    border-color: #c4b5fd;
}

/* ─── Entry Header ───────────────────────────────────────── */

.audit-entry-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.audit-entry-header strong {
    font-size: 14px;
    color: #1a1a2e;
}

.audit-stage-badge {
    font-size: 11px;
    font-weight: 500;
    color: #6b7280;
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 4px;
}

/* ─── Decision Pill ──────────────────────────────────────── */

.audit-decision-pill {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
}

.audit-decision-approve {
    background: #FFF7ED;
    color: #EA580C;
}

.audit-decision-kill {
    background: #fee2e2;
    color: #991b1b;
}

.audit-decision-revise {
    background: #fef3c7;
    color: #92400e;
}

/* ─── Entry Meta ─────────────────────────────────────────── */

.audit-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.audit-meta span {
    font-size: 12px;
    color: #6b7280;
}

.audit-cost {
    font-weight: 600;
    color: #374151 !important;
}

.audit-confidence.low {
    color: #dc2626 !important;
    font-weight: 600;
}

.audit-validation-warn {
    color: #d97706 !important;
    font-weight: 500;
}

.audit-comment {
    font-size: 13px;
    color: #4b5563;
    font-style: italic;
    margin-bottom: 6px;
    line-height: 1.5;
}

.audit-time {
    font-size: 11px;
    color: #9ca3af;
    margin-bottom: 4px;
}

/* ─── Tier Badges ────────────────────────────────────────── */

.audit-tier-haiku {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: #F5F5F7;
    color: #6E6E73;
}

.audit-tier-sonnet {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
}

.audit-tier-opus {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: #f3e8ff;
    color: #7c3aed;
}

/* ─── Review Badge ───────────────────────────────────────── */

.audit-review {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.audit-review-accepted {
    background: #FFF7ED;
    color: #EA580C;
}

.audit-review-modified {
    background: #fef3c7;
    color: #92400e;
}

.audit-review-rejected {
    background: #fee2e2;
    color: #991b1b;
}

/* ─── Expand Button ──────────────────────────────────────── */

.audit-expand-btn {
    font-size: 11px;
    color: #6b7280;
    cursor: pointer;
    background: none;
    border: none;
    padding: 2px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.audit-expand-btn:hover {
    color: #F97216;
}

/* ─── Detail Panel (expanded) ────────────────────────────── */

.audit-detail {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

.audit-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.audit-detail-field {
    font-size: 12px;
}

.audit-detail-field.full-width {
    grid-column: 1 / -1;
}

.audit-detail-field label {
    display: block;
    font-weight: 600;
    color: #6b7280;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 2px;
}

.audit-detail-field span {
    color: #374151;
}

.audit-mono {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    color: #6b7280 !important;
}

.audit-code {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    color: #374151;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 4px 0 0;
}

.audit-errors {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
}

.audit-errors li {
    color: #dc2626;
    font-size: 12px;
    padding: 2px 0;
}

.audit-errors li::before {
    content: '\26A0\0020';
}

.audit-detail-error {
    color: #dc2626;
    font-size: 13px;
    padding: 8px 0;
}

.audit-detail-loading {
    color: #9ca3af;
    font-size: 12px;
    padding: 8px 0;
}

/* ─── Admin Provenance Dashboard ─────────────────────────── */

.prov-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 16px 0 24px;
}

.prov-stat-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.prov-stat-val {
    font-size: 22px;
    font-weight: 700;
    color: #1a1a2e;
}

.prov-stat-lbl {
    font-size: 12px;
    color: #6b7280;
    margin-top: 4px;
}

.prov-section {
    margin-bottom: 24px;
}

.prov-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

/* ─── Provenance Cards (white elevated containers) ────────── */

.prov-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s;
}

.prov-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.prov-card h4 {
    font-size: 15px;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.prov-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.prov-table th {
    text-align: left;
    padding: 8px 12px;
    background: #f8fafc;
    border-bottom: 2px solid #e5e7eb;
    font-weight: 600;
    color: #6b7280;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.prov-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    color: #4b5563;
}

.prov-table tr:hover td {
    background: #f8fafc;
}

/* ─── Cost Share Bars ───────────────────────────────────── */

.prov-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 20px;
}

.prov-bar {
    height: 8px;
    border-radius: 4px;
    background: #F97216;
    min-width: 2px;
    transition: width 0.3s ease;
}

.prov-bar-blue {
    background: #EA580C;
}

.prov-bar-purple {
    background: #6E6E73;
}

.prov-bar-label {
    font-size: 11px;
    color: #6b7280;
    font-weight: 600;
    white-space: nowrap;
}

/* ─── Audit Trail Pill in Stage Navigation ───────────────── */

.stage-pill-audit {
    background: transparent;
    border: 1px dashed #d1d5db;
    color: #6b7280;
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.stage-pill-audit:hover {
    border-color: #F97216;
    color: #F97216;
    background: #FFF7ED;
}

.stage-pill-audit.active {
    border-style: solid;
    border-color: #F97216;
    color: #F97216;
    background: #FFF7ED;
    font-weight: 600;
}

.stage-pill-audit-icon {
    font-size: 14px;
}

/* ─── Responsive ─────────────────────────────────────────── */

@media (max-width: 768px) {
    .audit-header {
        flex-direction: column;
    }

    .audit-header-actions {
        width: 100%;
    }

    .audit-header-actions button {
        flex: 1;
    }

    .audit-detail-grid {
        grid-template-columns: 1fr;
    }

    .prov-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .guard-rails-grid {
        grid-template-columns: 1fr;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Phase 6: Guard Rails Configuration UI
   ═══════════════════════════════════════════════════════════════ */

.guard-rails-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.gr-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    transition: border-color 0.3s, box-shadow 0.2s;
}

.gr-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.gr-card-active {
    border-color: #F97216;
    background: #FFF7ED;
}

.gr-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.gr-card-icon {
    font-size: 24px;
    line-height: 1;
}

.gr-card-title {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.gr-card-title strong {
    font-size: 14px;
    color: #1a1a2e;
}

.gr-card-type {
    font-size: 11px;
    color: #8E8E93;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.gr-card-desc {
    font-size: 12.5px;
    color: #6b7280;
    line-height: 1.4;
    margin: 0 0 12px;
}

.gr-card-config {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    transition: opacity 0.2s;
}

.gr-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gr-field label {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
}

.gr-field-check label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    cursor: pointer;
}

.gr-input {
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    color: #1f2937;
    transition: border-color 0.15s;
}

.gr-input:focus {
    outline: none;
    border-color: #F97216;
    box-shadow: 0 0 0 2px rgba(249, 114, 22, 0.1);
}

.gr-input:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
}

select.gr-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

/* Toggle Switch */
.gr-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.gr-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.gr-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #d1d5db;
    border-radius: 24px;
    transition: background 0.25s;
}

.gr-toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.gr-toggle input:checked + .gr-toggle-slider {
    background: #F97216;
}

.gr-toggle input:checked + .gr-toggle-slider::before {
    transform: translateX(20px);
}

.gr-save-btn {
    align-self: flex-start;
    margin-top: 4px;
}

/* ─── Guard Flag Badges in Audit Trail ──────────────────── */

.audit-guard-flag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.audit-guard-drift {
    background: #FFF3CD;
    color: #856404;
}

.audit-guard-cost {
    background: #FFECD2;
    color: #C65D00;
}

.audit-guard-confidence {
    background: #FFF0F0;
    color: #D33;
}

.audit-guard-clamped {
    background: #F5F5F7;
    color: #6E6E73;
}

.audit-guard-schema {
    background: #FFF3E0;
    color: #E65100;
}

/* ═══════════════════════════════════════════════════════════════
   Phase 7: Cost Intelligence Dashboard
   ═══════════════════════════════════════════════════════════════ */

.cost-trend-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 120px;
    padding: 0 4px;
    margin: 16px 0 8px;
}

.cost-trend-bar {
    flex: 1;
    min-width: 20px;
    background: linear-gradient(180deg, #F97216 0%, #FDBA74 100%);
    border-radius: 4px 4px 0 0;
    position: relative;
    transition: height 0.3s ease;
    cursor: default;
}

.cost-trend-bar:hover {
    opacity: 0.85;
}

.cost-trend-bar-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: #9ca3af;
    white-space: nowrap;
}

.cost-trend-bar-val {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
}

.cost-trend-labels {
    display: flex;
    justify-content: space-between;
    padding: 0 4px;
    margin-top: 24px;
}

.cost-trend-labels span {
    font-size: 10px;
    color: #9ca3af;
}

.entity-cost-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #6b7280;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    padding: 3px 10px;
    border-radius: 6px;
    margin-left: 12px;
}

.cost-projection-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #FFFBEB;
    border: 1px solid #FDE68A;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #92400E;
}

.cost-projection-row strong {
    color: #78350F;
}

/* ═══════════════════════════════════════════════════════════
   Phase 8: Webhook Admin Styles
   ═══════════════════════════════════════════════════════════ */

.webhook-form {
    margin-top: 12px;
}

.webhook-form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.webhook-form-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.webhook-form-field label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
}

.webhook-event-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: #FFF7ED;
    color: #EA580C;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .webhook-form-row {
        flex-direction: column;
    }
}
