:root {
    --bg: #eef2f3;
    --surface: #ffffff;
    --surface-soft: #f6f8f8;
    --ink: #162024;
    --muted: #66777d;
    --line: #d9e1e4;
    --blue: #2d6cdf;
    --blue-dark: #1f54b2;
    --green: #158467;
    --coral: #cf5f47;
    --amber: #b98112;
    --shadow: 0 18px 50px rgba(22, 32, 36, 0.16);
}

* {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(45, 108, 223, 0.14), transparent 36%),
        linear-gradient(315deg, rgba(21, 132, 103, 0.16), transparent 42%),
        var(--bg);
}

.auth-panel {
    width: min(430px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.brand-lockup,
.brand-inline,
.drawer-profile,
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-lockup {
    margin-bottom: 28px;
}

.brand-lockup h1,
.modal-header h2,
.empty-state h2 {
    margin: 0;
}

.brand-lockup p,
.brand-inline span,
.drawer-profile span,
.chat-header span {
    display: block;
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.brand-mark,
.empty-mark {
    display: inline-grid;
    place-items: center;
    width: 52px;
    aspect-ratio: 1;
    background: var(--ink);
    color: #fff;
    border-radius: 8px;
    font-weight: 800;
    font-size: 25px;
}

.brand-mark.small {
    width: 36px;
    font-size: 18px;
}

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

label span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
}

input,
select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 0 12px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.14);
}

.button,
.icon-button {
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.button {
    gap: 8px;
    padding: 0 16px;
    font-weight: 800;
}

.button.primary {
    background: var(--blue);
    color: #fff;
}

.button.primary:hover {
    background: var(--blue-dark);
}

.icon-button {
    width: 42px;
    padding: 0;
    background: var(--surface-soft);
    color: var(--ink);
    border: 1px solid var(--line);
}

.icon-button:hover {
    background: #eaf0f2;
}

.form-error {
    min-height: 18px;
    margin: 0;
    color: var(--coral);
    font-size: 13px;
    font-weight: 700;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    height: 66px;
    display: grid;
    grid-template-columns: 42px 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 0 18px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.hamburger-line {
    width: 18px;
    height: 2px;
    background: var(--ink);
    display: block;
    margin: 2px 0;
    border-radius: 2px;
}

.random-button {
    min-width: 124px;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(290px, 380px) 1fr;
    gap: 18px;
    padding: 18px;
    min-height: 0;
}

.list-pane,
.chat-pane {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    min-height: calc(100vh - 102px);
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-soft);
}

.tab {
    min-height: 38px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-weight: 800;
}

.tab.active {
    background: #fff;
    color: var(--ink);
    box-shadow: 0 1px 3px rgba(22, 32, 36, 0.1);
}

.chat-list {
    display: grid;
    align-content: start;
    max-height: calc(100vh - 158px);
    overflow: auto;
}

.chat-item {
    width: 100%;
    min-height: 74px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: #fff;
    display: grid;
    grid-template-columns: 46px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    text-align: left;
}

.chat-item:hover,
.chat-item.active {
    background: #f2f7f6;
}

.avatar {
    width: 42px;
    aspect-ratio: 1;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--green), var(--blue));
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 900;
    overflow: hidden;
    text-transform: uppercase;
}

.avatar.large {
    width: 58px;
}

.avatar.xlarge {
    width: 86px;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-copy {
    min-width: 0;
}

.chat-copy strong,
.chat-copy span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-copy span {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

.chat-badges {
    display: grid;
    gap: 6px;
    justify-items: end;
}

.favorite-dot,
.unread-dot {
    min-width: 24px;
    min-height: 24px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 900;
}

.favorite-dot {
    background: rgba(185, 129, 18, 0.14);
    color: var(--amber);
}

.unread-dot {
    background: var(--coral);
    color: #fff;
}

.chat-pane {
    display: grid;
    min-width: 0;
}

.chat-pane.empty {
    place-items: center;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    display: grid;
    justify-items: center;
    gap: 12px;
    padding: 24px;
}

.empty-state h2 {
    color: var(--ink);
    font-size: 20px;
}

.chat-active {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: calc(100vh - 102px);
}

.chat-header {
    min-height: 70px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.chat-header > div:nth-child(2) {
    min-width: 0;
    flex: 1;
}

.chat-header strong,
.chat-header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.star-button.is-favorite {
    color: var(--amber);
    background: rgba(185, 129, 18, 0.14);
}

.message-list {
    min-height: 0;
    overflow: auto;
    padding: 18px;
    display: grid;
    align-content: end;
    gap: 10px;
    background:
        linear-gradient(180deg, rgba(246, 248, 248, 0.86), rgba(255, 255, 255, 0.86)),
        #fff;
}

.message {
    max-width: min(72%, 620px);
    padding: 10px 12px;
    border-radius: 8px;
    line-height: 1.35;
    word-break: break-word;
}

.message.mine {
    justify-self: end;
    background: var(--blue);
    color: #fff;
}

.message.theirs {
    justify-self: start;
    background: #e9eeee;
    color: var(--ink);
}

.message time {
    display: block;
    margin-top: 5px;
    font-size: 11px;
    opacity: 0.75;
}

.composer {
    min-height: 66px;
    display: grid;
    grid-template-columns: 1fr 42px;
    gap: 10px;
    padding: 12px;
    border-top: 1px solid var(--line);
    background: #fff;
}

.send-button {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

.drawer-backdrop,
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(22, 32, 36, 0.36);
    z-index: 20;
}

.drawer {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    background: #fff;
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
    transform: translateX(-102%);
    transition: transform 160ms ease;
    z-index: 30;
    padding: 18px;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-profile {
    padding: 8px 0 18px;
    border-bottom: 1px solid var(--line);
}

.drawer-nav {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.drawer-nav button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--ink);
    text-align: left;
    padding: 0 12px;
    font-weight: 800;
}

.drawer-nav button:hover {
    background: #eaf0f2;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
    z-index: 40;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.avatar-upload {
    display: flex;
    align-items: center;
    gap: 14px;
}

.avatar-upload input {
    padding-top: 10px;
}

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.switch-row {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.switch-row span {
    margin: 0;
    color: var(--ink);
    font-size: 15px;
}

.switch-row input {
    width: 48px;
    min-height: 26px;
    accent-color: var(--green);
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(360px, calc(100vw - 36px));
    background: var(--ink);
    color: #fff;
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: var(--shadow);
    z-index: 50;
    font-weight: 700;
}

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

    .random-button {
        min-width: 104px;
        padding: 0 12px;
    }

    .workspace {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .list-pane,
    .chat-pane,
    .chat-active {
        min-height: auto;
    }

    .chat-list {
        max-height: 42vh;
    }

    .chat-active {
        height: 52vh;
    }

    .message {
        max-width: 84%;
    }
}

@media (max-width: 520px) {
    .brand-inline strong {
        display: none;
    }

    .split {
        grid-template-columns: 1fr;
    }
}
