/* CORREÇÃO DO LAYOUT PRINCIPAL */
html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    max-width: 100%;
}

body {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    height: 100vh;
    box-sizing: border-box;
}

.main {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    box-sizing: border-box;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --sidebar-width: 250px;
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #718096;
    --border: #e7ebf2;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
    --sidebar: #111827;
}

.mobile-menu-toggle {
    display: none;
}

body {
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--bg);
    color: var(--text);
}

body.unauthenticated {
    display: block;
}

body.unauthenticated > .sidebar,
body.unauthenticated > .main,
body.unauthenticated > .modal,
body.unauthenticated > #toast {
    display: none;
}

.login-screen {
    display: none;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #eef4ff, #f7f5ff);
}

body.unauthenticated .login-screen {
    display: flex;
}

.login-card {
    width: min(100%, 420px);
    padding: 32px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--card);
    box-shadow: 0 18px 48px #1720331a;
}

.login-brand {
    padding: 0 0 26px;
}

.login-card h1 {
    font-size: 22px;
}

.login-card > p {
    margin: 7px 0 24px;
    color: var(--muted);
}

.login-card form {
    display: grid;
    gap: 16px;
}

.login-submit,
.logout-btn,
.secondary-btn {
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.login-submit {
    padding: 11px 14px;
}

.admin-identity {
    display: grid;
    gap: 3px;
    margin-bottom: 10px;
    color: #fff;
    font-size: 12px;
}

.admin-identity span {
    color: #9ca3af;
    overflow-wrap: anywhere;
}

.logout-btn {
    width: 100%;
    margin-bottom: 14px;
    padding: 8px;
    background: #374151;
}

.secondary-btn {
    padding: 10px 14px;
    background: #e9eef7;
    color: var(--text);
}

.secondary-btn:hover:not(:disabled) {
    background: #dce5f3;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

.sidebar {
    width: 250px;
    min-height: 100vh;
    background: var(--sidebar);
    color: white;
    padding: 22px 15px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 5px 10px 28px;
}

.brand-logo {
    display: block;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    object-fit: contain;
    border-radius: 10px;
}

.brand strong {
    display: block;
    font-size: 15px;
}

.brand span {
    display: block;
    font-size: 11px;
    color: #9ca3af;
    margin-top: 3px;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: #aeb7c7;
    text-align: left;
    padding: 12px 13px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: .2s;
}

.nav-item:hover {
    background: #1f2937;
    color: white;
}

.nav-item.active {
    background: #2563eb;
    color: white;
}

.nav-item span {
    width: 20px;
    text-align: center;
}

.sidebar-bottom {
    margin-top: auto;
    padding: 15px 10px 5px;
}

.connection {
    font-size: 12px;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 8px;
}

.connection-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
}

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

.topbar {
    height: 86px;
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 0 34px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topbar h1 {
    font-size: 23px;
}

.topbar p {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.refresh-btn {
    border: 1px solid var(--border);
    background: white;
    padding: 9px 15px;
    border-radius: 8px;
    color: #374151;
}

.refresh-btn:hover {
    background: #f8fafc;
}

.section {
    display: none;
    padding: 30px 34px;
}

.section.active {
    display: block;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    margin-bottom: 22px;
}

.stat-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-card span {
    color: var(--muted);
    font-size: 12px;
    display: block;
}

.stat-card strong {
    display: block;
    font-size: 26px;
    margin-top: 5px;
}

.stat-icon {
    width: 43px;
    height: 43px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.stat-icon.blue {
    background: #eff6ff;
    color: #2563eb;
}

.stat-icon.yellow {
    background: #fff7ed;
    color: #d97706;
}

.stat-icon.green {
    background: #f0fdf4;
    color: #16a34a;
}

.stat-icon.red {
    background: #fef2f2;
    color: #dc2626;
}

.panel.system-status-panel {
    padding: 0;
    overflow: hidden;
}

.system-status-header {
    padding: 20px 22px 0;
}

.sao-paulo-clock {
    min-width: 178px;
    text-align: right;
}

.sao-paulo-clock span,
.sao-paulo-clock small {
    display: block;
    color: var(--muted);
    font-size: 11px;
}

.sao-paulo-clock strong {
    display: block;
    margin: 4px 0;
    font-size: 14px;
}

.system-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.system-metric {
    min-width: 0;
    padding: 20px 22px;
    border-right: 1px solid var(--border);
}

.system-metric:last-child {
    border-right: 0;
}

.system-metric-label,
.system-metric-detail {
    display: block;
    color: var(--muted);
    font-size: 11px;
}

.system-metric strong {
    display: block;
    margin: 7px 0 6px;
    font-size: 22px;
}

.system-metric-detail {
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.system-services {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    padding: 16px 22px;
}

.system-service {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.system-service > span {
    color: var(--muted);
    font-size: 11px;
}

.system-service > strong:not(.health-badge) {
    font-size: 15px;
}

.health-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 10px;
    white-space: nowrap;
}

.health-badge.healthy {
    color: #166534;
    background: #dcfce7;
}

.health-badge.unhealthy {
    color: #991b1b;
    background: #fee2e2;
}

.health-badge.unavailable {
    color: #475569;
    background: #f1f5f9;
}

.system-alerts {
    min-height: 42px;
    padding: 0 22px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.system-alert,
.system-ok,
.system-unavailable {
    display: inline-flex;
    align-items: center;
    padding: 6px 9px;
    border-radius: 6px;
    font-size: 11px;
}

.system-ok {
    color: #166534;
    background: #f0fdf4;
}

.system-unavailable {
    color: #475569;
    background: #f1f5f9;
}

.system-alert.warning {
    color: #92400e;
    background: #fffbeb;
}

.system-alert.critical {
    color: #991b1b;
    background: #fef2f2;
}

.grid-two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.panel,
.form-panel {
    background: white;
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 23px;
    margin-bottom: 20px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.panel-header h2 {
    font-size: 16px;
}

.panel-header p {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.account-search {
    margin-bottom: 16px;
}

.small-btn {
    border: 1px solid var(--border);
    background: white;
    border-radius: 7px;
    padding: 8px 12px;
    font-size: 12px;
}

.small-btn:hover {
    background: #f8fafc;
}

.panel-actions {
    display: flex;
    gap: 8px;
}

.account-summary {
    min-height: 80px;
}

.account-card {
    display: flex;
    align-items: center;
    gap: 13px;
}

.account-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #eff6ff;
    color: #2563eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.account-info strong {
    display: block;
    font-size: 14px;
}

.account-info {
    min-width: 0;
}

.account-info span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
    overflow-wrap: anywhere;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 20px;
    padding: 5px 9px;
    font-size: 11px;
    font-weight: 600;
}

.status.success {
    color: #15803d;
    background: #f0fdf4;
}

.status.queued {
    color: #1d4ed8;
    background: #eff6ff;
}

.status.running {
    color: #b45309;
    background: #fff7ed;
}

.status.failed {
    color: #b91c1c;
    background: #fef2f2;
}

.status.cancelled {
    color: #475569;
    background: #f1f5f9;
}

.job-row {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 14px;
    margin-bottom: 9px;
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.job-main {
    min-width: 0;
}

.job-message {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 500px;
}

.job-meta {
    color: var(--muted);
    font-size: 11px;
    margin-top: 5px;
    overflow-wrap: anywhere;
}

.job-context {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.job-context span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.job-position {
    color: var(--text);
    font-weight: 600;
}

.performance-job {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}

.performance-job summary {
    min-height: 64px;
    padding: 13px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    cursor: pointer;
}

.performance-job-title {
    min-width: 0;
}

.performance-job-title strong,
.performance-job-title small {
    display: block;
    overflow-wrap: anywhere;
}

.performance-job-title small {
    margin-top: 5px;
    color: var(--muted);
}

.performance-summary-value {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
}

.performance-sections {
    padding: 0 16px 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.performance-group {
    min-width: 0;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.performance-group h3 {
    margin-bottom: 8px;
    font-size: 12px;
}

.performance-group dl > div {
    min-width: 0;
    padding: 5px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 11px;
}

.performance-group dt {
    color: var(--muted);
}

.performance-group dd {
    min-width: 0;
    text-align: right;
    overflow-wrap: anywhere;
}

.performance-analysis,
.performance-empty {
    margin: 0 16px 16px;
    padding: 12px;
    border-radius: 6px;
    background: #f8fafc;
    font-size: 12px;
}

.performance-analysis strong,
.performance-analysis span {
    display: block;
}

.performance-analysis span {
    margin-top: 5px;
    color: var(--muted);
}

.job-status {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    flex-direction: column;
    gap: 7px;
}

.danger-btn {
    color: #b91c1c;
    border-color: #fecaca;
}

.danger-btn:hover {
    background: #fef2f2;
}

.empty,
.loading {
    color: var(--muted);
    font-size: 13px;
    padding: 20px 0;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.form-group.full {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    border: 1px solid #dce2eb;
    border-radius: 8px;
    padding: 11px 12px;
    background: white;
    color: var(--text);
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px #2563eb14;
}

.form-group textarea {
    resize: vertical;
    min-height: 150px;
}

.form-group small {
    color: var(--muted);
    font-size: 11px;
}

.char-count {
    text-align: right;
    color: var(--muted);
    font-size: 11px;
}

.timezone-info {
    margin-top: 20px;
    padding: 12px 14px;
    background: #f8fafc;
    border-radius: 8px;
    color: #64748b;
    font-size: 12px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}

.primary-btn {
    border: 0;
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
}

.primary-btn:hover {
    background: var(--primary-dark);
}

.primary-btn:disabled {
    opacity: .6;
    cursor: wait;
}

.result {
    margin-top: 20px;
    padding: 15px;
    border-radius: 9px;
    font-size: 13px;
}

.result.success {
    background: #f0fdf4;
    color: #166534;
}

.result.error {
    background: #fef2f2;
    color: #991b1b;
}

.hidden {
    display: none;
}

.form-hint {
    color: var(--muted);
    font-size: 12px;
    margin-top: 16px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #11182780;
}

.modal.hidden {
    display: none;
}

.modal-card {
    width: min(100%, 520px);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: white;
    border-radius: 13px;
    padding: 24px;
    box-shadow: 0 20px 55px #11182740;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 18px;
}

.modal-header p {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.modal-close {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 28px;
    line-height: 1;
}

.toast {
    position: fixed;
    right: 25px;
    bottom: 25px;
    background: #111827;
    color: white;
    padding: 12px 17px;
    border-radius: 8px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: .25s;
    z-index: 1000;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 900px) {
    :root {
        --sidebar-width: 205px;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-two {
        grid-template-columns: 1fr;
    }

    .system-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .system-metric:nth-child(2) {
        border-right: 0;
    }

    .system-metric:nth-child(-n + 2) {
        border-bottom: 1px solid var(--border);
    }

    .system-services {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 650px) {
    :root {
        --sidebar-width: 0px;
    }

    body {
        display: block;
        min-width: 0;
    }

    .sidebar {
        position: sticky;
        top: 0;
        right: auto;
        bottom: auto;
        z-index: 1000;
        width: 100%;
        height: auto;
        min-height: auto;
        padding: 10px 14px;
        display: block;
        border-bottom: 1px solid #273244;
    }

    .brand {
        min-height: 48px;
        padding: 0 54px 0 0;
    }

    .brand-logo {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
        border-radius: 8px;
    }

    .mobile-menu-toggle {
        position: absolute;
        top: 12px;
        right: 14px;
        display: inline-flex;
        width: 44px;
        height: 44px;
        align-items: center;
        justify-content: center;
        border: 1px solid #374151;
        border-radius: 8px;
        background: #1f2937;
        color: white;
        font-size: 24px;
        line-height: 1;
    }

    nav {
        display: none;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding-top: 10px;
    }

    .nav-item {
        min-height: 48px;
        padding: 10px;
        white-space: normal;
    }

    .sidebar-bottom {
        display: none;
    }

    .sidebar.mobile-menu-open nav {
        display: grid;
    }

    .sidebar.mobile-menu-open .sidebar-bottom {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        margin-top: 10px;
        padding: 10px 0 0;
        border-top: 1px solid #374151;
    }

    .sidebar-bottom .admin-identity {
        min-width: 0;
        margin: 0;
    }

    .sidebar-bottom .logout-btn {
        width: auto;
        min-width: 72px;
        min-height: 44px;
        margin: 0;
        padding: 10px 14px;
    }

    .sidebar-bottom .connection {
        display: none;
    }

    .main {
        width: 100%;
        min-width: 0;
        margin-left: 0;
    }

    .topbar {
        gap: 12px;
        padding: 16px;
        height: auto;
    }

    .topbar > div {
        min-width: 0;
    }

    .topbar h1 {
        font-size: 20px;
    }

    .topbar p {
        overflow-wrap: anywhere;
    }

    .refresh-btn {
        min-height: 44px;
        padding: 9px 12px;
        flex: 0 0 auto;
    }

    .section {
        min-width: 0;
        padding: 16px;
    }

    .stats {
        grid-template-columns: 1fr;
    }

    .system-status-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .sao-paulo-clock {
        min-width: 0;
        text-align: left;
    }

    .system-metrics,
    .system-services {
        grid-template-columns: 1fr;
    }

    .system-status-header,
    .system-metric,
    .system-services {
        padding-left: 16px;
        padding-right: 16px;
    }

    .system-service {
        min-height: 36px;
    }

    .system-alerts {
        padding-right: 16px;
        padding-left: 16px;
    }

    .system-metric,
    .system-metric:nth-child(2) {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .system-metric:last-child {
        border-bottom: 0;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full {
        grid-column: auto;
    }

    .panel,
    .form-panel {
        min-width: 0;
        padding: 16px;
    }

    .panel-header {
        align-items: flex-start;
        gap: 12px;
    }

    .panel-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .small-btn,
    .primary-btn,
    .secondary-btn,
    .login-submit {
        min-height: 44px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        min-height: 46px;
        font-size: 16px;
    }

    .form-actions {
        flex-wrap: wrap;
        gap: 10px;
    }

    .form-actions > button {
        flex: 1 1 180px;
    }

    .job-row {
        min-width: 0;
        flex-direction: column;
        gap: 12px;
    }

    .job-message {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .job-context {
        display: grid;
        grid-template-columns: 1fr;
    }

    .job-status {
        width: 100%;
        align-items: stretch;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .job-status .status {
        min-height: 32px;
        margin-right: auto;
    }

    .job-status button {
        min-height: 44px;
    }

    .account-card {
        align-items: flex-start;
    }

    .performance-job summary {
        align-items: flex-start;
        flex-direction: column;
    }

    .performance-sections {
        grid-template-columns: 1fr;
        padding-right: 12px;
        padding-left: 12px;
    }

    .performance-summary-value {
        flex: auto;
    }

    .performance-group dl > div {
        align-items: flex-start;
    }

    .performance-analysis,
    .performance-empty {
        margin-right: 12px;
        margin-left: 12px;
    }

    .modal {
        align-items: flex-end;
        padding: 8px;
    }

    .modal-card {
        max-height: calc(100vh - 16px);
        max-height: calc(100dvh - 16px);
        padding: 18px 16px;
        border-radius: 8px;
    }

    .modal-close {
        width: 44px;
        height: 44px;
        flex: 0 0 auto;
    }

    .toast {
        right: 12px;
        bottom: 12px;
        left: 12px;
        max-width: none;
        text-align: center;
    }

    .login-screen {
        min-height: 100vh;
        min-height: 100dvh;
        padding: 16px;
    }

    .login-card {
        padding: 22px 18px;
        border-radius: 8px;
    }
}

@media (max-width: 360px) {
    .topbar {
        align-items: flex-start;
    }

    .refresh-btn {
        width: 44px;
        padding: 0;
        font-size: 0;
    }

    .refresh-btn::before {
        content: "↻";
        color: #374151;
        font-size: 20px;
    }

    .section {
        padding: 12px;
    }

    .panel-header:not(.system-status-header) {
        flex-direction: column;
    }

    .panel-actions,
    .panel-header > .small-btn {
        width: 100%;
    }

    .panel-actions .small-btn,
    .panel-header > .small-btn {
        flex: 1 1 auto;
        min-height: 44px;
    }
}
