:root {
    --cp-ink: #172b4d;
    --cp-muted: #65758b;
    --cp-line: #e7edf4;
    --cp-surface: #fff;
    --cp-bg: #f5f7fb;
    --cp-primary: #4056d6;
    --cp-radius: 14px;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--cp-ink);
    background: var(--cp-bg);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.cp-topbar {
    display: flex;
    min-height: 74px;
    align-items: center;
    gap: 26px;
    padding: 12px clamp(18px, 4vw, 54px);
    background: #fff;
    border-bottom: 1px solid var(--cp-line);
    box-shadow: 0 3px 18px rgba(22, 39, 74, .04);
}

.cp-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--cp-ink);
    font-size: 1.08rem;
    font-weight: 750;
}

.cp-brand img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

.cp-topbar nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.cp-topbar nav a {
    padding: 9px 12px;
    color: var(--cp-muted);
    border-radius: 8px;
    font-size: .92rem;
    font-weight: 600;
}

.cp-topbar nav a:hover {
    color: var(--cp-primary);
    background: #f2f4ff;
    text-decoration: none;
}

.cp-account {
    display: flex;
    align-items: center;
    gap: 14px;
    color: var(--cp-muted);
    font-size: .9rem;
}

.cp-account form {
    margin: 0;
}

.cp-logout {
    min-height: 36px;
    padding: 6px 11px;
    color: var(--cp-primary);
    background: #f2f4ff;
    border-color: #e2e6ff;
}

body:has(.cp-topbar) {
    display: block;
    padding: 0;
}

body>main {
    width: 95%;
    margin: 40px auto;
    padding: clamp(24px, 4vw, 48px);
    background: var(--cp-surface);
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-radius);
    box-shadow: 0 10px 32px rgba(22, 39, 74, .06);
}

body:has(form[action*="login.php"]) {
    display: grid;
    min-height: 100dvh;
    place-items: center;
    padding: 28px 16px;
    background: linear-gradient(135deg, #f3f6ff 0%, #eef3fb 55%, #f7f9fc 100%);
}

body:has(form[action*="login.php"])>main {
    width: min(460px, 100%);
    margin: 0;
    padding: clamp(30px, 7vw, 52px);
}

body:has(form[action*="login.php"]) h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

body:has(form[action*="login.php"]) h1::before {
    flex: 0 0 auto;
    width: clamp(36px, 11vw, 48px);
    aspect-ratio: 1;
    background: url("../theme/images/portal-logo.svg") center / contain no-repeat;
    content: "";
}

body:has(form[action*="login.php"]) form {
    display: grid;
}

body:has(form[action*="login.php"]) button[type="submit"] {
    justify-self: center;
}

h1,
h2,
h3 {
    color: var(--cp-ink);
    font-weight: 700;
    letter-spacing: -.025em;
}

h1 {
    margin: 0 0 10px;
    font-size: clamp(1.7rem, 3vw, 2.2rem);
}

h2 {
    margin: 0 0 18px;
    font-size: 1.15rem;
}

p,
dt,
dd,
label {
    color: var(--cp-muted);
}

body>main>p:first-of-type {
    margin-bottom: 26px;
}

section {
    margin: 22px 0;
    padding: 22px;
    background: #fbfcfe;
    border: 1px solid var(--cp-line);
    border-radius: 12px;
}

dl {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin: 18px 0;
}

dt {
    font-size: .82rem;
}

dd {
    margin: 4px 0 0;
    color: var(--cp-ink);
    font-size: 1.45rem;
    font-weight: 700;
}

form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 16px;
    margin: 16px 0;
}

form label {
    display: grid;
    flex: 1 1 210px;
    gap: 7px;
    font-size: .9rem;
    font-weight: 600;
}

input:not([type=hidden]):not([type=checkbox]),
select {
    width: 100%;
    min-height: 44px;
    padding: 10px 13px;
    color: var(--cp-ink);
    background: #fff;
    border: 1px solid #dbe3ed;
    border-radius: 9px;
}

input:focus,
select:focus {
    outline: 3px solid rgba(64, 86, 214, .16);
    border-color: var(--cp-primary);
}

button,
.button,
a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 16px;
    color: #fff;
    background: var(--cp-primary);
    border: 1px solid var(--cp-primary);
    border-radius: 9px;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button:hover {
    filter: brightness(.94);
    color: #fff;
}

button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

a {
    color: var(--cp-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--cp-line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--cp-muted);
    background: #f7f9fc;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

td {
    color: var(--cp-ink);
}

[role=alert] {
    padding: 12px 15px;
    color: #9a2b36;
    background: #fff0f1;
    border: 1px solid #f2cdd0;
    border-radius: 9px;
}

[role=status] {
    padding: 14px 16px;
    color: #176047;
    background: #eaf8f2;
    border: 1px solid #c5ebd8;
    border-radius: 9px;
}

@media (max-width: 700px) {
    .cp-topbar {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 10px;
    }

    .cp-topbar nav {
        order: 3;
        width: 100%;
        margin-left: 0;
        overflow-x: auto;
    }

    .cp-account {
        margin-left: auto;
    }

    body>main {
        width: calc(100% - 24px);
        margin: 12px auto;
        padding: 20px;
        overflow-x: auto;
    }

    table {
        min-width: 680px;
    }

    body>main:has(table) {
        overflow-x: auto;
    }

    form {
        align-items: stretch;
    }
}

body>main.cp-client-master {
    width: min(1600px, calc(100% - 32px));
    padding: clamp(16px, 2.5vw, 36px);
    overflow: visible;
}

.cp-status-filter,
.cp-client-pagination nav {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px;
    border-radius: 9px;
    background: #edf1f6;
}

.cp-status-filter a,
.cp-client-pagination a {
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--cp-ink);
    font-size: .875rem;
}

.cp-status-filter a[aria-current],
.cp-client-pagination a[aria-current] {
    color: #fff;
    background: var(--cp-primary);
}

.cp-client-search {
    align-items: center;
    gap: 8px;
}

.cp-client-search input[type=search] {
    width: min(100%, 320px);
}

.cp-client-table {
    border: 1px solid var(--cp-line);
    border-radius: 10px;
}

.cp-client-table table {
    min-width: 780px;
}

.cp-client-details {
    min-width: 0;
    table-layout: fixed;
}

.cp-client-details th:first-child {
    width: 36%;
}

.cp-client-details td {
    overflow-wrap: anywhere;
}

.cp-client-details tbody th {
    text-transform: none;
    letter-spacing: normal;
    font-size: inherit;
}

.cp-client-identity,
.cp-client-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cp-client-avatar {
    display: grid;
    flex: 0 0 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    color: var(--cp-primary);
    background: #edf0ff;
    font-weight: 700;
}

.cp-client-actions {
    flex-wrap: wrap;
    font-size: .875rem;
}

.cp-client-actions form,
.cp-client-form {
    margin: 0;
}

.cp-client-actions .cp-action-button {
    min-height: 0;
    padding: 0;
    border: 0;
    color: var(--cp-primary);
    background: transparent;
    font-weight: 400;
}

.cp-action-button:hover {
    text-decoration: underline;
}

.cp-client-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding-top: 14px;
    font-size: .875rem;
    color: var(--cp-muted);
}

.cp-client-form {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0;
}

.cp-client-form .cp-modal-close {
    min-height: 0;
    padding: 0 8px;
    border: 0;
    color: var(--cp-ink);
    background: transparent;
    font-size: 1.5rem;
    line-height: 1.3;
}

.cp-client-form .cp-secondary-button {
    background: #edf1f6;
    border-color: #edf1f6;
    color: var(--cp-ink);
}