/* FM Nation Rules Editor - styles */

:root {
    --bg: #1a1d21;
    --bg-panel: #252a30;
    --bg-elevated: #2e343b;
    --bg-hover: #353c44;
    --fg: #e5e9f0;
    --fg-muted: #98a3b3;
    --fg-faint: #6b7585;
    --accent: #88c0d0;
    --accent-strong: #5e9fb5;
    --danger: #bf616a;
    --warn: #ebcb8b;
    --success: #a3be8c;
    --border: #3b424c;
    --tag-record: #b48ead;
    --tag-list: #ebcb8b;
    --tag-string: #a3be8c;
    --tag-integer: #88c0d0;
    --tag-boolean: #d08770;
    --tag-date: #b48ead;
    --tag-real: #88c0d0;
    --tag-unsigned: #88c0d0;
    --tag-large: #88c0d0;
    --tag-null: #6b7585;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
    background: var(--bg);
    color: var(--fg);
    height: 100vh;
    overflow: hidden;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    min-height: 56px;
}

.topbar h1 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--fg);
    letter-spacing: 0.01em;
}

.topbar .spacer { flex: 1; }

.topbar .meta {
    font-size: 0.8rem;
    color: var(--fg-muted);
    font-family: var(--mono);
}

/* Main split layout */
.main {
    flex: 1;
    min-height: 0;              /* required so grid children can scroll past viewport */
    display: grid;
    grid-template-columns: 1fr 380px;
    overflow: hidden;
}

/* All grid panes need min-height:0 + overflow:auto so a tall tree
   scrolls inside its pane rather than blowing out the page height. */
.main > div {
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

.tree-pane, .side-pane {
    padding: 1rem;
}

.tree-pane {
    background: var(--bg);
    border-right: 1px solid var(--border);
}

.side-pane {
    background: var(--bg-panel);
}

/* Drop zone (when no file loaded) */
.dropzone {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 3rem;
    border: 2px dashed var(--border);
    margin: 2rem;
    border-radius: 12px;
    transition: all 0.15s ease;
    cursor: pointer;
    text-align: center;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent);
    background: rgba(136, 192, 208, 0.05);
}

.dropzone h2 {
    margin: 0;
    color: var(--fg);
    font-weight: 500;
}

.dropzone p {
    margin: 0;
    color: var(--fg-muted);
    max-width: 480px;
    line-height: 1.5;
}

.dropzone .icon {
    width: 64px;
    height: 64px;
    color: var(--accent);
    opacity: 0.6;
}

/* Buttons */
button, .btn {
    background: var(--bg-elevated);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.1s ease, border-color 0.1s ease;
}

button:hover, .btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-strong);
}

button.primary, .btn.primary {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    color: var(--bg);
    font-weight: 600;
}

button.primary:hover, .btn.primary:hover {
    background: var(--accent);
    border-color: var(--accent);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

button.icon-only {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button.danger {
    color: var(--danger);
    border-color: rgba(191, 97, 106, 0.4);
}

button.danger:hover {
    background: rgba(191, 97, 106, 0.15);
}

/* Tree view */
.tree {
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.55;
}

.tree-node {
    position: relative;
}

.tree-node-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 1px 0.25rem;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.tree-node-row:hover {
    background: var(--bg-elevated);
}

.tree-node-row.selected {
    background: rgba(136, 192, 208, 0.15);
    outline: 1px solid rgba(136, 192, 208, 0.4);
}

.tree-toggle {
    color: var(--fg-faint);
    width: 12px;
    text-align: center;
    flex-shrink: 0;
    font-family: var(--mono);
}

.tree-toggle.leaf { color: transparent; }

.tag {
    font-weight: 600;
    text-transform: lowercase;
}

.tag.record { color: var(--tag-record); }
.tag.list { color: var(--tag-list); }
.tag.string { color: var(--tag-string); }
.tag.integer, .tag.unsigned, .tag.unsigned_large, .tag.large { color: var(--tag-integer); }
.tag.boolean { color: var(--tag-boolean); }
.tag.date { color: var(--tag-date); }
.tag.real, .tag.float { color: var(--tag-real); }
.tag.colour { color: var(--tag-record); }
.tag.null { color: var(--tag-null); font-style: italic; }

.attr-id {
    color: var(--fg);
}

.attr-value {
    color: var(--fg-muted);
}

.attr-value.string-value { color: var(--success); }
.attr-value.numeric-value { color: var(--accent); }
.attr-value.boolean-value { color: var(--tag-boolean); }
.attr-value.date-value { color: var(--tag-date); }

.tree-children {
    margin-left: 1rem;
    border-left: 1px solid var(--border);
    padding-left: 0.5rem;
}

/* Side panel sections */
.section {
    margin-bottom: 1.25rem;
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg-faint);
    margin: 0 0 0.5rem 0;
    font-weight: 600;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.field label {
    font-size: 0.75rem;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.field input, .field select {
    background: var(--bg);
    color: var(--fg);
    border: 1px solid var(--border);
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.85rem;
    width: 100%;
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--accent);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.field-row.three {
    grid-template-columns: 1fr 1fr 1fr;
}

.field-row.four {
    grid-template-columns: 1fr 1fr 1fr 1fr;
}

/* Transformation cards */
.transform-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.85rem;
    margin-bottom: 0.6rem;
}

.transform-card h3 {
    margin: 0 0 0.4rem 0;
    font-size: 0.92rem;
    color: var(--fg);
}

.transform-card .desc {
    color: var(--fg-muted);
    font-size: 0.78rem;
    margin: 0 0 0.6rem 0;
    line-height: 1.45;
}

/* Status / messages */
.status {
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.82rem;
    margin-bottom: 0.5rem;
}

.status.info { background: rgba(136, 192, 208, 0.1); color: var(--accent); }
.status.success { background: rgba(163, 190, 140, 0.1); color: var(--success); }
.status.warn { background: rgba(235, 203, 139, 0.1); color: var(--warn); }
.status.error { background: rgba(191, 97, 106, 0.1); color: var(--danger); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover { background: var(--fg-faint); }

/* Tabs in side panel */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--fg-muted);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 0;
}

.tab.active {
    color: var(--fg);
    border-bottom-color: var(--accent);
}

.tab:hover:not(.active) {
    color: var(--fg);
    background: var(--bg-elevated);
}

/* Inline help / docs */
.help-link {
    color: var(--accent);
    font-size: 0.78rem;
    cursor: pointer;
}

.help-link:hover { text-decoration: underline; }

/* Loading / placeholder */
.placeholder {
    color: var(--fg-faint);
    font-style: italic;
    font-size: 0.85rem;
    text-align: center;
    padding: 2rem;
}

/* Compact action bar */
.actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Footer / status bar */
.statusbar {
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding: 0.3rem 1rem;
    font-size: 0.75rem;
    color: var(--fg-muted);
    font-family: var(--mono);
    display: flex;
    gap: 1rem;
    align-items: center;
}

.statusbar .item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
}

.dot.warn { background: var(--warn); }
.dot.error { background: var(--danger); }

/* Search */
.search {
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--fg);
    font-size: 0.85rem;
    width: 240px;
}

.search:focus { outline: none; border-color: var(--accent); }

/* Diff preview */
.diff {
    font-family: var(--mono);
    font-size: 0.78rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem;
    max-height: 240px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.diff .add { color: var(--success); }
.diff .del { color: var(--danger); }
.diff .ctx { color: var(--fg-muted); }

/* ============================================================ */
/* Outline navigation                                            */
/* ============================================================ */

.outline {
    font-size: 0.83rem;
    display: flex;
    flex-direction: column;
}

.outline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.outline-title {
    font-weight: 600;
    color: var(--fg);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.75rem;
}

.outline-status {
    font-family: var(--mono);
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.outline-status.error { background: rgba(191, 97, 106, 0.2); color: var(--danger); }
.outline-status.warn  { background: rgba(235, 203, 139, 0.2); color: var(--warn); }
.outline-status.clean { background: rgba(163, 190, 140, 0.15); color: var(--success); }

.outline-section { margin-bottom: 1rem; }

.outline-section-header {
    display: flex;
    justify-content: space-between;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-faint);
    font-size: 0.7rem;
    padding: 0.15rem 0;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 0.25rem;
}

.outline-section-count {
    color: var(--fg-muted);
}

.outline-entries {
    display: flex;
    flex-direction: column;
}

.outline-entry {
    padding: 0.3rem 0.5rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 3px;
    line-height: 1.3;
}

.outline-entry:hover { background: var(--bg-elevated); }

.outline-entry.selected {
    background: rgba(136, 192, 208, 0.15);
    outline: 1px solid rgba(136, 192, 208, 0.4);
}

.outline-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.outline-badge {
    margin-left: 0.4rem;
    padding: 0.05rem 0.4rem;
    border-radius: 8px;
    font-size: 0.7rem;
    font-family: var(--mono);
    font-weight: 600;
}

.outline-badge.error { background: var(--danger); color: white; }
.outline-badge.warn  { background: var(--warn); color: var(--bg); }

/* ============================================================ */
/* StructuredView                                                */
/* ============================================================ */

.structured-view {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.structured-header {
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.structured-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.structured-kind {
    font-weight: 600;
    color: var(--fg);
}

.structured-section {
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    background: var(--bg-elevated);
    color: var(--fg-muted);
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.structured-description {
    color: var(--fg-muted);
    font-size: 0.85rem;
    line-height: 1.45;
    margin-top: 0.3rem;
}

.structured-source {
    color: var(--fg-faint);
    font-size: 0.72rem;
    font-family: var(--mono);
    margin-top: 0.2rem;
}

.fields {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.field-row-wrap {
    display: grid;
    grid-template-columns: 200px 1fr auto;
    gap: 0.4rem 0.6rem;
    align-items: start;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.field-row-wrap.field-missing {
    background: rgba(191, 97, 106, 0.08);
    outline: 1px solid rgba(191, 97, 106, 0.4);
    border-radius: 4px;
    padding: 0.4rem 0.5rem;
}

.field-row-wrap.field-required:not(.field-missing) {
    /* required but absent and no default - same as missing actually */
    background: rgba(235, 203, 139, 0.08);
}

.field-row-wrap.field-default .field-label-id {
    color: var(--fg-muted);
}

.field-row-wrap.field-override .field-label-id {
    color: var(--fg);
    font-weight: 600;
}

.field-row-wrap.field-error {
    outline: 1px solid rgba(191, 97, 106, 0.6);
    border-radius: 4px;
    padding: 0.4rem 0.5rem;
}

.field-row-wrap.field-warn {
    outline: 1px dashed rgba(235, 203, 139, 0.6);
    border-radius: 4px;
    padding: 0.4rem 0.5rem;
}

.field-label {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
}

.field-label-id {
    font-family: var(--mono);
    font-size: 0.85rem;
}

.field-label-tag {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--fg-faint);
}

.field-label-required {
    color: var(--danger);
    font-weight: 600;
    margin-left: 0.2rem;
}

.field-label-default-marker {
    background: var(--bg-elevated);
    color: var(--fg-muted);
    font-size: 0.65rem;
    padding: 0.05rem 0.35rem;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field-label-override-marker {
    background: rgba(136, 192, 208, 0.2);
    color: var(--accent);
    font-size: 0.65rem;
    padding: 0.05rem 0.35rem;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field-label-implicit-marker {
    color: var(--fg-faint);
    font-size: 0.7rem;
    font-family: var(--mono);
}

.field-actions {
    display: flex;
    gap: 0.3rem;
}

.field-help {
    grid-column: 2;
    color: var(--fg-muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

.field-error-line {
    grid-column: 1 / -1;
    color: var(--danger);
    font-size: 0.78rem;
    font-family: var(--mono);
    padding-top: 0.2rem;
}

.field-warn-line {
    grid-column: 1 / -1;
    color: var(--warn);
    font-size: 0.78rem;
    font-family: var(--mono);
    padding-top: 0.2rem;
}

.btn-sm {
    padding: 0.18rem 0.5rem;
    font-size: 0.72rem;
}

.add-field-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding: 0.5rem 0;
    border-top: 1px dashed var(--border);
}

.add-field-label {
    color: var(--fg-muted);
    font-size: 0.78rem;
    margin-right: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Child-list nesting */

.child-lists {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.child-list-row {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem 0.6rem;
}

.child-list-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.child-list-count {
    color: var(--fg-muted);
    font-size: 0.78rem;
}

.child-list-items {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-top: 0.4rem;
}

.child-list-item {
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    background: var(--bg-elevated);
    font-family: var(--mono);
    font-size: 0.78rem;
}

.child-list-item:hover { background: var(--bg-hover); }
.child-list-item.selected {
    background: rgba(136, 192, 208, 0.15);
    outline: 1px solid rgba(136, 192, 208, 0.4);
}

/* Layout — three-pane mode (Outline + Structured + Inspector) */

.main.three-pane {
    grid-template-columns: 280px 1fr 360px;
}

.outline-pane {
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
}

.structured-pane {
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg);
}
