/**
 * Rainbird Rule Tracker - Styles
 * Clean, modern design for rule tree visualisation
 */

/* === GLOBAL STYLES === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
    background-color: #1c083b;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
}

/* === HEADER === */
.header {
    background: white;
    color: #321658;
    padding: 40px 30px;
    border-radius: 0;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    position: relative;
}

.header-logo {
    height: 60px;
    width: auto;
    object-fit: contain;
    position: absolute;
    left: 0;
}

.header-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.header h1 {
    font-size: 32px;
    margin-bottom: 8px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #1c083b;
}

.alpha-badge {
    display: inline-block;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.header p {
    font-size: 18px;
    font-weight: 400;
    color: #666;
    margin: 0;
}

/* === CONFIG PANEL === */
.config-panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin: 0 20px 20px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-group {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
}

.form-group-small {
    flex: 0 0 auto;
    min-width: 150px;
    max-width: 200px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group button {
    margin-top: auto;
    align-self: flex-start;
    min-width: fit-content;
}

.form-group input:focus {
    outline: none;
    border-color: #67BED9;
    box-shadow: 0 0 0 3px rgba(103, 190, 217, 0.1);
}

.btn-primary {
    background: #67BED9;
    color: white;
    border: 1px solid #67BED9;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(103, 190, 217, 0.4);
    background: #52a8c4;
}

.btn-primary:active {
    transform: translateY(0);
}

/* === MODE SELECTOR === */
.mode-selector {
    min-width: 100%;
}

.radio-group {
    display: flex;
    gap: 20px;
    margin-top: 8px;
}

.radio-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 6px;
    transition: all 0.2s;
    flex: 1;
}

.radio-label:hover {
    border-color: #67BED9;
    background: #f8fbfc;
}

.radio-label input[type="radio"] {
    margin-right: 10px;
    margin-top: 3px;
    cursor: pointer;
    width: auto;
}

.radio-label input[type="radio"]:checked + span {
    color: #67BED9;
    font-weight: 600;
}

.radio-label:has(input[type="radio"]:checked) {
    border-color: #67BED9;
    background: #f0f9fc;
}

.radio-label span {
    display: block;
    font-weight: 500;
    color: #333;
    margin-bottom: 4px;
}

.radio-label small {
    display: block;
    color: #666;
    font-size: 12px;
    margin-top: 4px;
    line-height: 1.3;
}

/* === STATUS BAR === */
.status-bar {
    background: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin: 0 20px 20px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #67BED9;
}

#statusText {
    font-weight: 500;
    color: #555;
}

/* === MAIN CONTENT === */
.main-content {
    display: flex;
    gap: 20px;
    min-height: 1000px;
    max-height: calc(100vh - 150px);
    margin: 0 20px;
}

/* === TREE PANEL === */
.tree-panel {
    flex: 2;
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: visible; /* Changed from hidden to allow scrolling */
    display: flex;
    flex-direction: column;
    max-height: 100%; /* Respect parent's max-height */
}

.tree-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.tree-panel h2 {
    font-size: 18px;
    margin-bottom: 0;
    color: #333;
}

.btn-download {
    background: #67BED9;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-download:hover {
    background: #52a8c4;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(103, 190, 217, 0.4);
}

.btn-download:active {
    transform: translateY(0);
}

.tree-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 10px;
    background: #fafafa;
    border-radius: 4px;
    min-height: 0; /* Allow flex child to shrink and enable scrolling */
}

.placeholder {
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 40px 20px;
}

/* === RIGHT PANEL === */
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 300px;
}

/* === RESULTS PANEL === */
.results-panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #28a745;
    margin-bottom: 20px;
}

.results-panel h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #28a745;
    display: flex;
    align-items: center;
    gap: 8px;
}

.results-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-item {
    background: #f8f9fa;
    padding: 12px 15px;
    border-radius: 6px;
    border-left: 3px solid #28a745;
    transition: all 0.2s ease;
}

.result-item:hover {
    background: #e9ecef;
    transform: translateX(2px);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.result-relationship {
    font-weight: 600;
    color: #321658;
    font-size: 14px;
}

.result-certainty {
    background: #28a745;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.result-certainty.medium {
    background: #f59e0b;
}

.result-certainty.low {
    background: #dc3545;
}

.result-body {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #495057;
}

.result-arrow {
    color: #667eea;
    font-weight: bold;
}

.result-subject,
.result-object {
    font-weight: 500;
    color: #321658;
}

.result-metadata {
    margin-top: 8px;
    font-size: 12px;
    color: #6c757d;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

/* Result bindings display */
.result-bindings {
    margin-top: 8px;
    padding: 6px 10px;
    background: #f0f7ff;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    color: #321658;
}

.result-bindings-loading {
    margin-top: 8px;
    font-size: 12px;
    color: #999;
    font-style: italic;
}

/* === QUESTION PANEL === */
.question-panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #f59e0b;
}

.question-panel h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #f59e0b;
}

.question-prompt {
    margin-bottom: 15px;
}

.question-prompt p {
    margin-bottom: 8px;
}

.question-prompt-text {
    margin-bottom: 12px;
}

.question-prompt-text p {
    margin-bottom: 8px;
}

.question-prompt-text h1,
.question-prompt-text h2,
.question-prompt-text h3,
.question-prompt-text h4,
.question-prompt-text h5,
.question-prompt-text h6 {
    font-size: 13px;
    font-weight: 500;
    color: #555;
    margin-top: 6px;
    margin-bottom: 4px;
}

.question-prompt-text em {
    font-style: italic;
    color: #666;
}

.question-prompt-text strong {
    font-weight: 600;
}

.question-meta {
    font-size: 13px;
    color: #666;
}

.highlight {
    font-weight: 600;
    color: #667eea;
}

.answer-options {
    margin-top: 15px;
}

.options-title {
    font-weight: 500;
    margin-bottom: 10px;
    color: #555;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.option-btn {
    background: white;
    border: 2px solid #ddd;
    padding: 12px 16px;
    border-radius: 4px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    font-size: 14px;
}

.option-btn:hover {
    border-color: #667eea;
    background: #f8f9ff;
    transform: translateX(4px);
}

.option-btn:active {
    transform: translateX(2px);
}

.option-btn.selected {
    background: #667eea;
    color: white;
    border-color: #667eea;
    font-weight: 600;
}

.option-btn.selected:hover {
    background: #5568d3;
    border-color: #5568d3;
}

.option-none {
    border-color: #e74c3c;
    color: #e74c3c;
}

.option-none:hover {
    border-color: #e74c3c;
    background: #fee;
}

/* === FREE TEXT INPUT === */
.free-text-input {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.free-text-input p {
    margin: 0;
    padding: 0;
}

.free-text-input input[type="text"],
.free-text-input input[type="number"],
.free-text-input input[type="date"] {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.free-text-input input[type="date"] {
    min-width: 200px;
}

.free-text-input input:focus {
    outline: none;
    border-color: #67BED9;
    box-shadow: 0 0 0 3px rgba(103, 190, 217, 0.1);
}

/* Custom answer input */
.custom-answer-input {
    display: flex;
    flex-direction: column;
}

.custom-answer-input p {
    margin: 0;
    padding: 0;
}

.custom-answer-input input[type="text"],
.custom-answer-input input[type="number"],
.custom-answer-input input[type="date"] {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.custom-answer-input input[type="date"] {
    min-width: 200px;
}

.custom-answer-input input:focus {
    outline: none;
    border-color: #67BED9;
    box-shadow: 0 0 0 3px rgba(103, 190, 217, 0.1);
}

/* === SESSION LOG === */
.session-log {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.session-log h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #333;
}

.log-container {
    flex: 1;
    overflow-y: auto;
    background: #fafafa;
    border-radius: 4px;
    padding: 10px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
}

.log-entry {
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-time {
    color: #999;
    margin-right: 8px;
}

.log-info {
    color: #555;
}

.log-success {
    color: #27ae60;
}

.log-error {
    color: #e74c3c;
    font-weight: 500;
}

/* === TREE STYLES === */
.tree-node {
    margin: 8px 0;
}

.tree-item {
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 4px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    transition: background 0.2s;
}

.tree-item .icon {
    font-size: 16px;
    flex-shrink: 0;
}

.tree-item .text {
    flex: 1;
    word-wrap: break-word;
}

.relationship-header {
    background: #e3f2fd;
    border-left: 3px solid #2196f3;
    font-weight: 500;
}

.rule-header {
    background: #f3e5f5;
    border-left: 3px solid #9c27b0;
    cursor: pointer;
    position: relative;
}

.rule-header:hover {
    background: #ede7f6;
}

/* Rule status-specific styling */
.rule-satisfied {
    background: #e8f5e9 !important;
    border-left-color: #27ae60 !important;
}

.rule-satisfied:hover {
    background: #c8e6c9 !important;
}

.rule-not_satisfied {
    background: #ffebee !important;
    border-left-color: #e74c3c !important;
}

.rule-not_satisfied:hover {
    background: #ffcdd2 !important;
}

.rule-pending {
    background: #fff8e1 !important;
    border-left-color: #f39c12 !important;
}

.rule-pending:hover {
    background: #ffecb3 !important;
}

.rule-header .toggle {
    font-size: 12px;
    margin-right: 4px;
    transition: transform 0.2s;
}

.rule-header .rule-expression {
    display: block;
    font-size: 12px;
    font-weight: normal;
    color: #444;
    font-family: 'Monaco', 'Courier New', monospace;
    margin-top: 4px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
    display: inline-block;
}

.rule-header .progress {
    display: block;
    font-size: 12px;
    font-weight: normal;
    color: #666;
    margin-top: 4px;
}

/* Rule-level bindings display */
.rule-bindings {
    margin-left: 40px;
    margin-top: 8px;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #f0f7ff;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    color: #321658;
}

.condition-item {
    background: white;
    border-left: 3px solid #ccc;
    margin-left: 20px;
}

.status-satisfied {
    border-left-color: #27ae60 !important;
}

.status-not_satisfied {
    border-left-color: #e74c3c !important;
}

.status-pending {
    border-left-color: #f39c12 !important;
}

.status-expression {
    border-left-color: #3498db !important;
}

.fact-detail {
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: 3px;
    font-size: 12px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.fact-detail.success {
    background: #d4edda;
    color: #155724;
}

.fact-detail.error {
    background: #f8d7da;
    color: #721c24;
}

.expression-text {
    margin-top: 6px;
    padding: 6px 10px;
    background: #e8f4f8;
    border-radius: 3px;
    font-size: 12px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.expression-result {
    margin-top: 4px;
    padding: 4px 8px;
    background: #ecf0f1;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.expression-result.success {
    background: #d4edda;
    color: #155724;
}

.expression-result.error {
    background: #f8d7da;
    color: #721c24;
}

.variable-binding {
    margin-top: 4px;
    padding: 4px 8px;
    background: #fff3cd;
    border-left: 3px solid #ffc107;
    border-radius: 3px;
    font-size: 0.85em;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    color: #856404;
}

.conditions-container {
    max-height: none; /* No limit - allow full expansion */
    overflow: visible; /* Don't hide overflow */
    transition: max-height 0.3s ease-out;
}

.conditions-container.collapsed {
    max-height: 0;
    overflow: hidden; /* Hide when collapsed */
}

/* Nested tree collapsing */
.nested-tree {
    max-height: none;
    overflow: visible;
    transition: max-height 0.3s ease-out;
}

.nested-tree.collapsed {
    max-height: 0;
    overflow: hidden;
}

/* Collapsible condition header */
.collapsible-condition {
    cursor: pointer;
}

.collapsible-condition:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.collapsible-condition .toggle {
    display: inline-block;
    margin-right: 5px;
    transition: transform 0.2s;
    font-size: 0.8em;
    color: #666;
}

/* Collapsible referenced relationship header */
.collapsible-ref-rel {
    cursor: pointer;
}

.collapsible-ref-rel:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.collapsible-ref-rel .toggle {
    display: inline-block;
    margin-right: 5px;
    transition: transform 0.2s;
    font-size: 0.8em;
    color: #666;
}

/* Referenced relationships in expression conditions */
.referenced-relationships {
    margin-left: 20px;
    margin-top: 8px;
    padding-left: 12px;
    border-left: 2px dashed #9e9e9e;
}

.referenced-rel-header {
    padding: 6px 10px;
    margin: 4px 0;
    background: #f5f5f5;
    border-left: 3px solid #9e9e9e;
    border-radius: 3px;
    font-size: 0.9em;
}

.referenced-rel-header .icon {
    color: #9e9e9e;
    margin-right: 6px;
}

.referenced-rel-header .text {
    color: #555;
}

.nested-tree {
    margin-left: 20px;
    margin-top: 8px;
    padding-left: 12px;
    border-left: 2px dashed #ccc;
}

.no-rules {
    color: #999;
    font-style: italic;
}

.error {
    background: #fee !important;
    border-left-color: #e74c3c !important;
    color: #e74c3c;
}

.cycle {
    background: #fff3cd !important;
    border-left-color: #f39c12 !important;
    color: #856404;
}

/* === LOADING OVERLAY === */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loadingText {
    color: white;
    margin-top: 20px;
    font-size: 16px;
}

/* === FOOTER === */
.footer {
    background: white;
    color: #1c083b;
    text-align: center;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 20px 20px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.footer p {
    margin: 0;
    font-size: 13px;
    opacity: 0.8;
}

/* === EVIDENCE METADATA === */
.evidence-metadata {
    margin-top: 8px;
    padding: 10px;
    background: #f8f9fa;
    border-left: 3px solid #67BED9;
    border-radius: 4px;
    font-size: 12px;
}

.evidence-bindings {
    padding: 6px 10px;
    background: #e7f3f8;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    color: #0d5c7d;
    margin-bottom: 8px;
}

.evidence-conditions-header {
    font-weight: 600;
    color: #555;
    margin-top: 8px;
    margin-bottom: 6px;
}

.evidence-condition {
    padding: 8px 10px;
    background: white;
    border-radius: 3px;
    margin-bottom: 6px;
    border-left: 3px solid #ccc;
}

.evidence-condition.high-impact {
    border-left-color: #27ae60;
    background: #f0fdf4;
}

.evidence-condition.medium-impact {
    border-left-color: #f39c12;
    background: #fffbeb;
}

.evidence-condition.low-impact {
    border-left-color: #e74c3c;
    background: #fef2f2;
}

.evidence-condition .condition-text {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 11px;
    color: #333;
    margin-bottom: 4px;
}

.evidence-scores {
    font-size: 11px;
    color: #666;
    display: flex;
    gap: 12px;
}

.evidence-max-certainty {
    margin-top: 8px;
    padding: 4px 8px;
    background: #e0e7ff;
    border-radius: 3px;
    font-size: 11px;
    color: #4338ca;
    font-weight: 500;
}

.condition-with-evidence {
    background: #f0f9ff !important;
}

.condition-no-evidence {
    opacity: 0.8;
}

/* Synthetic fact display */
.synthetic-fact-info {
    margin-top: 10px;
    padding: 10px;
    background: #fff8e6;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
}

.synthetic-fact-header {
    font-weight: 600;
    color: #f59e0b;
    margin-bottom: 6px;
    font-size: 0.9em;
}

.synthetic-fact-detail {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
    color: #333;
    margin-bottom: 6px;
}

/* Highlight synthetic facts in condition display */
.synthetic-fact-highlight {
    background: #fff8e6;
    border-left: 3px solid #f59e0b;
    padding-left: 8px;
}

/* Style for conditions not satisfied due to synthetic facts */
.fact-detail.error.synthetic {
    background: #fff4e6;
    border-left: 3px solid #f59e0b;
    color: #a26a12;
}

.fact-detail.error.synthetic::before {
    content: '🔗 ';
}

/* Error message for failed bindings fetch */
.result-bindings-error {
    margin-top: 8px;
    padding: 6px 10px;
    background: #fff4e6;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    font-size: 12px;
    color: #a26a12;
}

/* === TARGET FACT STATUS === */
.target-fact-info {
    margin-left: 40px;
    margin-top: 5px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.9em;
}

.target-fact-info.success {
    background-color: rgba(40, 167, 69, 0.1);
    border-left: 3px solid #28a745;
    color: #155724;
}

.target-fact-info.error {
    background-color: rgba(220, 53, 69, 0.1);
    border-left: 3px solid #dc3545;
    color: #721c24;
}

.target-fact-detail {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.95em;
}

/* === RESPONSIVE === */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .right-panel {
        min-width: auto;
    }
}

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

    .form-group {
        min-width: auto;
    }
}
