/* ===================================================================
   Realta Demo — Stylesheet
   =================================================================== */

/* --- Reset & base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: #333;
    background: #f0f2f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: #4A90D9;
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

code {
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    font-size: 0.88em;
    background: #e8ecf0;
    padding: 0.15em 0.35em;
    border-radius: 3px;
}

/* --- Navbar --- */
.navbar {
    background: #1a1a2e;
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand a {
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.nav-brand a:hover {
    text-decoration: none;
    opacity: 0.9;
}

.nav-links {
    display: flex;
    align-items: center;
    margin-left: 2rem;
    gap: 0.25rem;
}

.nav-link {
    color: rgba(255,255,255,0.8);
    padding: 0.5rem 0.9rem;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background 0.15s;
}
.nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,0.12);
    text-decoration: none;
}

.nav-dropdown {
    position: relative;
}

.nav-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 200px;
    padding: 0.4rem 0;
    z-index: 200;
}

.nav-dropdown:hover .nav-dropdown-content {
    display: block;
}

.nav-dropdown-content a {
    display: block;
    color: #333;
    padding: 0.5rem 1rem;
    font-size: 0.88rem;
}
.nav-dropdown-content a:hover {
    background: #f0f2f5;
    text-decoration: none;
}

.nav-doc-selector {
    margin-left: auto;
    padding: 0.3rem 0.5rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.9);
    font-size: 0.85rem;
    max-width: 260px;
    cursor: pointer;
}
.nav-doc-selector:focus {
    outline: none;
    border-color: rgba(255,255,255,0.6);
}
.nav-doc-selector option {
    color: #333;
    background: #fff;
}

/* --- Container --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    flex: 1;
}

/* --- Page header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}
.page-header h1 {
    font-size: 1.6rem;
    font-weight: 600;
    color: #1a1a2e;
}

/* --- Cards --- */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    margin-bottom: 1.25rem;
    overflow: hidden;
    position: relative;
}

.card-header {
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* --- Phase grid (dashboard) --- */
.phase-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.25rem;
}

.phase-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.phase-number {
    font-weight: 700;
    font-size: 0.85rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.phase-card h3 {
    margin-bottom: 0.4rem;
}

.phase-card p {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.phase-meta {
    font-size: 0.82rem;
    color: #888;
}

.phase-progress {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: #4A90D9;
    z-index: 5;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 1rem;
    border-radius: 5px;
    border: 1px solid transparent;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover {
    text-decoration: none;
    opacity: 0.9;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #4A90D9;
    color: #fff;
}
.btn-primary:hover {
    background: #3b7fc8;
}

.btn-secondary {
    background: #fff;
    color: #555;
    border-color: #ccc;
}
.btn-secondary:hover {
    background: #f5f5f5;
}

.btn-run {
    background: #27AE60;
    color: #fff;
}
.btn-run:hover {
    background: #219a52;
}

.btn-lg {
    padding: 0.65rem 1.5rem;
    font-size: 1rem;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.2em 0.6em;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

.badge-complete {
    background: #d4edda;
    color: #155724;
}
.badge-pending {
    background: #fff3cd;
    color: #856404;
}
.badge-error {
    background: #f8d7da;
    color: #721c24;
}
.badge-info {
    background: #d1ecf1;
    color: #0c5460;
}
.badge-warning {
    background: #fff3cd;
    color: #856404;
}
.badge-small {
    font-size: 0.72rem;
    padding: 0.1em 0.4em;
}
.badge-definition {
    background: #e8daef;
    color: #6c3483;
}

/* Modality badges */
.modality-obligatory, .badge-obligatory {
    background: #27AE60;
    color: #fff;
}
.modality-forbidden, .badge-forbidden {
    background: #E74C3C;
    color: #fff;
}
.modality-permitted, .badge-permitted {
    background: #8E44AD;
    color: #fff;
}
.modality-excused, .badge-excused {
    background: #F39C12;
    color: #fff;
}
.modality-is, .badge-is {
    background: #4A90D9;
    color: #fff;
}
.modality-isnot, .badge-isnot {
    background: #95a5a6;
    color: #fff;
}

/* --- Tables --- */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.55rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 0.88rem;
}

.data-table thead th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 0;
}

.data-table tbody tr:hover {
    background: #f8f9fa;
}

.table-responsive {
    overflow-x: auto;
}

/* --- Stat boxes --- */
.stat-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f8f9fa;
    border-radius: 6px;
    padding: 0.75rem 1.25rem;
    min-width: 100px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a2e;
}

.stat-label {
    font-size: 0.78rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.2rem;
}

/* --- Tree view (phase 1 sections) --- */
.tree-view {
    max-height: 500px;
    overflow-y: auto;
}

.tree-item {
    margin-bottom: 0.3rem;
}

.tree-item summary {
    cursor: pointer;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.tree-item summary:hover {
    background: #f0f2f5;
}

.tree-item-content {
    padding: 0.25rem 0 0.25rem 1.5rem;
}

.paragraph-item {
    padding: 0.3rem 0.5rem;
    margin-bottom: 0.2rem;
    border-left: 2px solid #ddd;
    font-size: 0.88rem;
}

.paragraph-item .para-type {
    margin-right: 0.5rem;
}
.paragraph-item .para-content {
    color: #555;
}

/* depth indentation */
.depth-0 { margin-left: 0; }
.depth-1 { margin-left: 1rem; }
.depth-2 { margin-left: 2rem; }
.depth-3 { margin-left: 3rem; }
.depth-4 { margin-left: 4rem; }
.depth-5 { margin-left: 5rem; }

/* --- Code blocks (Turnip rules) --- */
.code-block {
    background: #1e1e2e;
    color: #cdd6f4;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.6;
    margin-top: 0.5rem;
}
.code-block code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

/* --- Rule / error sections --- */
.rule-section,
.error-section {
    margin-bottom: 0.75rem;
}

.rule-section summary,
.error-section summary {
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.rule-section summary:hover,
.error-section summary:hover {
    background: #f0f2f5;
}

.error-list {
    padding: 0.5rem 1.5rem;
    color: #721c24;
    font-size: 0.88rem;
}

.entry-point-list {
    padding: 0.5rem 1.5rem;
}
.entry-point-list li {
    margin-bottom: 0.3rem;
}

/* --- Alerts --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}
.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #28a745;
}
.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #dc3545;
}
.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #17a2b8;
}

/* --- Spinner --- */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #e0e0e0;
    border-top-color: #4A90D9;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* --- Forms (query page) --- */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 0.35rem;
    color: #444;
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: #4A90D9;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

select.form-control {
    appearance: auto;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
}

/* --- Query layout --- */
.query-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    align-items: start;
}

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

.query-rhs {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.query-form-card {
    position: relative;
}

.query-progress {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: #4A90D9;
    z-index: 5;
}

/* Conclusion badges in result */
.conclusion-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.conclusion-badge {
    font-size: 1.1rem;
    padding: 0.4em 1em;
    border-radius: 6px;
    font-weight: 700;
}

/* Derivation path */
.derivation-list {
    list-style: none;
    padding: 0;
}

.derivation-step {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.3rem;
    border-left: 3px solid #4A90D9;
    background: #f8f9fa;
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
}

.derivation-step .step-type {
    font-weight: 600;
    color: #4A90D9;
    margin-right: 0.5rem;
}
.derivation-step .step-rule {
    font-size: 0.78em;
    color: #888;
    margin-left: 0.3rem;
}
.step-conclusion {
    border-left-color: #27AE60;
}
.step-value {
    border-left-color: #85C1E9;
}
.step-failed {
    border-left-color: #E8922D;
}
.step-missing {
    border-left-color: #E74C3C;
}

/* Missing facts warning */
.missing-facts {
    padding: 0.75rem 1rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 6px;
    margin-bottom: 1rem;
}
.missing-facts h4 {
    margin-bottom: 0.4rem;
    color: #856404;
}
.missing-facts ul {
    padding-left: 1.5rem;
    color: #856404;
}

/* Follow-up questions card */
.followup-card {
    position: relative;
    border-color: #e8922d;
}
.followup-card .card-header {
    background: #fff8f0;
    color: #b35c00;
}
.followup-hint {
    font-size: 0.88rem;
    color: #666;
    margin-bottom: 1rem;
}

/* All facts table */
.facts-section h4 {
    margin-bottom: 0.5rem;
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.82rem;
    color: #999;
    border-top: 1px solid #eee;
    background: #fff;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .phase-grid {
        grid-template-columns: 1fr;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .stat-row {
        justify-content: center;
    }
}
