/* ── TOKENS ───────────────────────────────────────────── */
:root {
    --bg: #f4f7f9;
    --panel: #ffffff;
    --ink: #1f2937;
    --muted: #6b7280;
    --line: #d9e3ea;
    --brand: #0b6e4f;
    --brand-2: #084c61;
    --warn: #bd3d3a;
    --lv1: #064e3b;
    --lv1-bg: #c9f9dd;
    --lv2: #744210;
    --lv2-bg: #ffefb5;
    --lv3: #7f1d1d;
    --lv3-bg: #ffd8d6;
}

body.high-contrast {
    --bg: #0b0b0b;
    --panel: #111827;
    --ink: #f9fafb;
    --muted: #9ca3af;
    --line: #374151;
    --lv1: #6ee7b7;
    --lv1-bg: #052e1c;
    --lv2: #fcd34d;
    --lv2-bg: #3b1c06;
    --lv3: #fca5a5;
    --lv3-bg: #3b0606;
}

/* ── RESET ────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Manrope, sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at top right, #142636 0%, #0c1020 55%, #05070d 100%);
    min-height: 100vh;
}

body:not(.high-contrast) {
    background: radial-gradient(circle at top right, #d9f0ff 0%, #f4f7f9 45%, #ecf5ea 100%);
}

/* ── SHELL ────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    min-height: 100vh;
}

/* ── TOPBAR ───────────────────────────────────────────── */
.topbar {
    background: linear-gradient(120deg, var(--brand-2), var(--brand));
    color: #fff;
    border-radius: 12px;
    padding: 10px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    box-shadow: 0 10px 24px rgba(8, 76, 97, 0.30);
    flex-shrink: 0;
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.brand-name h1 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
}

.brand-name p {
    margin: 1px 0 0;
    opacity: 0.82;
    font-size: 0.74rem;
}

.brand-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.legend-inline {
    display: flex;
    gap: 4px;
    align-items: center;
}

.legend-inline .tag {
    cursor: default;
    font-size: 0.7rem;
    padding: 2px 7px;
}

.topbar-search {
    border: 1px solid rgba(255, 255, 255, 0.30);
    border-radius: 8px;
    padding: 4px 9px;
    font-family: Manrope, sans-serif;
    font-size: 0.78rem;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    width: 190px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.topbar-search::placeholder {
    color: rgba(255, 255, 255, 0.50);
}

.topbar-search:focus {
    border-color: rgba(255, 255, 255, 0.60);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.14);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

/* ── BUTTONS ──────────────────────────────────────────── */
.btn {
    border: 0;
    border-radius: 8px;
    padding: 7px 11px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.8rem;
    font-family: Manrope, sans-serif;
    transition: opacity 0.15s, transform 0.12s;
    position: relative;
}

.btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: #ffd166;
    color: #253237;
    box-shadow: 0 4px 12px rgba(255, 209, 102, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.13);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.28);
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.06);
    color: var(--ink);
    border: 1px solid var(--line);
}

body.high-contrast .btn-ghost {
    color: var(--ink);
}

/* Icon-only buttons in topbar */
.btn-icon {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 1rem;
    line-height: 1;
    min-width: 34px;
    text-align: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.45);
}

/* tooltip mostra abaixo dos botões do topbar (ficam no topo da tela) */
.btn-icon[data-tooltip]::after {
    top: calc(100% + 8px);
    bottom: auto;
    white-space: nowrap;
    font-size: 0.72rem;
}

.btn-icon[data-tooltip]::before {
    top: calc(100% + 2px);
    bottom: auto;
    border-top-color: transparent;
    border-bottom-color: #1e293b;
}

.btn-logout {
    background: rgba(180, 35, 24, 0.25);
    border-color: rgba(255, 100, 80, 0.4);
}

.btn-logout:hover {
    background: rgba(180, 35, 24, 0.5);
}

/* ── TOOLTIPS ─────────────────────────────────────────── */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #f8fafc;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
    z-index: 500;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1e293b;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s ease;
    z-index: 500;
}

[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
    opacity: 1;
}

/* ── LEVEL TAGS ───────────────────────────────────────── */
.tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    padding: 2px 7px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    white-space: nowrap;
    flex-shrink: 0;
}

.level-1 {
    background: var(--lv1-bg);
    color: var(--lv1);
    border: 1px solid rgba(6, 78, 59, 0.20);
}

.level-2 {
    background: var(--lv2-bg);
    color: var(--lv2);
    border: 1px solid rgba(116, 66, 16, 0.20);
}

.level-3 {
    background: var(--lv3-bg);
    color: var(--lv3);
    border: 1px solid rgba(127, 29, 29, 0.20);
}

/* ── ACCORDION GRID (masonry-flex) ─────────────────────── */
.accordion-grid {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    flex-shrink: 0;
}

.accordion-group {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: visible;
    flex: 0 0 auto;
    min-width: 200px;
    max-width: min(560px, 100%);
}

.accordion-group>summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.88rem;
    user-select: none;
    list-style: none;
    border-bottom: 1px solid transparent;
    transition: background 0.15s;
}

.accordion-group[open]>summary {
    border-bottom-color: var(--line);
    background: rgba(11, 110, 79, 0.06);
}

.accordion-group>summary::-webkit-details-marker {
    display: none;
}

.accordion-group>summary::before {
    content: '\25B6';
    font-size: 0.6rem;
    color: var(--muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.accordion-group[open]>summary::before {
    transform: rotate(90deg);
}

.acc-icon {
    font-size: 1rem;
}

.acc-count {
    margin-left: auto;
    background: var(--line);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
}

.accordion-group>ul {
    list-style: none;
    padding: 6px 8px 8px;
    margin: 0;
}

/* ── AGENT GROUPS ──────────────────────────────────── */
.agent-groups-container {
    display: contents;
}

.group-body {
    padding-bottom: 4px;
}

.group-section-title {
    padding: 5px 14px 2px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* ── NESTED ACCORDION (Operários / Skills) ─────────── */
.accordion-nested {
    border: 1px solid var(--line);
    border-radius: 7px;
    margin: 4px 8px;
    overflow: visible;
}

.accordion-nested>summary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.82rem;
    color: var(--muted);
    list-style: none;
    border-bottom: 1px solid transparent;
    border-radius: 7px;
    transition: background 0.15s;
    user-select: none;
}

.accordion-nested[open]>summary {
    border-bottom-color: var(--line);
    border-radius: 7px 7px 0 0;
    background: rgba(11, 110, 79, 0.04);
}

.accordion-nested>summary::-webkit-details-marker {
    display: none;
}

.accordion-nested>summary::before {
    content: '\25B6';
    font-size: 0.55rem;
    color: var(--muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.accordion-nested[open]>summary::before {
    transform: rotate(90deg);
}

.accordion-skills>summary {
    color: var(--ink);
}

.accordion-skills {
    margin-bottom: 6px;
}

/* ── FILE ITEM ────────────────────────────────────────── */
.file-item {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 5px 7px;
    margin-bottom: 3px;
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.file-item:hover {
    background: rgba(11, 110, 79, 0.07);
    border-color: var(--line);
}

.file-item.active {
    background: rgba(11, 110, 79, 0.13);
    border-color: rgba(11, 110, 79, 0.45);
}

.file-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
    flex-shrink: 0;
}

.file-path {
    font-family: "JetBrains Mono", monospace;
    font-size: 0.66rem;
    white-space: nowrap;
    color: var(--muted);
    line-height: 1.3;
    flex-shrink: 0;
}

.file-lock {
    font-size: 0.78rem;
    color: var(--warn);
    flex-shrink: 0;
}

.btn-edit {
    flex-shrink: 0;
    border: 1px solid rgba(11, 110, 79, 0.35);
    border-radius: 5px;
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: Manrope, sans-serif;
    cursor: pointer;
    background: rgba(11, 110, 79, 0.08);
    color: var(--brand);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.btn-edit:hover {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

body.high-contrast .btn-edit {
    color: #6ee7b7;
    border-color: rgba(110, 231, 183, 0.35);
    background: rgba(110, 231, 183, 0.07);
}

body.high-contrast .btn-edit:hover {
    background: #065f46;
    color: #fff;
}

.btn-view {
    flex-shrink: 0;
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 5px;
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: Manrope, sans-serif;
    cursor: pointer;
    background: rgba(99, 102, 241, 0.08);
    color: #818cf8;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.btn-view:hover {
    background: rgba(99, 102, 241, 0.22);
    border-color: rgba(99, 102, 241, 0.6);
}

/* ── EDITOR AREA ──────────────────────────────────────── */
.editor-area {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.editor-area.hidden {
    display: none;
}

.editor-meta {
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.editor-meta-info strong {
    font-size: 0.86rem;
    font-family: "JetBrains Mono", monospace;
    word-break: break-all;
}

.editor-meta-info span {
    margin-left: 10px;
    color: var(--muted);
    font-size: 0.8rem;
}

.meta-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.switch-label {
    font-size: 0.8rem;
    color: var(--muted);
    display: inline-flex;
    gap: 5px;
    align-items: center;
    cursor: pointer;
}

.editor-panels {
    display: flex;
    flex: 1;
    min-height: 0;
}

.editor-panels.with-preview {
    /* preview left (order 1) + editor right (order 2) via CSS order */
}

.editor-panel {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    order: 2;
}

.preview-panel {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    order: 1;
    border-right: 1px solid var(--line);
    border-left: none;
    padding: 14px;
}

.preview-panel.hidden {
    display: none;
}

.CodeMirror {
    height: calc(100vh - 280px);
    min-height: 300px;
    font-family: "JetBrains Mono", monospace;
    font-size: 13px;
    background: linear-gradient(to bottom, #000000 0%, #212121 100%) !important;
}

.CodeMirror-gutters {
    background: #0a0a0a !important;
    border-right: 1px solid #2a2a2a !important;
}

.preview-panel article {
    max-width: 900px;
}

.preview-panel article h1,
.preview-panel article h2,
.preview-panel article h3 {
    margin-top: 1.2em;
    margin-bottom: 0.4em;
}

.preview-panel article pre {
    overflow: auto;
    border-radius: 8px;
}

/* ── MODAL ────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.50);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 220;
}

.modal.hidden {
    display: none;
}

.modal-card {
    width: min(1120px, 94vw);
    max-height: 88vh;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    display: flex;
    flex-direction: column;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    font-weight: 700;
}

.modal-body {
    overflow: auto;
    padding: 14px;
}

/* ── DIFF ─────────────────────────────────────────────── */
.diff-box {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    font-family: "JetBrains Mono", monospace;
    white-space: pre-wrap;
    font-size: 12px;
    line-height: 1.45;
}

.diff-box .plus {
    color: #86efac;
}

.diff-box .minus {
    color: #fca5a5;
}

/* ── TABLE ────────────────────────────────────────────── */
.table-like {
    width: 100%;
    border-collapse: collapse;
}

.table-like td,
.table-like th {
    border-bottom: 1px solid var(--line);
    padding: 7px 8px;
    font-size: 0.83rem;
    vertical-align: top;
    text-align: left;
}

/* ── SEARCH HIT ───────────────────────────────────────── */
.search-hit {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
    font-size: 0.83rem;
}

/* ── EDITOR SAVE BAR ─────────────────────────────────── */
.editor-save-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: var(--panel);
    border-radius: 0 0 10px 10px;
    flex-shrink: 0;
}

.btn-save-editor {
    font-size: 0.88rem;
    padding: 9px 18px;
    box-shadow: 0 4px 12px rgba(255, 209, 102, 0.35);
}

.save-hint {
    font-size: 0.74rem;
    color: var(--muted);
    font-family: "JetBrains Mono", monospace;
    background: var(--line);
    border-radius: 4px;
    padding: 2px 7px;
}

/* ── FLOATING SAVE ────────────────────────────────────── */
.floating-save {
    position: fixed;
    right: 14px;
    bottom: 14px;
    border: 0;
    border-radius: 999px;
    background: #14b8a6;
    color: #062a2a;
    font-weight: 800;
    font-family: Manrope, sans-serif;
    padding: 11px 20px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.30);
    cursor: pointer;
    z-index: 150;
    font-size: 0.85rem;
    transition: transform 0.15s, box-shadow 0.15s;
}

.floating-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
}

.floating-save:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

/* ── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 900px) {
    .accordion-group {
        min-width: 100%;
        max-width: 100%;
    }

    .topbar-search {
        width: 130px;
        font-size: 0.74rem;
    }

    .brand-meta {
        flex-wrap: wrap;
        gap: 5px;
    }

    .CodeMirror {
        height: 50vh;
        min-height: 200px;
    }

    .actions .btn {
        padding: 5px 7px;
        font-size: 0.74rem;
    }

    .editor-panels {
        flex-direction: column;
    }

    .editor-panel {
        order: 1;
    }

    .preview-panel {
        order: 2;
        border-right: none;
        border-top: 1px solid var(--line);
        padding: 10px;
    }
}