/* =================================================================
   Finite State Report Kit — Web UI Styles
   Ported from _design_system.html + new layout styles
   ================================================================= */

/* ── RESET & BASE ─────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── TOP NAVIGATION ───────────────────────────────────────────── */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background-color: #2c3e50;
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand a {
    color: white;
    font-weight: 700;
    font-size: 1.1em;
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: 24px;
}

.nav-link {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 0.9em;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-link:hover, .nav-link.active {
    color: white;
    border-bottom-color: #007bff;
    text-decoration: none;
}

/* ── ACTIVE RUNS INDICATOR ─────────────────────────────────────── */
#active-runs-indicator {
    display: flex;
    align-items: center;
    margin-left: 8px;
}

.active-runs-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.15);
    padding: 4px 12px;
    border-radius: 16px;
}

.run-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #28a745;
    animation: pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

.active-run-link {
    color: #a0d8ef;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 500;
    white-space: nowrap;
}

.active-run-link:hover {
    color: white;
    text-decoration: underline;
}

.completed-run-link {
    color: #a5d6a7;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 12px;
    background-color: rgba(40, 167, 69, 0.2);
    margin-left: 8px;
}

.completed-run-link:hover {
    color: white;
    text-decoration: none;
}

/* ── MAIN CONTENT ─────────────────────────────────────────────── */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ── STATUS BAR ───────────────────────────────────────────────── */
.status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 12px 16px;
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin-bottom: 24px;
    font-size: 0.85em;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-label {
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.75em;
    font-weight: 600;
}

.status-value {
    color: #2c3e50;
    font-weight: 500;
}

.status-value.connected { color: #28a745; }
.status-value.disconnected { color: #dc3545; }

/* ── DASHBOARD LAYOUT ─────────────────────────────────────────── */
.dashboard-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 900px) {
    .dashboard-layout { grid-template-columns: 1fr; }
}

.section-heading {
    font-size: 1.2em;
    color: #2c3e50;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

/* ── WORKFLOW CARDS ────────────────────────────────────────────── */
.workflow-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.workflow-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.workflow-card:hover {
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.15);
}

.workflow-icon {
    font-size: 1.8em;
    flex-shrink: 0;
}

.workflow-info {
    flex: 1;
}

.workflow-info h3 {
    font-size: 1em;
    color: #2c3e50;
    margin-bottom: 2px;
}

.workflow-info p {
    font-size: 0.85em;
    color: #6c757d;
    margin: 0;
}

/* ── RECIPE LIST ──────────────────────────────────────────────── */
.recipe-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.recipe-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.recipe-item:hover {
    background-color: #f8f9fa;
}

.recipe-item input[type="checkbox"] {
    margin-top: 4px;
    flex-shrink: 0;
}

.recipe-info {
    display: flex;
    flex-direction: column;
}

.recipe-name {
    font-weight: 500;
    color: #2c3e50;
}

.recipe-category {
    font-size: 0.8em;
    color: #6c757d;
    background-color: #f0f0f0;
    padding: 1px 8px;
    border-radius: 10px;
    display: inline-block;
    margin-top: 2px;
    width: fit-content;
}

.recipe-desc {
    font-size: 0.8em;
    color: #6c757d;
    margin-top: 2px;
}

.recipe-actions {
    display: flex;
    gap: 8px;
}

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    background-color: white;
    color: #495057;
    text-decoration: none;
    transition: all 0.15s;
    line-height: 1.4;
}

.btn:hover {
    background-color: #f8f9fa;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0069d9;
    border-color: #0062cc;
}

.btn-warning {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #333;
}

.btn-warning:hover {
    background-color: #e0a800;
    border-color: #d39e00;
}

.btn-danger {
    background-color: #dc3545;
    border-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-default {
    background-color: white;
    color: #495057;
}

.btn-sm {
    padding: 4px 12px;
    font-size: 0.85em;
}

/* ── PRERUN OVERLAY / PANEL ───────────────────────────────────── */
.prerun-overlay {
    display: none;
}

.prerun-overlay.active {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    height: 100vh;
    background-color: white;
    border-left: 1px solid #dee2e6;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    overflow-y: auto;
    z-index: 200;
}

.prerun-panel {
    padding: 24px;
}

.prerun-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
}

.prerun-header h2 {
    font-size: 1.3em;
    color: #2c3e50;
}

.prerun-recipes {
    font-size: 0.85em;
    color: #6c757d;
    margin-top: 4px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.5em;
    color: #6c757d;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.btn-close:hover {
    color: #333;
}

.prerun-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

/* ── FORM SECTIONS ────────────────────────────────────────────── */
.form-section {
    margin-bottom: 16px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    overflow: hidden;
}

.form-section[open] > .form-section-title {
    border-bottom: 1px solid #e9ecef;
}

.form-section-title {
    padding: 12px 16px;
    font-weight: 600;
    color: #2c3e50;
    background-color: #f8f9fa;
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-size: 0.95em;
}

.form-section-title::-webkit-details-marker { display: none; }

.form-section-title::before {
    content: '▸';
    display: inline-block;
    margin-right: 8px;
    transition: transform 0.2s;
}

.form-section[open] > .form-section-title::before {
    transform: rotate(90deg);
}

.form-section > :not(summary) {
    padding: 4px 16px;
}

.form-group {
    margin-bottom: 12px;
    padding: 0 16px;
}

.form-group:first-of-type {
    margin-top: 12px;
}

.form-group:last-child {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85em;
    font-weight: 500;
    color: #495057;
    margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.9em;
    background-color: white;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.form-row > label:first-child {
    margin-bottom: 0;
}

.form-static {
    padding: 8px 0;
    color: #495057;
}

.form-hint {
    font-size: 0.8em;
    color: #adb5bd;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

.form-actions-row {
    display: flex;
    gap: 8px;
    padding: 0 16px 16px;
}

/* ── TOGGLE SWITCH ────────────────────────────────────────────── */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.2s;
    border-radius: 24px;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.2s;
    border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
    background-color: #007bff;
}

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

/* ── PROGRESS PAGE ────────────────────────────────────────────── */
.progress-page {
    max-width: 800px;
    margin: 0 auto;
}

.progress-page h2 {
    color: #2c3e50;
    margin-bottom: 4px;
}

.progress-recipes {
    font-size: 0.9em;
    color: #6c757d;
    margin-bottom: 20px;
}

.progress-bar-container {
    position: relative;
    height: 32px;
    background-color: #e9ecef;
    border-radius: 8px;
    margin-bottom: 20px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: #007bff;
    border-radius: 8px;
    transition: width 0.3s ease;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
}

.log-output {
    background-color: #1e1e1e;
    color: #d4d4d4;
    border-radius: 8px;
    padding: 16px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.8em;
    line-height: 1.5;
    height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.log-line { padding: 1px 0; }
.log-error { color: #f44747; }
.log-warning { color: #cca700; }
.log-info { color: #d4d4d4; }
.log-debug { color: #808080; }

.run-result {
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
}

.result-success {
    background-color: #e8f5e9;
    border: 1px solid #a5d6a7;
}

.result-error {
    background-color: #ffebee;
    border: 1px solid #ef9a9a;
}

.result-message {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 12px;
}

.result-success .result-message { color: #2e7d32; }
.result-error .result-message { color: #c62828; }

.progress-actions {
    margin-top: 16px;
}

/* ── SETTINGS PAGE ────────────────────────────────────────────── */
.settings-page {
    max-width: 700px;
    margin: 0 auto;
}

.settings-page h2 {
    color: #2c3e50;
    margin-bottom: 20px;
}

.cache-info {
    padding: 0 16px 12px;
}

.cache-stat {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.9em;
}

.cache-label {
    color: #6c757d;
}

.cache-value {
    color: #2c3e50;
    font-weight: 500;
}

/* ── REPORTS PAGE ─────────────────────────────────────────────── */
.reports-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.reports-header h2 {
    color: #2c3e50;
}

.reports-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.reports-dir {
    font-size: 0.85em;
    color: #6c757d;
}

.report-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.report-card {
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    overflow: hidden;
    transition: border-color 0.15s;
}

.report-card:hover {
    border-color: #007bff;
}

.report-info {
    padding: 8px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
}

.report-name {
    font-size: 0.9em;
    color: #2c3e50;
    margin-bottom: 0;
}

.report-meta {
    display: flex;
    gap: 12px;
    font-size: 0.78em;
    color: #6c757d;
}

.report-actions {
    padding: 0 14px 8px;
}

.report-preview {
    border-top: 1px solid #e9ecef;
    height: 300px;
}

.report-preview iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ── EMPTY STATE ──────────────────────────────────────────────── */
.empty-state-container {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-text {
    font-size: 1.1em;
    color: #6c757d;
    margin-bottom: 8px;
}

.empty-state-hint {
    font-size: 0.9em;
    color: #adb5bd;
}

/* ── RUN HISTORY ──────────────────────────────────────────────── */
.run-history {
    margin-top: 40px;
}

.run-history h3 {
    color: #2c3e50;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e9ecef;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    padding: 10px 14px;
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

.history-meta {
    display: flex;
    gap: 16px;
    font-size: 0.85em;
    margin-bottom: 6px;
}

.history-id {
    font-family: monospace;
    color: #6c757d;
}

.history-time {
    color: #6c757d;
}

.history-domain {
    color: #495057;
    font-weight: 500;
}

.history-recipes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}

.history-recipe-badge {
    font-size: 0.8em;
    padding: 2px 10px;
    border-radius: 12px;
    background-color: #e3f2fd;
    color: #1565c0;
    font-weight: 500;
}

.history-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.85em;
}

.history-file-link {
    color: #007bff;
}

.history-dir {
    color: #6c757d;
    font-size: 0.85em;
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

.history-no-files {
    color: #adb5bd;
    font-size: 0.9em;
    font-style: italic;
    margin: 4px 0 0;
}

.current-output-section {
    margin-top: 40px;
}

.current-output-section h3 {
    color: #2c3e50;
    margin-bottom: 8px;
}

.current-output-section .reports-dir {
    display: block;
    margin-bottom: 16px;
}

/* ── FORMAT BADGES ────────────────────────────────────────────── */
.format-badge {
    display: inline-block;
    font-size: 0.65em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 6px;
}

.format-html {
    background-color: #d4edda;
    color: #155724;
}

.format-csv {
    background-color: #d1ecf1;
    color: #0c5460;
}

.format-xlsx {
    background-color: #d4edda;
    color: #155724;
}

.format-json {
    background-color: #fff3cd;
    color: #856404;
}

/* ── COMPACT FILE ROW ────────────────────────────────────────── */
.report-file-compact {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    font-size: 0.85em;
}

.compact-name {
    color: #495057;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compact-meta {
    color: #adb5bd;
    font-size: 0.9em;
    white-space: nowrap;
}

.compact-download {
    color: #6c757d;
    font-size: 0.9em;
    white-space: nowrap;
}

.compact-download:hover {
    color: #007bff;
}

/* ── SETUP PAGE ───────────────────────────────────────────────── */
.setup-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 56px - 48px);
}

.setup-card {
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 40px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.setup-card h2 {
    color: #2c3e50;
    margin-bottom: 8px;
}

.setup-intro {
    color: #6c757d;
    margin-bottom: 32px;
}

.setup-step {
    text-align: left;
}

.setup-step h3 {
    font-size: 1.1em;
    color: #2c3e50;
    margin-bottom: 8px;
}

.setup-hint {
    font-size: 0.85em;
    color: #6c757d;
    margin-bottom: 16px;
}

.setup-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.95em;
}

.setup-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

.setup-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    justify-content: flex-end;
}

.setup-steps-indicator {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 32px;
}

.step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #dee2e6;
    transition: background-color 0.2s;
}

.step-dot.active {
    background-color: #007bff;
}

/* ── TOAST NOTIFICATIONS ──────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 280px;
}

.toast.info {
    background-color: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
}

.toast.success {
    background-color: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.toast.error {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

.toast.warning {
    background-color: #fff8e1;
    color: #f57f17;
    border: 1px solid #ffe082;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
    margin-left: auto;
}

.toast-close:hover {
    opacity: 1;
}

/* ── HTMX INDICATOR ───────────────────────────────────────────── */
.htmx-indicator {
    display: none;
    color: #6c757d;
    font-size: 0.9em;
    padding: 8px;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}
