:root {
    --bg: #0b1020;
    --bg-soft: #11182d;
    --bg-card: #0f172a;
    --bg-input: #111827;
    --text: #e5e7eb;
    --text-soft: #9ca3af;
    --border: #25304a;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #2563eb;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

html[data-theme="light"] {
    --bg: #f3f6fb;
    --bg-soft: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text: #111827;
    --text-soft: #6b7280;
    --border: #d8e0ed;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #2563eb;
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

textarea {
    resize: vertical;
}

.app-shell {
    display: grid;
    grid-template-columns: 390px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-soft);
    border-right: 1px solid var(--border);
    overflow: auto;
}

.sidebar__header {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 16px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
}

.sidebar__header h1 {
    margin: 0;
    font-size: 28px;
}

.sidebar__header p {
    margin: 6px 0 0;
    color: var(--text-soft);
    font-size: 13px;
}

.panel {
    margin: 16px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.panel__head,
.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel__head h2,
.card__head h2 {
    margin: 0;
    font-size: 18px;
}

.field {
    margin-bottom: 14px;
}

.field--compact {
    margin-bottom: 0;
}

.field label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text-soft);
}

input,
textarea,
select {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    padding: 12px 14px;
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    color: var(--text-soft);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.action-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.depends-box {
    border: 1px solid var(--border);
    background: var(--bg-input);
    border-radius: 12px;
    padding: 12px;
    color: var(--text-soft);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-soft);
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    min-width: 0;
}

.card__head {
    padding: 16px 16px 0;
}

.card__body {
    min-height: 320px;
    padding: 16px;
    overflow: auto;
}

.card--graph {
    min-height: 420px;
}

.card--files {
    grid-column: 1 / -1;
    min-height: 500px;
}

.files-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 16px;
    padding: 0 16px 16px;
}

.files-sidebar,
.files-content {
    min-width: 0;
}

.code-box {
    margin: 0;
    padding: 16px;
    border-radius: 14px;
    background: #020617;
    color: #cbd5e1;
    border: 1px solid var(--border);
    overflow: auto;
    white-space: pre-wrap;
    min-height: 320px;
}

.card > #preview.code-box {
    height: clamp(280px, 45vh, 560px);
    min-height: 280px;
}

.card--files .files-layout {
    height: clamp(420px, 60vh, 820px);
}

.card--files .files-sidebar,
.card--files .files-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.card--files .files-sidebar #fileTree {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.card--files .files-content #fileContent.code-box {
    flex: 1;
    min-height: 0;
    height: 100%;
}

.code-box--mini {
    min-height: 120px;
    max-height: 220px;
    font-size: 12px;
    white-space: pre;
}

.agent-card {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg-input);
    padding: 14px;
}

.agent-card__head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}

.agent-card__title {
    margin: 0;
    font-size: 16px;
}

.agent-card__role {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-soft);
}

.agent-card__resp {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-soft);
}

.agent-card__meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.meta-box {
    padding: 10px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: 12px;
}

.meta-box strong {
    display: block;
    margin-top: 4px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--primary);
    color: white;
}

.muted {
    color: var(--text-soft);
    font-size: 13px;
}

.file-button {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
}

.file-button.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn {
    border: 0;
    border-radius: 12px;
    padding: 10px 14px;
    color: white;
    transition: 0.2s ease;
}

.btn--primary {
    background: var(--primary);
}

.btn--primary:hover {
    background: var(--primary-hover);
}

.btn--secondary {
    background: var(--secondary);
}

.btn--success {
    background: var(--success);
}

.btn--danger {
    background: var(--danger);
}

.btn--ghost {
    background: #334155;
}

.agent-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.agent-actions .btn {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 8px;
    width: auto !important;
}

.agent-category {
    display: inline-flex;
    font-size: 12px;
    border-radius: 999px;
    padding: 4px 10px;
    color: white;
}

html[data-theme="light"] .code-box {
    background: #0f172a;
    color: #e2e8f0;
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
        max-height: none;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }

    .card--files {
        grid-column: auto;
    }
}

@media (max-width: 820px) {
    .files-layout {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar__actions {
        width: 100%;
    }

    .topbar__actions .btn {
        flex: 1 1 calc(50% - 8px);
    }

    .agent-card__meta {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-2,
    .action-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {

    .sidebar__header,
    .topbar,
    .panel,
    .content-grid {
        padding-left: 12px;
        padding-right: 12px;
    }

    .panel {
        margin: 12px;
    }

    .content-grid {
        gap: 12px;
    }

    .card__head {
        padding: 14px 14px 0;
    }

    .files-layout {
        padding: 0 14px 14px;
    }

    .btn {
        width: 100%;
    }

    .topbar__actions {
        flex-direction: column;
        gap: 8px;
    }

    .topbar__actions .btn {
        flex: none;
        width: 100%;
    }
}

.hidden {
    display: none !important;
}

.btn--icon {
    width: 42px;
    height: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(4px);
}

.modal__dialog {
    position: relative;
    z-index: 1;
    width: min(960px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    margin: 12px auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal__header,
.modal__footer {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal__footer {
    border-top: 1px solid var(--border);
    border-bottom: 0;
}

.modal__body {
    padding: 18px;
    overflow: auto;
}

.modal__actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

body.modal-open {
    overflow: hidden;
}

@media (max-width: 820px) {
    .modal__dialog {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        margin: 8px auto;
        border-radius: 16px;
    }

    .modal__header,
    .modal__body,
    .modal__footer {
        padding: 14px;
    }

    .modal__footer {
        flex-direction: column;
        align-items: stretch;
    }

    .modal__actions {
        width: 100%;
        flex-direction: column;
    }
}

/* Collapsible Sections */
.panel.collapsed > *:not(.panel__head),
.card.collapsed > *:not(.card__head) {
    display: none !important;
}

.card.collapsed {
    min-height: 0 !important;
}

.panel__head h2::before,
.card__head h2::before {
    content: '▼';
    display: inline-block;
    font-size: 10px;
    margin-right: 8px;
    transition: transform 0.2s;
}

.panel.collapsed .panel__head h2::before,
.card.collapsed .card__head h2::before {
    transform: rotate(-90deg);
}
