/* History Page — Day Cards & Timeline (Feature 007) */

/* Date Range Picker */
.date-range-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.date-range-section label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
}
.date-range-section input[type="date"] {
    padding: 6px 10px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #1e293b);
}
.date-range-section .load-btn {
    padding: 6px 16px;
    border: none;
    border-radius: 6px;
    background: var(--primary, #3b82f6);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.date-range-section .load-btn:hover {
    background: var(--primary-dark, #2563eb);
}

/* Day Cards Container */
.day-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

/* Day Card */
.day-card {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    padding: 14px 16px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
}
.day-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    border-color: var(--primary, #3b82f6);
}
.day-card.no-activity {
    opacity: 0.55;
}
.day-card.no-activity:hover {
    opacity: 0.75;
}
.day-card.expanded {
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 2px 12px rgba(59,130,246,0.12);
}

/* Day Card Header */
.day-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.day-card-date {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary, #1e293b);
}
.day-card-trend {
    font-size: 16px;
    font-weight: 700;
}

/* Trend indicators */
.trend-up { color: #16a34a; }
.trend-down { color: #dc2626; }
.trend-unchanged { color: #94a3b8; }

/* Day Card Body — metric grid */
.day-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
}
.day-card-metric {
    display: flex;
    flex-direction: column;
}
.day-card-metric-label {
    font-size: 11px;
    color: var(--text-secondary, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.day-card-metric-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    font-variant-numeric: tabular-nums;
}

/* No-activity label */
.day-card-no-activity {
    text-align: center;
    color: var(--text-secondary, #64748b);
    font-size: 13px;
    padding: 8px 0;
}

/* Timeline (inside expanded card) */
.day-timeline {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border, #e2e8f0);
}
.timeline-event {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 0;
    position: relative;
}
.timeline-event + .timeline-event {
    border-top: 1px dashed var(--border, #e2e8f0);
}
.timeline-event-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    background: var(--bg-secondary, #f1f5f9);
}
.timeline-event-icon.balance_check { background: rgba(59,130,246,0.12); color: #3b82f6; }
.timeline-event-icon.wholesale_batch { background: rgba(34,197,94,0.12); color: #16a34a; }
.timeline-event-icon.retail_sale { background: rgba(168,85,247,0.12); color: #9333ea; }
.timeline-event-icon.allocation { background: rgba(234,179,8,0.12); color: #b45309; }

.timeline-event-content {
    flex: 1;
    min-width: 0;
}
.timeline-event-time {
    font-size: 11px;
    color: var(--text-secondary, #64748b);
    font-variant-numeric: tabular-nums;
}
.timeline-event-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}
.timeline-event-details {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    margin-top: 2px;
}

/* Empty state for day cards */
.day-cards-empty {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary, #64748b);
}
.day-cards-empty i {
    font-size: 32px;
    margin-bottom: 8px;
    display: block;
}

/* Loading state */
.day-cards-loading {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary, #64748b);
}

/* Divider between day-cards and job history */
.history-divider {
    margin: 32px 0 20px;
    border: none;
    border-top: 1px solid var(--border, #e2e8f0);
}

/* Live badge */
.summary-live-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    background: rgba(34,197,94,0.15);
    color: #16a34a;
    vertical-align: middle;
    margin-left: 4px;
}

/* ── Job History Detail View ──────────────────────────────────── */

/* Clickable rows */
.job-history-table .clickable-row {
    cursor: pointer;
    transition: background 0.15s;
}
.job-history-table .clickable-row:hover {
    background: var(--bg-secondary, #f1f5f9);
}
.job-history-table .clickable-row.expanded {
    background: var(--bg-secondary, #f1f5f9);
    border-left: 3px solid var(--primary, #3b82f6);
}

/* Detail row (inserted below clicked row) */
.job-detail-row {
    background: var(--bg-primary, #fff);
}
.job-detail-row:hover {
    background: var(--bg-primary, #fff);
}
.job-detail-row td {
    padding: 0 !important;
}

/* Detail panel inside the row */
.job-detail-panel {
    padding: 16px 20px;
    margin: 4px 8px 12px;
    background: var(--bg-secondary, #f8fafc);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
}

/* Header grid (type, source, status, times) */
.detail-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border, #e2e8f0);
}
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px 24px;
}
.detail-kv {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.detail-key {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary, #64748b);
}
.detail-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1e293b);
}

/* Sections (Result, Error) */
.detail-section {
    margin-top: 12px;
}
.detail-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.detail-section-title i {
    font-size: 14px;
}
.detail-section-title .fa-exclamation-circle {
    color: #dc2626;
}
.detail-section-title .fa-clipboard-check {
    color: #16a34a;
}

/* Error block */
.detail-error-block {
    background: rgba(220,38,38,0.06);
    border: 1px solid rgba(220,38,38,0.2);
    border-radius: 6px;
    padding: 10px 14px;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 12px;
    color: #dc2626;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}
.detail-error {
    color: #dc2626;
    font-size: 13px;
    padding: 8px 0;
}
.detail-error-list {
    margin: 0;
    padding: 0 0 0 20px;
    font-size: 12px;
    color: #dc2626;
}
.detail-error-list li {
    margin-bottom: 4px;
}

/* JSON fallback */
.detail-json {
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    padding: 10px 14px;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 12px;
    color: var(--text-primary, #1e293b);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
    max-height: 400px;
    overflow-y: auto;
}

/* Subtable (e.g. vehicle details, diff groups) */
.detail-subtable {
    margin-top: 10px;
}
.detail-subtable h5,
.detail-diff-summary h5 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 8px 0 6px;
}
.detail-subtable .data-table.compact,
.detail-diff-summary .data-table.compact {
    font-size: 12px;
}
.detail-subtable .data-table.compact th,
.detail-subtable .data-table.compact td,
.detail-diff-summary .data-table.compact th,
.detail-diff-summary .data-table.compact td {
    padding: 4px 10px;
}

/* Muted text */
.detail-muted {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    font-style: italic;
    padding: 4px 0;
}

/* Running indicator */
.detail-running {
    font-size: 13px;
    color: var(--primary, #3b82f6);
    padding: 8px 0;
}
.detail-running i {
    margin-right: 6px;
}

/* Text helpers */
.text-success { color: #16a34a; }
.text-danger { color: #dc2626; }

/* ── Progress Steps Timeline ────────────────────────────────── */

.progress-steps {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.progress-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}
.progress-step:hover {
    background: rgba(0,0,0,0.02);
}

/* Step status icon */
.progress-step-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    flex-shrink: 0;
    margin-top: 1px;
}
.progress-step-icon.done {
    background: rgba(34,197,94,0.12);
    color: #16a34a;
}
.progress-step-icon.running {
    background: rgba(59,130,246,0.12);
    color: #3b82f6;
}
.progress-step-icon.pending {
    background: var(--bg-secondary, #f1f5f9);
    color: #94a3b8;
}
.progress-step-icon.error {
    background: rgba(220,38,38,0.10);
    color: #dc2626;
}

/* Step body */
.progress-step-body {
    flex: 1;
    min-width: 0;
}
.progress-step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.progress-step-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}
.progress-step-pending .progress-step-label {
    color: var(--text-secondary, #94a3b8);
}
.progress-step-duration {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary, #64748b);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.progress-step-data {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.progress-step-error .progress-step-data {
    color: #dc2626;
}

/* ── Stop Job Button ────────────────────────────────────────── */

.detail-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}
.detail-header-top .detail-grid {
    flex: 1;
}
.detail-stop-area {
    flex-shrink: 0;
    padding-top: 2px;
}
.stop-job-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    background: #dc2626;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}
.stop-job-btn:hover {
    background: #b91c1c;
}
.stop-job-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Cancelled status badge */
.scheduler-job-status.cancelled {
    background: rgba(234,179,8,0.12);
    color: #b45309;
}
