:root {
    color-scheme: light dark;
    --page: #eef4f8;
    --surface: #fff;
    --subtle: #f4f8fb;
    --line: #cbd8e4;
    --text: #111c30;
    --muted: #465973;
    --brand: #066c9f;
    --accent: #075985;
    --accent-hover: #064867;
    --focus: #087bb8;
    --error: #a21c30;
    --error-surface: #fdf0f2;
    --shadow: 0 18px 46px -28px #27405760;
    font: 15px/1.55 Inter, system-ui, sans-serif;
    color: var(--text);
    background: var(--page);
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand); text-underline-offset: .17em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
::selection { background: #bae6fd; color: #0f2840; }

.skip-link {
    position: fixed;
    inset: 12px auto auto 12px;
    z-index: 2;
    transform: translateY(-180%);
    padding: 10px 15px;
    border-radius: 10px;
    background: var(--surface);
}
.skip-link:focus { transform: none; }

.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }
.masthead-inner, .cabinet-workspace main {
    width: min(1120px, calc(100% - 40px));
    margin-inline: auto;
}
.masthead-inner {
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 24px;
    padding-block: 9px;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--brand);
    font-size: 1.16rem;
    line-height: 1.2;
    text-decoration: none;
}
.brand-label { display: block; margin-top: 3px; color: var(--muted); font-size: .77rem; }
.brand-icon {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--subtle);
}
.brand-icon img { display: block; }
.account-action { display: flex; align-items: center; gap: 10px 14px; margin: 0; }
.account-action span { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }

.cabinet-auth {
    min-height: 100dvh;
    display: grid;
    align-items: center;
    padding: 24px 16px;
    background:
        url('/static/images/logos/tsi-login-houses-light.png') left bottom / min(45vw, 430px) auto no-repeat,
        radial-gradient(ellipse at 50% 45%, #f9fcff 5%, #e7f1f9 63%, transparent 85%),
        linear-gradient(135deg, #f4f9fd, #dce9f3);
}
.cabinet-auth main { width: min(100%, 408px); margin-inline: auto; }
.auth-content.section-card {
    border-radius: 24px;
    background: #f8fcff;
    border-color: #e1eaf4;
    box-shadow: 0 26px 56px -34px #2c4b6b70;
}
.auth-content .section-card-body { padding: 26px; }
.auth-brand { display: flex; margin-bottom: 20px; }
.auth-brand .brand-icon { width: 48px; height: 48px; }
.auth-content h1 { margin: 0 0 18px; font-size: 1.38rem; letter-spacing: -.025em; }
.auth-content form > .field-label + .field-label { margin-top: 13px; }
.auth-content form .btn-primary { display: flex; width: 100%; margin-top: 18px; }
.auth-secondary { margin-top: 18px; text-align: center; font-size: .9rem; font-weight: 600; }

.cabinet-workspace main { margin-block: 24px 48px; }
.portal-page { display: grid; min-width: 0; gap: 18px; }
.page-header {
    padding: 20px 24px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--subtle);
}
.page-header h1 { font-size: 1.62rem; letter-spacing: -.025em; }
h1, h2 { margin: 0; line-height: 1.24; overflow-wrap: anywhere; }
h2 { font-size: 1.06rem; }
p { margin: .55rem 0; }
.section-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.section-card-header, .section-card-body { padding: 16px 20px; }
.section-card-header { border-bottom: 1px solid var(--line); }
.section-card-body > :first-child { margin-top: 0; }
.section-card-body > :last-child { margin-bottom: 0; }

.field-label { display: grid; gap: 6px; min-width: 0; font-size: .87rem; font-weight: 600; color: var(--muted); }
.field-control {
    min-width: 0;
    width: 100%;
    min-height: 45px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    font-weight: 400;
}
.field-control:hover { border-color: var(--muted); }
.field-control:focus-visible { outline-offset: 1px; }
.auth-content .field-control { min-height: 48px; }
textarea.field-control { min-height: 88px; resize: vertical; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: 12px; }
legend { padding-inline: 5px; font-weight: 600; }
summary { cursor: pointer; }

.btn-primary, .btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 43px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: .89rem;
    font-weight: 650;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-secondary:hover { background: var(--subtle); border-color: var(--muted); }
button:disabled { cursor: default; opacity: .58; }

.form-error {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--error-surface);
    color: var(--error);
}
.totp-qr { display: block; width: 184px; height: auto; max-width: 100%; margin: 14px auto; border: 8px solid #fff; border-radius: 10px; }
code { overflow-wrap: anywhere; }
.flex { display: flex; }
.grid { display: grid; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-end { align-items: end; }
.items-start { align-items: start; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-3 { margin-top: 12px; }
.space-y-2 > * + * { margin-top: 8px; }
.space-y-3 > * + * { margin-top: 12px; }
.space-y-4 > * + * { margin-top: 16px; }
.font-medium, .font-semibold { font-weight: 600; }
.overflow-x-auto { overflow-x: auto; }
.tsi-table { width: 100%; border-collapse: collapse; }
.tsi-table th, .tsi-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tsi-table th { background: var(--subtle); color: var(--muted); font-size: .85rem; }
.tsi-table tbody tr:last-child td { border-bottom: 0; }

@media (max-width: 560px) {
    .masthead-inner, .cabinet-workspace main { width: calc(100% - 24px); }
    .cabinet-workspace main { margin-top: 15px; }
    .page-header, .section-card-header, .section-card-body { padding: 14px; }
    .page-header h1 { font-size: 1.4rem; }
    .auth-content .section-card-body { padding: 21px; }
    .tsi-table { min-width: 510px; }
}
@media (prefers-color-scheme: dark) {
    :root {
        --page: #101a2b;
        --surface: #172337;
        --subtle: #192a41;
        --line: #42556e;
        --text: #eff6ff;
        --muted: #bdcce0;
        --brand: #76cdff;
        --accent: #075985;
        --accent-hover: #086995;
        --focus: #7dd3fc;
        --error: #ffc4ca;
        --error-surface: #462b39;
    }
    .cabinet-auth {
        background:
            url('/static/images/logos/tsi-login-houses-dark.png') left bottom / min(45vw, 430px) auto no-repeat,
            radial-gradient(ellipse at 50% 45%, #1d3853, #141f34 64%, #0d1627);
    }
    .auth-content.section-card { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
}
