:root {
    --rtc-bg: #f4f6fb;
    --rtc-sidebar: #10213b;
    --rtc-sidebar-hover: #1b3357;
    --rtc-accent: #2563eb;
    --rtc-border: #e3e8f0;
    --rtc-code-bg: #0f172a;
    --rtc-code-fg: #e2e8f0;
}

html, body {
    min-height: 100%;
}

body {
    background: var(--rtc-bg);
    color: #1e293b;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 272px;
    flex: 0 0 272px;
    background: var(--rtc-sidebar);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1040;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.sidebar-brand strong {
    display: block;
    font-size: .98rem;
    line-height: 1.2;
    color: #fff;
}

.sidebar-brand small {
    display: block;
    font-size: .72rem;
    color: #94a3b8;
    margin-top: 2px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: .85rem;
    letter-spacing: .04em;
    box-shadow: 0 8px 20px rgba(37, 99, 235, .35);
}

.sidebar-nav {
    padding: 16px 10px;
    overflow-y: auto;
    flex: 1;
}

.nav-section-label {
    text-transform: uppercase;
    font-size: .66rem;
    letter-spacing: .12em;
    color: #64748b;
    padding: 4px 12px 10px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    color: #cbd5e1;
    border-radius: 9px;
    padding: 10px 12px;
    font-size: .88rem;
    margin-bottom: 3px;
    transition: background .15s ease, color .15s ease;
}

.sidebar-nav .nav-link:hover {
    background: var(--rtc-sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--rtc-accent);
    color: #fff;
    box-shadow: 0 6px 16px rgba(37, 99, 235, .28);
}

.nav-icon {
    width: 22px;
    text-align: center;
    font-size: 1rem;
    opacity: .9;
}

.sidebar-footer {
    padding: 16px 18px;
    border-top: 1px solid rgba(255, 255, 255, .09);
    font-size: .75rem;
}

.sidebar-footer a {
    color: #93c5fd;
}

.api-url {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .68rem;
    color: #a5b4fc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 4px 0 8px;
}

.main-column {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 62px;
    background: #fff;
    border-bottom: 1px solid var(--rtc-border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 26px;
    position: sticky;
    top: 0;
    z-index: 1030;
}

.topbar-title {
    flex: 1;
    font-size: .86rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-title strong {
    color: #0f172a;
}

.content-area {
    padding: 26px;
    max-width: 1560px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
}

.app-footer {
    border-top: 1px solid var(--rtc-border);
    padding: 14px 26px;
    font-size: .74rem;
    color: #94a3b8;
    background: #fff;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.page-header h1 {
    letter-spacing: -.02em;
}

.card {
    border-color: var(--rtc-border);
    border-radius: 14px;
}

.card-header {
    background: #fbfcfe;
    border-bottom-color: var(--rtc-border);
    font-size: .88rem;
}

.feature-card {
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.feature-card:hover {
    transform: translateY(-3px);
    border-color: #bfdbfe;
    box-shadow: 0 14px 30px rgba(15, 23, 42, .08) !important;
}

.feature-icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: #eff6ff;
    color: var(--rtc-accent);
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    font-weight: 700;
}

.metric-card {
    background: #fff;
    border: 1px solid var(--rtc-border);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .03);
}

.metric-card span {
    display: block;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #94a3b8;
    margin-bottom: 4px;
}

.metric-card strong {
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
}

.advanced-box {
    border: 1px dashed var(--rtc-border);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fcfdff;
}

.advanced-box summary {
    cursor: pointer;
    font-size: .82rem;
    font-weight: 600;
    color: #475569;
}

.json-view, .xml-view, .code-editor {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: .78rem;
    line-height: 1.5;
}

.json-view, .xml-view {
    background: var(--rtc-code-bg);
    color: var(--rtc-code-fg);
    border-radius: 10px;
    padding: 16px;
    max-height: 560px;
    overflow: auto;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.code-editor {
    background: var(--rtc-code-bg);
    color: var(--rtc-code-fg);
    border-color: #1e293b;
    tab-size: 2;
}

.code-editor:focus {
    background: var(--rtc-code-bg);
    color: #fff;
    border-color: var(--rtc-accent);
    box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .2);
}

.itens-table {
    table-layout: fixed;
}

.itens-table input, .itens-table select {
    min-width: 56px;
}

.itens-table .coluna-ncm-nbs {
    min-width: 126px;
    width: 126px;
}

.itens-table .campo-ncm-nbs input {
    min-width: 0;
    width: 100%;
}

.itens-table .advanced-fields {
    background: #f8fafc;
}

.item-advanced-row > td {
    background: #f8fafc;
    border-top: 0;
}

.item-advanced-row .advanced-box {
    background: #fff;
    border-style: solid;
    padding: 14px 16px 16px;
}

.item-advanced-row .advanced-box summary {
    font-size: .88rem;
}

.item-advanced-row .form-label {
    font-size: .78rem;
    color: #475569;
}

.friendly-scroll {
    max-height: 520px;
    overflow: auto;
    border: 1px solid var(--rtc-border);
    border-radius: 10px;
    background: #fff;
}

.friendly-scroll table {
    margin-bottom: 0;
}

.friendly-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
}

.friendly-scroll td {
    max-width: 420px;
    overflow-wrap: anywhere;
    vertical-align: top;
}

[data-friendly-pager] .btn {
    min-width: 2rem;
}

.itens-table .btn-remove-item,
.itens-table .btn-remove-trecho {
    padding: 2px 7px;
    line-height: 1.2;
}

.sidebar-backdrop {
    display: none;
}

.fatal-page {
    background: var(--rtc-bg);
}

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 12px 0 30px rgba(15, 23, 42, .25);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    .sidebar-backdrop.sidebar-backdrop-visible {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .45);
        z-index: 1035;
    }

    .content-area {
        padding: 18px;
    }

    .topbar {
        padding: 0 16px;
    }

    .page-header {
        flex-direction: column;
    }
}
