/* Ом — каркас интерфейса.
   Модель экранов взята из om-prod/references: вложенные div.page, видимость
   классом .active. Оформление — приборная панель: плотно, сдержанно, золото
   означает «своё» (исходящие сообщения, активная вкладка, главное действие). */

:root {
    --outside: #011513;
    --app: #062925;
    --raised: #083832;
    --line: #0D6B60;
    --line-soft: rgba(13, 107, 96, 0.4);
    --text: #E0F5F2;
    --muted: #6ECCC2;
    --faint: #4DB6AB;
    --gold: #D4A853;

    --gold-wash: rgba(212, 168, 83, 0.13);
    --gold-edge: rgba(212, 168, 83, 0.32);

    --radius: 12px;
    --radius-sm: 8px;

    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    --mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'Roboto Mono', Menlo, Consolas, monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    background: var(--outside);
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------- прибор */

.device {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 384px;
    min-width: 320px;
    height: 100dvh;
    background: var(--app);
    overflow: hidden;
}

@media (min-width: 480px) {
    .device {
        height: min(100dvh - 4rem, 860px);
        margin: 2rem 0;
        border: 1px solid var(--line);
        border-radius: 26px;
    }
}

/* -------------------------------------------------------------- экраны */

.page {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.page.active {
    display: flex;
}

.page.auth {
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

/* Вложенный экран занимает родителя целиком. */
.page .page {
    flex: 1;
    min-height: 0;
}

.page.active > .page:not(.active) {
    display: none;
}

.page.auth > .page:not(.active) {
    display: none;
}

.page.active {
    animation: enter 140ms ease both;
}

@keyframes enter {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .page.active { animation: none; }
}

/* ---------------------------------------------------------------- вход */

.brand {
    text-align: center;
    margin-bottom: 2rem;
}

.brand__mark {
    display: block;
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    margin-bottom: 0.75rem;
}

.brand__note {
    font-size: 0.9rem;
    color: var(--muted);
    max-width: 17rem;
    margin: 0 auto;
}

.form {
    width: 100%;
    max-width: 19rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.form__title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.form__note {
    font-size: 0.87rem;
    color: var(--muted);
    margin-bottom: 1.5rem;
}

.form__note code {
    font-family: var(--mono);
    font-size: 0.85em;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
    max-width: 19rem;
    margin: 0 auto;
}

/* -------------------------------------------------------------- поля */

.field {
    display: block;
    margin-bottom: 0.3rem;
}

.field__label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.82rem;
    color: var(--muted);
}

.input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    background: var(--raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
    color: rgba(110, 204, 194, 0.4);
}

.input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.18);
}

/* ------------------------------------------------------------ кнопки */

.btn {
    padding: 0.7rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
    background: rgba(77, 182, 171, 0.08);
    border-color: var(--faint);
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.4);
}

.btn--primary {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--app);
    font-weight: 600;
}

.btn--primary:hover {
    background: #E0B761;
    border-color: #E0B761;
}

.btn--quiet {
    border-color: transparent;
    color: var(--muted);
    padding: 0.5rem;
}

.btn--quiet:hover {
    color: var(--text);
    background: rgba(77, 182, 171, 0.07);
}

.iconbtn {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    cursor: pointer;
}

.iconbtn:hover {
    background: rgba(77, 182, 171, 0.1);
    color: var(--text);
}

/* ----------------------------------------------------------- шапка */

.topbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--line-soft);
    flex: 0 0 auto;
}

.topbar__title {
    font-size: 1.05rem;
    font-weight: 600;
}

/* ------------------------------------------------------------ списки */

.list {
    list-style: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
}

.list::-webkit-scrollbar {
    display: none;
}

.item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.7rem 1rem;
    border: none;
    border-bottom: 1px solid var(--line-soft);
    background: transparent;
    color: inherit;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.item:hover {
    background: rgba(77, 182, 171, 0.06);
}

.item__body {
    flex: 1;
    min-width: 0;
}

.item__top {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    align-items: baseline;
}

.item__name {
    font-weight: 500;
    font-size: 0.93rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item__time {
    flex: 0 0 auto;
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--faint);
}

.item__preview {
    font-size: 0.84rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item__unread {
    flex: 0 0 auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--gold);
    color: var(--app);
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 600;
}

/* Буквы вместо фотографий: фотографий у нас нет, выдумывать их незачем. */
.avatar {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--raised);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ------------------------------------------------------------ строки */

.rows {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--line-soft);
}

.row__key {
    font-size: 0.8rem;
    color: var(--muted);
}

.row__val {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--text);
    word-break: break-all;
}

/* ---------------------------------------------------------- таб-бар */

.tabbar {
    flex: 0 0 auto;
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line-soft);
    background: var(--app);
}

.tab {
    flex: 1;
    padding: 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

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

.tab.active {
    color: var(--gold);
    background: var(--gold-wash);
}

.tab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.4);
}

/* ------------------------------------------------------------ диалог */

.thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 1rem 0.75rem;
    scrollbar-width: none;
}

.thread::-webkit-scrollbar {
    display: none;
}

/* Сообщения растут от низа, как в настоящем чате. auto-margin вместо
   justify-content: flex-end — иначе ломается прокрутка при переполнении. */
.thread > :first-child {
    margin-top: auto;
}

.daymark {
    align-self: center;
    margin: 0.5rem 0 0.25rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--faint);
}

.bubble {
    max-width: 78%;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius);
    background: var(--raised);
    align-self: flex-start;
    overflow-wrap: anywhere;
}

.bubble--mine {
    align-self: flex-end;
    background: var(--gold-wash);
    border: 1px solid var(--gold-edge);
    border-bottom-right-radius: 4px;
}

.bubble:not(.bubble--mine) {
    border-bottom-left-radius: 4px;
}

.bubble__time {
    display: block;
    margin-top: 0.2rem;
    font-family: var(--mono);
    font-size: 0.66rem;
    color: var(--faint);
    text-align: right;
}

.composer {
    flex: 0 0 auto;
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line-soft);
    background: var(--app);
}

.composer__field {
    flex: 1;
}

.send {
    flex: 0 0 auto;
    width: 40px;
    border: 1px solid var(--gold-edge);
    border-radius: var(--radius-sm);
    background: var(--gold-wash);
    color: var(--gold);
    font-size: 1rem;
    cursor: pointer;
}

.send:hover {
    background: rgba(212, 168, 83, 0.22);
}

.send:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.4);
}

/* ------------------------------------------------------------- пусто */

.empty {
    display: grid;
    place-items: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.88rem;
}