:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --text: #191919;
    --muted: #5f5f5a;
    --line: #d9d9d6;
    --line-strong: #2a2a2a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}

.page-shell {
    min-height: 0;
    flex: 1;
    width: min(100%, 1600px);
    margin: 0 auto;
    padding: clamp(12px, 2.5vw, 32px);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(14px, 2.5vw, 32px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0;
    box-shadow: 0 4px 16px rgb(0 0 0 / 8%);
}

.brand {
    flex: 0 0 auto;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-decoration: none;
}

.topbar-links {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    min-width: 0;
    justify-content: flex-end;
}

.topbar-links a {
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 8px;
}

.topbar-links a[aria-current="page"] {
    color: var(--text);
    background: #ececeb;
}

.user-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.account-menu {
    position: relative;
    max-width: 100%;
    min-width: 0;
}

.user-menu-button {
    max-width: 100%;
    min-width: 0;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease;
}

.user-menu-button:hover,
.user-menu-button[aria-expanded="true"] {
    border-color: var(--line);
    background: #f2f2f0;
}

.user-menu-button:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
}

.account-menu-chevron {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    margin-top: -3px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    transition: transform 140ms ease;
}

.user-menu-button[aria-expanded="true"] .account-menu-chevron {
    margin-top: 3px;
    transform: rotate(225deg);
}

.account-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 120;
    width: 176px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 14px 36px rgb(0 0 0 / 14%);
}

.account-menu-dropdown[hidden] { display: none; }

.account-menu-dropdown button {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.account-menu-dropdown .account-menu-danger {
    color: #b42335;
}

.account-menu-dropdown button:hover,
.account-menu-dropdown button:focus-visible {
    background: #fff0f1;
    outline: 0;
}

.page-back-row {
    display: flex;
    align-items: center;
}

.page-back-row-wide {
    width: 100%;
    padding: 14px clamp(12px, 2.5vw, 32px) 0;
}

.page-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 24px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.page-back:hover {
    color: var(--text);
}

.page-back:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 3px;
    border-radius: 4px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: clamp(16px, 2vw, 24px);
}

h1,
h2 {
    margin: 0 0 8px;
    font-weight: 600;
}

.muted {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 14px;
}

.auth-message {
    margin: 14px 0;
    padding: 10px 12px;
    border: 1px solid #e2c46f;
    border-radius: 8px;
    background: #fff8df;
    color: #664d03;
    font-size: 14px;
    line-height: 1.45;
}

.form-stack,
.form-grid {
    display: grid;
    gap: 10px;
}

label {
    font-size: 13px;
    color: #313131;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    padding: 10px 12px;
    font-size: 14px;
}

input:focus,
select:focus {
    outline: 2px solid #000;
    outline-offset: 1px;
    border-color: #000;
}

.btn {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    min-height: 42px;
}

.btn-primary {
    background: #111;
    color: #fff;
}

.btn-primary:hover {
    background: #000;
}

.btn-ghost {
    background: #fff;
    color: var(--text);
    border-color: var(--line);
    padding: 6px 10px;
}

.helper-text {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.helper-text a {
    color: var(--text);
}

.pill {
    display: inline-block;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
}

.status-pill {
    background: #fff;
    color: var(--text);
    cursor: pointer;
}

.status-pill:hover {
    border-color: var(--line-strong);
}

@media (max-width: 560px) {
    .topbar {
        padding: 10px 12px;
    }

    .brand,
    .topbar-links a,
    .user-name,
    .user-menu-button {
        font-size: 13px;
    }

    .topbar-links a {
        padding: 6px;
    }
}

@media (max-width: 480px) {
    .topbar {
        flex-wrap: nowrap;
        gap: 10px;
        padding-block: 9px;
    }

    .brand {
        flex: 0 0 auto;
        width: auto;
    }

    .topbar-links {
        width: auto;
        margin-left: auto;
        flex-wrap: nowrap;
        justify-content: flex-end;
        gap: 7px;
    }

    .user-name {
        min-width: 0;
        max-width: none;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .user-menu-button {
        max-width: 100%;
        padding: 6px 8px;
    }
}

@media (max-width: 350px) {
    .brand,
    .user-name,
    .user-menu-button {
        font-size: 12px;
    }

    .topbar {
        gap: 7px;
    }
}

@media (max-width: 600px) {
    :root {
        --bg: #fbfbfa;
        --text: #151515;
        --muted: #666662;
        --line: #d8d8d4;
    }

    body {
        -webkit-font-smoothing: antialiased;
        text-rendering: optimizeLegibility;
    }

    .page-shell {
        padding: 22px 16px 32px;
    }

    .topbar {
        min-height: 68px;
        gap: 10px;
        padding: 10px 14px;
        border-width: 0 0 1px;
        box-shadow: 0 5px 18px rgb(0 0 0 / 6%);
    }

    .brand {
        font-size: 15px;
        font-weight: 750;
        letter-spacing: -0.01em;
    }

    .topbar-links {
        gap: 8px;
    }

    .user-name {
        max-width: none;
        font-size: 14px;
        font-weight: 700;
    }

    .user-menu-button {
        min-height: 42px;
        padding: 9px 12px;
        border-radius: 11px;
        font-size: 14px;
    }

    .account-menu-dropdown {
        width: 168px;
    }

    .account-menu-dropdown button {
        min-height: 46px;
        font-size: 15px;
    }

    .page-back-row-wide {
        padding: 8px 10px 0;
    }

    .page-back {
        width: 44px;
        height: 44px;
        font-size: 27px;
    }

    .card {
        border-radius: 14px;
        padding: 20px;
    }

    h1,
    h2 {
        letter-spacing: -0.025em;
    }

    .muted {
        font-size: 16px;
        line-height: 1.45;
    }

    .form-stack,
    .form-grid {
        gap: 11px;
    }

    label {
        font-size: 15px;
    }

    input,
    select {
        min-height: 52px;
        padding: 12px 14px;
        border-radius: 10px;
        font-size: 16px;
    }

    .btn {
        min-height: 52px;
        padding: 12px 16px;
        border-radius: 10px;
        font-size: 16px;
        font-weight: 700;
    }

    .btn-ghost {
        min-height: 44px;
        padding: 9px 13px;
        font-size: 14px;
        font-weight: 600;
    }

    .helper-text,
    .auth-message {
        font-size: 14px;
        line-height: 1.5;
    }
}

@media (max-width: 370px) {
    .topbar {
        gap: 7px;
        padding-inline: 10px;
    }

    .brand { font-size: 14px; }
    .user-name { max-width: none; font-size: 13px; }
    .user-menu-button { padding-inline: 8px; font-size: 13px; }
}
