:root {
    --portal-accent: #a31123;
    --portal-accent-dark: #7f0d1c;
    --portal-ink: #0f172a;
    --portal-muted: #64748b;
    --portal-line: #e5ebf3;
    --portal-bg: #f5f7fb;
}

body {
    background: var(--portal-bg);
}

.portal-crm-shell {
    color: var(--portal-ink);
}

.portal-sidebar-brand {
    display: grid;
    gap: 0.35rem;
    color: #ffffff;
}

.portal-sidebar-brand img {
    display: block;
    width: 148px;
    max-width: 100%;
    height: auto;
    filter: brightness(0) invert(1);
}

.portal-sidebar-brand span {
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.portal-shell {
    min-height: 100vh;
    color: var(--portal-ink);
}

.portal-public-shell {
    display: grid;
    grid-template-rows: auto 1fr;
}

.portal-public-header {
    min-height: 72px;
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
}

.portal-header {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: #ffffff;
    border-bottom: 1px solid var(--portal-line);
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.04);
}

.portal-brand img {
    display: block;
    width: 170px;
    height: auto;
}

.portal-nav {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.portal-nav a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    color: #334155;
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.portal-nav a:hover {
    background: #f8fafc;
    color: var(--portal-accent);
}

.portal-main {
    width: min(1220px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.5rem 0 2.5rem;
}

.portal-public-main {
    display: grid;
    align-content: center;
    padding-top: 0;
}

.crm-content-wrap.portal-main {
    width: min(1220px, calc(100% - 2rem));
    padding-top: 1.5rem !important;
    padding-bottom: 2.5rem !important;
}

.portal-alerts {
    margin-bottom: 1rem;
}

.portal-alerts .alert {
    border-radius: 8px;
    border-width: 1px;
    box-shadow: none;
}

.portal-auth {
    min-height: calc(100vh - 128px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
    align-items: center;
    gap: 1.25rem;
}

.portal-auth--compact {
    grid-template-columns: minmax(320px, 430px);
    justify-content: center;
}

.portal-auth__copy {
    background: #ffffff;
    border: 1px solid var(--portal-line);
    border-radius: 8px;
    padding: 1.5rem;
}

.portal-auth__copy h1 {
    margin: 0 0 0.5rem;
    font-size: 1.75rem;
    font-weight: 800;
}

.portal-auth__copy p,
.portal-card p,
.portal-muted {
    color: var(--portal-muted);
}

.portal-card {
    background: #ffffff;
    border: 1px solid var(--portal-line);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.055);
    padding: 1.2rem;
}

.portal-auth__card {
    padding: 1.4rem;
}

.portal-card h2,
.portal-auth__card h2 {
    margin: 0 0 0.35rem;
    color: var(--portal-ink);
    font-size: 1.15rem;
    font-weight: 800;
}

.portal-link,
.portal-card__header a {
    color: var(--portal-accent);
    font-weight: 800;
    text-decoration: none;
}

.portal-card .form-control,
.portal-card .form-select {
    min-height: 42px;
    border-radius: 8px;
    border-color: #d9e2ef;
    box-shadow: none !important;
}

.portal-card .form-control:focus,
.portal-card .form-select:focus {
    border-color: var(--portal-accent);
    box-shadow: 0 0 0 4px rgba(163, 17, 35, 0.12) !important;
}

.portal-card .btn-primary,
.portal-auth .btn-primary,
.portal-property .btn-primary {
    background: var(--portal-accent);
    border-color: var(--portal-accent);
}

.portal-card .btn-primary:hover,
.portal-auth .btn-primary:hover,
.portal-property .btn-primary:hover {
    background: var(--portal-accent-dark);
    border-color: var(--portal-accent-dark);
}

.portal-code-input {
    text-align: center;
    letter-spacing: 0.35em;
    font-weight: 800;
}

.portal-page-title {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1.2rem;
    background: #ffffff;
    border: 1px solid var(--portal-line);
    border-radius: 8px;
}

.portal-page-title p {
    margin: 0 0 0.25rem;
    color: var(--portal-muted);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.portal-page-title h1 {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 800;
}

.portal-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: flex-end;
}

.portal-summary div,
.portal-account-strip {
    min-width: 150px;
    padding: 0.75rem 0.9rem;
    background: #f8fafc;
    border: 1px solid var(--portal-line);
    border-radius: 8px;
}

.portal-summary span,
.portal-account-strip span,
.portal-payment-footer span {
    display: block;
    color: var(--portal-muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.portal-summary strong,
.portal-account-strip strong,
.portal-payment-footer strong {
    display: block;
    color: var(--portal-ink);
    font-size: 1.08rem;
    font-weight: 800;
}

.portal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.portal-property__top {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--portal-line);
}

.portal-property__top span {
    color: var(--portal-muted);
    font-size: 0.8rem;
    font-weight: 800;
}

.portal-property__top h2 {
    margin: 0.2rem 0 0;
}

.portal-badge {
    border-radius: 999px;
    padding: 0.38rem 0.62rem;
    background: #fff1f3;
    color: var(--portal-accent) !important;
    white-space: nowrap;
}

.portal-details {
    display: grid;
    gap: 0.45rem;
    margin: 0.9rem 0;
}

.portal-details div {
    display: grid;
    grid-template-columns: 112px 1fr;
    gap: 0.75rem;
}

.portal-details dt {
    color: var(--portal-muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.portal-details dd {
    margin: 0;
    font-weight: 700;
}

.portal-account-strip--large {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.portal-account-strip--stack {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
}

.portal-account-strip--stack > div {
    min-width: 0;
}

.portal-card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    margin-top: 0.9rem;
}

.portal-section-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
    gap: 1rem;
}

.portal-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--portal-line);
}

.portal-list {
    display: grid;
}

.portal-list-item {
    display: block;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--portal-line);
    color: var(--portal-ink);
    text-decoration: none;
}

button.portal-list-item {
    width: 100%;
    background: transparent;
    border-top: 0;
    border-right: 0;
    border-left: 0;
    text-align: left;
}

.portal-list-item:last-child {
    border-bottom: 0;
}

.portal-list-item span {
    display: block;
    font-weight: 800;
}

.portal-list-item small {
    display: block;
    color: var(--portal-muted);
    margin-top: 0.2rem;
}

.portal-document-item {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    gap: 0.75rem;
}

.portal-document-item__icon {
    color: #b42318;
    font-size: 1.45rem;
}

.portal-document-item:hover {
    color: var(--portal-accent);
}

.portal-document-modal .modal-body {
    padding: 0;
}

.portal-document-modal iframe {
    display: block;
    width: 100%;
    height: min(72vh, 760px);
    border: 0;
    background: #f8fafc;
}

.portal-payment-stack {
    display: grid;
    gap: 1rem;
}

.portal-payment-card--selected {
    border-color: rgba(163, 17, 35, 0.28);
}

.portal-account-table .portal-table-row--morosa > td {
    color: #b42318;
}

.portal-account-table .portal-table-row--morosa .portal-muted {
    color: #b42318 !important;
}

.portal-payment-table tbody tr.portal-payment-row--selected > td {
    background: #ecfdf3;
    border-bottom-color: #b7e4c7;
}

.portal-payment-summary-strip {
    min-width: min(520px, 100%);
}

.portal-payment-table {
    margin-bottom: 0;
}

.portal-payment-table thead th {
    background: #f8fafc;
    color: var(--portal-muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--portal-line);
}

.portal-payment-table tbody td {
    border-bottom: 1px solid #edf2f7;
}

.portal-payment-table .form-check-input {
    width: 1.1rem;
    height: 1.1rem;
}

.portal-payment-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 1rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--portal-line);
}

.portal-request-card {
    display: block;
    color: var(--portal-ink);
    text-decoration: none;
}

.portal-request-card:hover {
    border-color: rgba(163, 17, 35, 0.32);
    color: var(--portal-ink);
}

.portal-request-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    color: var(--portal-muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.portal-thread {
    display: grid;
    gap: 0.85rem;
}

.portal-thread-item {
    max-width: min(760px, 100%);
    padding: 0.9rem;
    border: 1px solid var(--portal-line);
    border-radius: 8px;
    background: #f8fafc;
}

.portal-thread-item--client {
    margin-left: auto;
    background: #fff7ed;
}

.portal-thread-item--sgp {
    margin-right: auto;
    background: #f8fafc;
}

.portal-thread-item__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    color: var(--portal-muted);
    font-size: 0.82rem;
}

.portal-thread-item__head strong {
    color: var(--portal-ink);
}

.portal-thread-item__body {
    margin-top: 0.45rem;
    white-space: pre-line;
}

.portal-thread-reply {
    padding-top: 0.9rem;
    border-top: 1px solid var(--portal-line);
}

@media (max-width: 768px) {
    .portal-public-header {
        min-height: 64px;
        padding: 0.9rem 1rem;
    }

    .portal-header {
        align-items: flex-start;
        flex-direction: column;
        padding: 1rem;
    }

    .portal-brand img {
        width: 150px;
    }

    .portal-nav {
        width: 100%;
        overflow-x: auto;
    }

    .portal-main {
        width: min(100% - 1rem, 680px);
        padding: 1rem 0 2rem;
    }

    .crm-content-wrap.portal-main {
        width: min(100% - 1rem, 680px);
        padding: 1rem 0 2rem !important;
    }

    .portal-auth,
    .portal-page-title,
    .portal-summary,
    .portal-account-strip--stack,
    .portal-card-actions,
    .portal-payment-footer,
    .portal-section-grid {
        display: grid;
        grid-template-columns: 1fr;
    }

    .portal-auth__copy {
        display: none;
    }

    .portal-page-title {
        align-items: start;
    }
}
