:root {
    --bg: #f0f4f8;
    --surface: #ffffff;
    --surface2: #f8fafc;
    --border: #dbe4ef;
    --text: #1e293b;
    --muted: #64748b;
    --primary: #166b48;
    --primary-hover: #125a3a;
    --primary-light: #e8f5ef;
    --sidebar-bg: #186347;
    --sidebar-text: #f1f5f9;
    --sidebar-muted: #b8dcc8;
    --success: #15803d;
    --danger: #b91c1c;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(24, 99, 71, 0.08), 0 4px 16px rgba(24, 99, 71, 0.06);
    --sidebar-width: 260px;
    font-family: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    min-width: 0;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    color: var(--sidebar-text);
    transition: flex-basis 0.25s ease, width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
    overflow-x: hidden;
    overflow-y: auto;
}

.app-shell.sidebar-collapsed .sidebar {
    flex-basis: 0;
    width: 0;
    min-width: 0;
    padding-left: 0;
    padding-right: 0;
    opacity: 0;
    pointer-events: none;
    border: none;
}

.main-topbar {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    margin: 0 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 90;
    background: var(--bg);
    padding: 0.35rem 0;
}

.main-inner {
    min-width: 0;
}

.sidebar-toggle {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--sidebar-bg);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(24, 99, 71, 0.25);
    transition: background 0.15s ease;
}

.sidebar-toggle:hover {
    background: var(--primary-hover);
}

.sidebar-toggle-icon {
    display: block;
    width: 14px;
    height: 14px;
    border-left: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    margin-left: 3px;
    transition: transform 0.2s ease;
}

.app-shell.sidebar-collapsed .sidebar-toggle-icon {
    transform: rotate(-135deg);
    margin-left: -2px;
}

.sidebar-backdrop {
    display: none;
}

.brand-text {
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.2s ease;
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .sidebar-welcome,
.app-shell.sidebar-collapsed .nav {
    opacity: 0;
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .5rem;
    margin-bottom: .75rem;
}

.sidebar-welcome {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.sidebar-welcome .user-chip {
    margin-bottom: .65rem;
}

.sidebar-welcome .sidebar-logout {
    width: 100%;
}

.brand-logo {
    width: 100%;
    max-width: 150px;
    height: auto;
    object-fit: contain;
    background: transparent;
    border-radius: 10px;
    padding: 0;
    flex-shrink: 0;
    display: block;
}

.brand-text strong { display: block; color: #fff; font-size: .95rem; }
.brand-text small { color: var(--sidebar-muted); font-size: .75rem; }

.nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }

.nav-section { margin-bottom: 1rem; }

.nav-section-label {
    display: block;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--sidebar-muted);
    margin: 0 0 .5rem .5rem;
}

.nav a {
    display: block;
    padding: .55rem .75rem;
    border-radius: 8px;
    color: var(--sidebar-muted);
    text-decoration: none;
    font-size: .9rem;
}

.nav a:hover,
.nav a.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    text-decoration: none;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-chip strong { color: #fff; font-size: .85rem; display: block; }
.user-chip small { color: var(--sidebar-muted); display: block; font-size: .72rem; line-height: 1.35; }

.sidebar .btn-ghost {
    color: var(--sidebar-muted);
    border-color: rgba(255, 255, 255, 0.25);
    width: 100%;
}

.sidebar .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 0 1.5rem 1.5rem;
    background: var(--bg);
    position: relative;
}

body.menu-open {
    overflow: hidden;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(288px, 88vw);
        max-width: 288px;
        flex: none;
        z-index: 1100;
        transform: translateX(-105%);
        opacity: 1;
        pointer-events: auto;
        padding: 1rem 1rem 1.25rem;
        padding-top: max(1rem, env(safe-area-inset-top));
        box-shadow: 4px 0 24px rgba(15, 23, 42, 0.2);
        transition: transform 0.25s ease;
    }

    .app-shell:not(.sidebar-collapsed) .sidebar {
        transform: translateX(0);
    }

    .app-shell.sidebar-collapsed .sidebar {
        flex-basis: auto;
        width: min(288px, 88vw);
        min-width: 0;
        padding: 1rem;
        opacity: 1;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1050;
        margin: 0;
        padding: 0;
        border: none;
        background: rgba(15, 23, 42, 0.45);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-backdrop[hidden] {
        display: none !important;
    }

    .main {
        width: 100%;
        padding: 0.75rem 1rem 1.25rem;
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .main-topbar {
        margin-bottom: 1rem;
        padding-top: max(0.35rem, env(safe-area-inset-top));
    }

    .sidebar-toggle {
        width: 44px;
        height: 44px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .table-wrap {
        margin: 0 -0.25rem;
    }

    table {
        font-size: .82rem;
    }

    th, td {
        padding: .5rem .45rem;
    }
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 600; color: var(--primary); }
.page-header p { color: var(--muted); font-size: .9rem; margin-top: .25rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1rem;
    border-radius: 8px;
    border: none;
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }

.btn-ghost {
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }

.btn-sm { padding: .35rem .7rem; font-size: .8rem; }

.alert {
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: .9rem;
}

.alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }

.form-group label { font-size: .875rem; font-weight: 500; color: var(--text); }

.form-group input,
.form-group select,
.form-group textarea {
    padding: .6rem .75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

th, td {
    padding: .65rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    background: var(--surface2);
}

.badge {
    display: inline-block;
    padding: .2rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-info { background: var(--primary-light); color: var(--primary); }

.perm-hint {
    color: var(--muted);
    font-size: .85rem;
    margin: .25rem 0 .75rem;
}

.perm-group {
    margin-bottom: 1rem;
}

.perm-group-title {
    display: block;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-bottom: .5rem;
}

.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .5rem;
}

.perm-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
    font-size: .875rem;
    cursor: pointer;
}

.perm-item input { width: auto; margin: 0; }

.actions-inline {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
}

/* Login — igual ao mont: fundo branco/claro */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(160deg, rgba(232, 240, 250, 0.92) 0%, rgba(248, 250, 252, 0.95) 50%, #ffffff 100%);
}

.login-brand {
    text-align: center;
    margin-bottom: 1.25rem;
}

.login-logo {
    max-width: 210px;
    width: 100%;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    border-radius: 12px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 1.35rem;
    margin-bottom: .35rem;
    color: var(--primary);
    text-align: center;
}

.login-card .subtitle {
    color: var(--muted);
    font-size: .9rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-card .form-group input {
    width: 100%;
    padding: .65rem .75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.login-card .form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(24, 99, 71, 0.15);
}

.dept-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.dept-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow);
    color: inherit;
    text-decoration: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.dept-card:hover {
    border-color: #9fd4bc;
    box-shadow: 0 4px 18px rgba(24, 99, 71, 0.12);
    text-decoration: none;
}

.dept-card h2,
.dept-card h3 {
    margin: 0 0 .35rem;
    font-size: 1.05rem;
    color: var(--primary);
}

.dept-card--soon {
    opacity: .85;
}

.dept-card--dash {
    min-height: auto;
    padding: 1rem 1.1rem;
}

.dept-card--dash h3 {
    margin: 0;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    margin: 0 0 1rem;
}

.dash-list {
    display: flex;
    flex-direction: column;
    gap: .65rem;
    margin-top: 1rem;
}

.dash-picker {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
}

.dash-projeto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: .75rem;
    margin-top: .75rem;
}

.dash-projeto-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .85rem;
    background: var(--surface2);
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.dash-projeto-check {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    cursor: pointer;
    margin: 0;
}

.dash-projeto-check input {
    width: auto;
    margin-top: .2rem;
    flex-shrink: 0;
}

.dash-projeto-check span {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
}

.dash-projeto-meta {
    padding-left: 1.45rem;
}

.dash-projeto-ordem {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    font-size: .8rem;
    color: var(--muted);
}

.dash-projeto-ordem .dash-sort {
    width: 72px;
}

.dash-picker-select {
    flex: 1;
    min-width: 220px;
    padding: .55rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    background: #fff;
}

.dash-row {
    display: grid;
    grid-template-columns: 64px 1fr auto auto;
    gap: .5rem;
    align-items: center;
    padding: .65rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface2);
}

.dash-row--projeto .dash-projeto-info {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
}

.dash-projeto-nome {
    font-size: .95rem;
    color: var(--text);
}

.dash-sort {
    width: 100%;
    padding: .5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.dash-row input[type="text"] {
    padding: .55rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

.dash-ativo {
    margin: 0;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .dash-row {
        grid-template-columns: 1fr;
    }
}

/* Shell do portal com dashboard embutido (iframe) */
.embed-shell-body {
    overflow: hidden;
}

.sidebar--embed {
    padding-top: 0.85rem;
}

.sidebar--embed .nav--departments {
    margin-top: 0;
}

.app-shell--embed {
    min-height: 100vh;
}

.brand--link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
    margin-bottom: 1.25rem;
}

.brand--link:hover {
    text-decoration: none;
    opacity: 0.95;
}

.nav--departments {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.15rem;
}

.nav-dept-link {
    display: block;
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    line-height: 1.3;
}

.nav-dept-link:hover {
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
    color: #fff;
}

.nav-dept-link.active {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.nav-dept-group {
    border-radius: 8px;
}

.nav-dept-group summary.nav-dept-toggle {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--sidebar-text);
    font: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    list-style: none;
}

.nav-dept-group summary.nav-dept-toggle::-webkit-details-marker {
    display: none;
}

.nav-dept-group summary.nav-dept-toggle::marker {
    content: '';
}

.nav-dept-group summary.nav-dept-toggle:hover,
.nav-dept-group[open] summary.nav-dept-toggle {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.nav-dept-chevron {
    width: 0.45rem;
    height: 0.45rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-top: -0.15rem;
    opacity: 0.85;
}

.nav-dept-group[open] .nav-dept-chevron {
    transform: rotate(45deg);
    margin-top: 0.1rem;
}

.nav-dept-label {
    flex: 1;
    min-width: 0;
}

.nav-dept-children {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.15rem 0 0.35rem 0.35rem;
    margin-left: 0.65rem;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
}

.nav-dash-link {
    display: block;
    padding: 0.45rem 0.65rem;
    border-radius: 6px;
    color: var(--sidebar-muted);
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.35;
}

.nav-dash-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}

.nav-dash-link.active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 600;
}

.nav-section--config {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.main--embed {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 0;
    overflow: hidden;
}

.main-topbar--embed {
    flex-shrink: 0;
    margin: 0;
    padding: 0.35rem 1rem;
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
    justify-content: flex-start;
}

.embed-topbar-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    min-width: 0;
    flex: 1;
}

.embed-topbar-title strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.embed-topbar-back {
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    flex-shrink: 0;
}

.embed-topbar-back:hover {
    color: var(--primary);
    text-decoration: none;
}

.embed-topbar-sep {
    color: var(--border);
}

.embed-fullscreen-btn {
    margin-left: auto;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.embed-fs-icon {
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 2px;
    position: relative;
    display: inline-block;
}

.embed-fullscreen-btn.is-active .embed-fs-icon::after {
    content: '';
    position: absolute;
    inset: 2px;
    border: 1px solid currentColor;
}

.embed-workspace {
    flex: 1;
    min-height: 0;
    padding: 12px;
    background: #e5e7eb;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.embed-workspace:fullscreen {
    background: #e5e7eb;
    padding: 0;
}

.embed-workspace:fullscreen .embed-frame {
    height: 100vh !important;
    min-height: 100vh;
}

.embed-frame {
    display: block;
    width: 100%;
    flex: 1;
    min-height: calc(100vh - 4rem);
    border: none;
    background: transparent;
    border-radius: 8px;
}
