:root {
    --ink: #132522;
    --muted: #667773;
    --line: #dfe7e4;
    --paper: #f6f8f7;
    --white: #fff;
    --brand: #0c7668;
    --brand-dark: #075d53;
    --brand-soft: #dff3ed;
    --sent: #d9fdd3;
    --danger: #a43636;
    --shadow: 0 18px 55px rgba(20, 53, 47, .12);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 10%, rgba(12,118,104,.14), transparent 35%),
        var(--paper);
}

.auth-card {
    width: min(100%, 430px);
    background: var(--white);
    padding: 38px;
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

h1, h2, p { margin-top: 0; }
.auth-card h1 { margin-bottom: 8px; font-size: 28px; }
.auth-card > p:not(.eyebrow) { color: var(--muted); margin-bottom: 28px; }
.eyebrow { margin: 0 0 6px; color: var(--brand); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.stack { display: grid; gap: 18px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
input, textarea {
    width: 100%;
    border: 1px solid #cbd8d4;
    border-radius: 10px;
    padding: 12px 13px;
    color: var(--ink);
    background: var(--white);
    outline: none;
}
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(12,118,104,.12); }
button[type="submit"], .composer button {
    border: 0;
    border-radius: 10px;
    padding: 12px 18px;
    color: white;
    background: var(--brand);
    font-weight: 800;
}
button[type="submit"]:hover, .composer button:hover { background: var(--brand-dark); }
button:disabled { cursor: not-allowed; opacity: .55; }

.notice { padding: 12px 14px; margin: 18px 0; border-radius: 10px; font-size: 14px; }
.notice.error { color: #762525; background: #fde8e8; }
.notice.success { color: #155d41; background: #e2f7ed; }

.inbox-page { height: 100vh; overflow: hidden; background: #e9efed; }
.shell { width: min(1500px, 100%); height: 100vh; margin: auto; display: grid; grid-template-columns: 380px 1fr; background: white; box-shadow: var(--shadow); }
.sidebar { min-width: 0; display: grid; grid-template-rows: auto auto 1fr auto; border-right: 1px solid var(--line); background: white; }
.sidebar-header, .chat-header { min-height: 82px; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.sidebar-header h1 { margin: 0; font-size: 21px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); font-size: 24px; line-height: 1; }
.connection-state { padding: 8px 20px; color: var(--muted); background: var(--paper); border-bottom: 1px solid var(--line); font-size: 12px; }
.connection-state.online { color: #176447; }
.connection-state.error { color: var(--danger); }
.conversation-list { min-height: 0; overflow-y: auto; }
.conversation { width: 100%; border: 0; border-bottom: 1px solid #edf1ef; padding: 15px 18px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; text-align: left; background: white; color: var(--ink); }
.conversation:hover, .conversation.active { background: #f0f7f5; }
.conversation-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-time { color: var(--muted); font-size: 11px; }
.conversation-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread { min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; justify-self: end; border-radius: 12px; color: white; background: var(--brand); font-size: 11px; font-weight: 800; }
.account-bar { min-height: 56px; padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.account-bar form { margin: 0; }
.account-bar a, .users-heading a { color: var(--brand); font-weight: 700; text-decoration: none; }
.link-button { border: 0; padding: 4px; color: var(--brand); background: transparent; font-weight: 700; }

.chat-panel { min-width: 0; min-height: 0; background: #efeae2; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; color: var(--muted); }
.empty-mark { width: 78px; height: 78px; margin-bottom: 20px; display: grid; place-items: center; border-radius: 24px; color: var(--brand); background: var(--brand-soft); font-weight: 900; }
.empty-state h2 { margin-bottom: 8px; color: var(--ink); }
.chat { height: 100%; min-height: 0; display: grid; grid-template-rows: auto 1fr auto auto; }
.hidden { display: none !important; }
.chat-header { background: #fafcfb; }
.chat-header h2 { margin: 0 0 3px; font-size: 18px; }
.chat-header p { margin: 0; color: var(--muted); font-size: 12px; }
.window-status { padding: 6px 9px; border-radius: 8px; font-size: 11px; font-weight: 800; background: var(--brand-soft); color: var(--brand-dark); }
.window-status.closed { background: #f5e8df; color: #7b4527; }
.message-list { min-height: 0; overflow-y: auto; padding: 26px 6%; background-color: #efeae2; background-image: radial-gradient(rgba(30, 70, 62, .06) 1px, transparent 1px); background-size: 17px 17px; }
.message-row { display: flex; margin: 7px 0; }
.message-row.outbound { justify-content: flex-end; }
.bubble { max-width: min(620px, 78%); padding: 9px 11px 6px; border-radius: 10px; background: white; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; overflow-wrap: anywhere; }
.outbound .bubble { background: var(--sent); }
.message-meta { display: flex; gap: 7px; justify-content: flex-end; margin-top: 4px; color: #71807c; font-size: 10px; }
.message-error { color: var(--danger); }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; padding: 14px 20px; background: #f6f8f7; border-top: 1px solid var(--line); }
.composer textarea { max-height: 130px; resize: none; }
.composer-note { min-height: 25px; margin: 0; padding: 4px 22px 8px; color: var(--muted); background: #f6f8f7; font-size: 11px; }

dialog { width: min(92vw, 480px); border: 1px solid var(--line); border-radius: 18px; padding: 26px; color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(9, 30, 27, .55); }
dialog p { color: var(--muted); font-size: 14px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 430px; padding: 13px 16px; border-radius: 10px; color: white; background: #183d36; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #8d3030; }

.users-card { width: min(100%, 1000px); background: white; padding: 34px; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.users-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 30px; }
.users-heading h1, .users-grid h2 { margin: 0; }
.users-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 42px; }
.user-list { margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.user-row { min-height: 68px; padding: 13px 15px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row small { display: block; margin-top: 4px; color: var(--muted); }
.secondary-button { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--brand-dark); background: white; font-weight: 700; }
.self-badge { padding: 5px 8px; border-radius: 7px; color: var(--brand-dark); background: var(--brand-soft); font-size: 11px; font-weight: 800; }

@media (max-width: 760px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { border: 0; }
    .chat-panel { position: fixed; inset: 0; z-index: 3; }
    .chat-panel:not(.mobile-open) { display: none; }
    .chat-header::before { content: '‹'; margin-right: 12px; color: var(--brand); font-size: 32px; cursor: pointer; }
    .bubble { max-width: 88%; }
    .users-card { padding: 24px; }
    .users-grid { grid-template-columns: 1fr; }
}
