:root {
    color-scheme: light;
    --portal-bg: #f7f8fa;
    --portal-surface: #ffffff;
    --portal-surface-2: #f1f5f9;
    --portal-border: #e8edf3;
    --portal-text: #0f172a;
    --portal-text-2: #64748b;
    --portal-muted: #94a3b8;
    --portal-brand: #f27420;
    --portal-brand-dark: #d45f12;
    --portal-brand-soft: #fff1e6;
    --portal-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px -18px rgba(15, 23, 42, 0.28);
    --portal-radius: 14px;
    --tone: #64748b;
    --tone-bg: #f1f5f9;
    --tone-soft: #e2e8f0;
}

[data-theme="dark"] {
    color-scheme: dark;
    --portal-bg: #101318;
    --portal-surface: #191d25;
    --portal-surface-2: #20252f;
    --portal-border: #2d3440;
    --portal-text: #f8fafc;
    --portal-text-2: #c0c8d4;
    --portal-muted: #7f8999;
    --portal-brand-soft: rgba(242, 116, 32, 0.16);
    --portal-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--portal-bg);
    color: var(--portal-text);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.portal-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.portal-topbar {
    min-height: 68px;
    padding: 10px clamp(16px, 2.4vw, 36px);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 18px;
    background: var(--portal-surface);
    border-bottom: 1px solid var(--portal-border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.portal-brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.portal-brand {
    display: flex;
    align-items: center;
    color: var(--portal-text);
    text-decoration: none;
}

/* Logo mantida (sem filtros / sem troca de asset) */
.portal-brand img {
    width: 142px;
    height: auto;
    display: block;
}

.nav-burger {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--portal-border);
    border-radius: 10px;
    background: var(--portal-surface);
    color: var(--portal-text-2);
    cursor: pointer;
}

.nav-burger:hover {
    background: var(--portal-surface-2);
    color: var(--portal-text);
}

.portal-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
}

.portal-nav a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: #334155;
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.portal-nav a i {
    font-size: 0.92rem;
    color: #64748b;
}

.portal-nav a:hover {
    background: #f8fafc;
    border-color: #e2e8f0;
}

.portal-nav a.is-active {
    background: var(--portal-brand);
    border-color: var(--portal-brand);
    color: #ffffff;
    box-shadow: 0 6px 14px -8px rgba(242, 116, 32, 0.9);
}

.portal-nav a.is-active i {
    color: #ffffff;
}

.portal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.icon-button,
.logout-button {
    min-height: 40px;
    border: 1px solid var(--portal-border);
    background: var(--portal-surface);
    color: var(--portal-text-2);
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.icon-button {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    text-decoration: none;
}

.icon-button:hover,
.logout-button:hover {
    background: var(--portal-surface-2);
    border-color: #cbd5e1;
    color: var(--portal-text);
}

.portal-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    min-height: 48px;
    padding: 4px 10px 4px 6px;
    border: 0;
    background: transparent;
    color: var(--portal-text);
    text-align: left;
    cursor: pointer;
    border-radius: 999px;
    transition: background 160ms ease;
}

.portal-user:hover { background: var(--portal-surface-2); }
.portal-user:focus-visible {
    outline: 3px solid rgba(242, 116, 32, 0.2);
    outline-offset: 2px;
}

.portal-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex: 0 0 auto;
    overflow: hidden;
    background: var(--portal-brand);
    color: #fff;
    font-size: 0.86rem;
    font-weight: 800;
}

.portal-avatar > span,
.portal-avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.portal-avatar > span { display: grid; place-items: center; }
.portal-avatar img { display: block; object-fit: cover; }

.portal-user-copy { min-width: 0; }
.portal-user-copy strong,
.portal-user-copy span {
    display: block;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.portal-user-copy strong {
    font-size: 0.86rem;
    font-weight: 700;
}
.portal-user-copy span {
    margin-top: 1px;
    color: var(--portal-muted);
    font-size: 0.7rem;
}

.portal-user-chevron {
    margin-left: 2px;
    color: var(--portal-muted);
    font-size: 0.62rem;
    transition: transform 160ms ease;
}
.portal-user[aria-expanded="true"] .portal-user-chevron { transform: rotate(180deg); }

.logout-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    padding: 0 14px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--portal-text);
}

/* ===== Main full-bleed ===== */
.portal-main {
    width: 100%;
    margin: 0;
    padding: 28px clamp(16px, 2.4vw, 36px) 40px;
    flex: 1;
}

.portal-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.portal-heading h1 {
    margin: 0;
    font-size: clamp(1.7rem, 2.5vw, 2.2rem);
    line-height: 1.15;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.portal-welcome {
    margin: 8px 0 0;
    color: var(--portal-text-2);
    font-size: 0.95rem;
    line-height: 1.45;
}

.module-search {
    width: min(380px, 100%);
    height: 46px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    background: var(--portal-surface);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    color: var(--portal-muted);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
    flex-shrink: 0;
}

.module-search:focus-within {
    border-color: color-mix(in srgb, var(--portal-brand) 45%, var(--portal-border));
    box-shadow: 0 0 0 3px rgba(242, 116, 32, 0.12);
}

.module-search input {
    width: 100%;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--portal-text);
    font-size: 0.9rem;
}

/* ===== Hub sections ===== */
.hub-board {
    display: grid;
    grid-template-columns: 1.2fr 1.25fr 0.9fr;
    gap: 14px;
    align-items: stretch;
}

.hub-section {
    --tone: #64748b;
    --tone-bg: #f1f5f9;
    border-radius: 16px;
    background: var(--tone-bg);
    border: 0;
    padding: 14px;
    min-width: 0;
}

.hub-section[data-tone="green"] {
    --tone: #16a34a;
    --tone-bg: #e7f8ef;
}
.hub-section[data-tone="blue"] {
    --tone: #2563eb;
    --tone-bg: #e8f1ff;
}
.hub-section[data-tone="orange"] {
    --tone: #ea580c;
    --tone-bg: #fff0e4;
}
.hub-section[data-tone="yellow"] {
    --tone: #ca8a04;
    --tone-bg: #fff8e1;
}
.hub-section[data-tone="slate"] {
    --tone: #475569;
    --tone-bg: #eef2f7;
}
.hub-section[data-tone="purple"] {
    --tone: #7c3aed;
    --tone-bg: #f2ebff;
}

.hub-section[data-area="comercial"] { grid-column: 1; grid-row: 1; }
.hub-section[data-area="gestao"] { grid-column: 2 / 4; grid-row: 1; }
.hub-section[data-area="operacao"] { grid-column: 1; grid-row: 2 / 4; }
.hub-section[data-area="subgerente"] { grid-column: 2; grid-row: 2 / 4; }
.hub-section[data-area="administracao"] { grid-column: 3; grid-row: 2; }
.hub-section[data-area="ferramentas"] { grid-column: 3; grid-row: 3; }
.hub-section[data-area="outros"] { grid-column: 1 / -1; }

.hub-section-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: var(--tone);
}

.hub-section-head i {
    width: auto;
    height: auto;
    display: inline;
    background: transparent;
    border-radius: 0;
    font-size: 0.95rem;
}

.hub-section-head h2 {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.hub-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.hub-section[data-area="administracao"] .hub-cards,
.hub-section[data-area="ferramentas"] .hub-cards {
    grid-template-columns: 1fr;
}

.module-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    min-height: 96px;
    padding: 14px;
    border: 0;
    border-radius: 12px;
    background: #ffffff;
    color: var(--portal-text);
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: transform 140ms ease, box-shadow 140ms ease;
}

.module-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px -16px rgba(15, 23, 42, 0.35);
}

.module-card:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--tone) 28%, transparent);
    outline-offset: 2px;
}

.module-card-main {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}

.module-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: transparent;
    color: var(--tone);
    font-size: 1.05rem;
    flex: 0 0 auto;
}

.module-card-body { min-width: 0; }
.module-card-body h3 {
    margin: 0 0 4px;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
    color: #0f172a;
}
.module-card-body p {
    margin: 0;
    color: #64748b;
    font-size: 0.74rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.module-arrow {
    align-self: flex-end;
    color: var(--tone);
    font-size: 0.78rem;
    opacity: 0.9;
}

.module-empty {
    min-height: 230px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 8px;
    padding: 32px;
    border: 1px dashed var(--portal-border);
    border-radius: var(--portal-radius);
    color: var(--portal-muted);
    text-align: center;
    background: var(--portal-surface);
}
.module-empty i { font-size: 1.6rem; }
.module-empty strong { color: var(--portal-text); font-size: 0.9rem; }
.module-empty span { font-size: 0.76rem; }

/* ===== Quick access ===== */
.quick-access {
    margin-top: 16px;
    padding: 16px 18px 14px;
    border-radius: 16px;
    background: #fff4eb;
    border: 0;
}

.quick-access h2 {
    margin: 0 0 12px;
    color: #f27420;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.quick-access-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.quick-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 999px;
    background: #ffffff;
    border: 0;
    color: #f27420;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    transition: transform 140ms ease, box-shadow 140ms ease;
}

.quick-pill:hover {
    transform: translateY(-1px);
    box-shadow: var(--portal-shadow);
}

.quick-pill i {
    color: var(--pill-color, #f27420);
    font-size: 0.9rem;
}

.portal-loading,
.portal-error {
    min-height: 100vh;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 14px;
    padding: 24px;
    color: var(--portal-text-2);
    text-align: center;
}

.portal-loading img { animation: portal-pulse 1.25s ease-in-out infinite; }
.portal-loading span { font-size: 0.8rem; font-weight: 600; }

.portal-error i { color: var(--portal-brand); font-size: 2rem; }
.portal-error h1 { margin: 4px 0 0; font-size: 1.25rem; }
.portal-error p { margin: 0; color: var(--portal-text-2); font-size: 0.85rem; }
.portal-error div { display: flex; gap: 8px; margin-top: 8px; }
.portal-error button,
.portal-error a {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.portal-error button { border: 1px solid var(--portal-brand); background: var(--portal-brand); color: #fff; }
.portal-error a { border: 1px solid var(--portal-border); color: var(--portal-text); background: var(--portal-surface); }

/* ===== Profile modal ===== */
.profile-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.54);
}

.profile-dialog {
    width: min(620px, 100%);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    border: 1px solid var(--portal-border);
    border-radius: 12px;
    background: var(--portal-surface);
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.24);
}

.profile-dialog-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--portal-border);
    background: var(--portal-surface);
}

.profile-dialog-header p {
    margin: 0 0 4px;
    color: var(--portal-brand);
    font-size: 0.67rem;
    font-weight: 800;
    text-transform: uppercase;
}

.profile-dialog-header h2 { margin: 0; font-size: 1.12rem; }

.profile-close {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border: 1px solid var(--portal-border);
    border-radius: 999px;
    background: var(--portal-surface);
    color: var(--portal-text-2);
    cursor: pointer;
}
.profile-close:hover { background: var(--portal-surface-2); color: var(--portal-text); }

#profileForm { padding: 22px; }

.profile-photo-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--portal-border);
}

.profile-photo {
    position: relative;
    width: 72px;
    height: 72px;
    flex: 0 0 auto;
    overflow: hidden;
    border-radius: 50%;
    background: var(--portal-brand);
    color: #fff;
    font-size: 1.3rem;
    font-weight: 800;
}

.profile-photo > span,
.profile-photo img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.profile-photo > span { display: grid; place-items: center; }
.profile-photo img { display: block; object-fit: cover; }
.profile-photo-row > div { min-width: 0; }
.profile-photo-row > div > strong,
.profile-photo-row > div > span { display: block; }
.profile-photo-row strong { font-size: 0.86rem; }
.profile-photo-row > div > span { margin: 4px 0 10px; color: var(--portal-muted); font-size: 0.72rem; line-height: 1.4; }

.profile-secondary-button,
.profile-cancel-button,
.profile-save-button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 700;
}

.profile-secondary-button,
.profile-cancel-button {
    border: 1px solid var(--portal-border);
    background: var(--portal-surface);
    color: var(--portal-text-2);
}
.profile-secondary-button:hover,
.profile-cancel-button:hover { background: var(--portal-surface-2); color: var(--portal-text); }
.profile-secondary-button:disabled,
.profile-cancel-button:disabled,
.profile-save-button:disabled { opacity: 0.58; cursor: wait; }

.profile-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.profile-field { min-width: 0; }
.profile-field > span { display: block; margin-bottom: 7px; color: var(--portal-text-2); font-size: 0.72rem; font-weight: 700; }
.profile-field input {
    width: 100%;
    height: 42px;
    padding: 0 11px;
    border: 1px solid var(--portal-border);
    border-radius: 10px;
    outline: 0;
    background: var(--portal-surface);
    color: var(--portal-text);
    font-size: 0.8rem;
}
.profile-field input:focus { border-color: var(--portal-brand); box-shadow: 0 0 0 3px rgba(242, 116, 32, 0.12); }
.profile-field input:disabled { background: var(--portal-surface-2); color: var(--portal-muted); cursor: not-allowed; }
.profile-field-full { grid-column: 1 / -1; }

.profile-password {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--portal-border);
}
.profile-password summary { color: var(--portal-text-2); cursor: pointer; font-size: 0.78rem; font-weight: 700; }
.profile-password-fields { margin-top: 15px; }
.profile-password > p { margin: 10px 0 0; color: var(--portal-muted); font-size: 0.68rem; line-height: 1.5; }

.profile-status {
    min-height: 20px;
    margin-top: 14px;
    color: var(--portal-text-2);
    font-size: 0.74rem;
}
.profile-status.is-error { color: #dc2626; }
.profile-status.is-success { color: #059669; }

.profile-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--portal-border);
}

.profile-save-button { border: 1px solid var(--portal-brand); background: var(--portal-brand); color: #fff; }
.profile-save-button:hover { background: var(--portal-brand-dark); border-color: var(--portal-brand-dark); }

[hidden] { display: none !important; }

@keyframes portal-pulse {
    0%, 100% { opacity: 0.55; transform: scale(0.96); }
    50% { opacity: 1; transform: scale(1); }
}

@media (max-width: 1180px) {
    .hub-board {
        grid-template-columns: 1fr 1fr;
    }
    .hub-section[data-area="comercial"],
    .hub-section[data-area="gestao"],
    .hub-section[data-area="operacao"],
    .hub-section[data-area="subgerente"],
    .hub-section[data-area="administracao"],
    .hub-section[data-area="ferramentas"],
    .hub-section[data-area="outros"] {
        grid-column: auto;
        grid-row: auto;
    }
    .hub-section[data-area="gestao"] { grid-column: 1 / -1; }
}

@media (max-width: 980px) {
    .portal-topbar {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "brand actions"
            "nav nav";
    }
    .portal-brand-wrap { grid-area: brand; }
    .portal-actions { grid-area: actions; }
    .portal-nav {
        grid-area: nav;
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }
    .portal-nav.is-collapsed { display: none; }
    .portal-user-copy { display: none; }
    .portal-user { min-width: 0; padding: 4px; }
    .portal-user-chevron { display: none; }
}

@media (min-width: 981px) {
    .nav-burger { display: none; }
    .portal-nav.is-collapsed { display: flex; }
}

@media (max-width: 700px) {
    .portal-topbar { padding: 10px 14px; gap: 10px; }
    .portal-brand img { width: 120px; }
    .logout-button { width: 40px; padding: 0; justify-content: center; }
    .logout-button span { display: none; }
    .portal-main { padding: 20px 14px 28px; }
    .portal-heading { align-items: stretch; flex-direction: column; gap: 14px; }
    .module-search { width: 100%; }
    .hub-board { grid-template-columns: 1fr; gap: 12px; }
    .hub-cards { grid-template-columns: 1fr; }
    .hub-section[data-area="comercial"] .hub-cards,
    .hub-section[data-area="gestao"] .hub-cards,
    .hub-section[data-area="subgerente"] .hub-cards { grid-template-columns: 1fr; }
    .quick-access { padding: 14px; }
    .profile-modal { place-items: end center; padding: 0; }
    .profile-dialog { width: 100%; max-height: 92vh; border-radius: 12px 12px 0 0; }
    .profile-dialog-header, #profileForm { padding: 18px 16px; }
    .profile-fields { grid-template-columns: 1fr; }
    .profile-dialog-footer { flex-direction: column-reverse; }
    .profile-cancel-button, .profile-save-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
