:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --border: #d9e0e4;
    --text: #172026;
    --muted: #61717c;
    --accent: #177245;
    --accent-dark: #0f5d36;
    --customer: #eef4f8;
    --operator: #eaf7ef;
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
}

.topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    height: 56px;
    justify-content: space-between;
    padding: 0 24px;
}

.brand {
    color: var(--accent-dark);
    font-weight: 700;
    text-decoration: none;
}

.topbar nav,
.logout {
    align-items: center;
    display: flex;
    gap: 12px;
}

.operator {
    color: var(--muted);
}

.page {
    margin: 0 auto;
    max-width: 1120px;
    padding: 24px;
}

.toolbar,
.dialog-header {
    align-items: flex-end;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 16px;
}

h1 {
    font-size: 28px;
    line-height: 1.2;
    margin: 0;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filters a,
button {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    font: inherit;
    padding: 8px 12px;
    text-decoration: none;
}

.filters a.active,
button {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

button:hover {
    background: var(--accent-dark);
}

.conversation-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.conversation-row {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 14px 16px;
    text-decoration: none;
}

.conversation-row:last-child {
    border-bottom: 0;
}

.conversation-row:hover {
    background: #f9fbfb;
}

.conversation-row strong,
.conversation-row span {
    display: block;
}

.conversation-row span,
.conversation-meta,
.details,
.dialog-header p,
.back-link,
.message-meta {
    color: var(--muted);
}

.conversation-meta {
    align-items: flex-end;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 160px;
    text-align: right;
}

.conversation-meta b {
    align-items: center;
    background: var(--accent);
    border-radius: 999px;
    color: #ffffff;
    display: inline-flex;
    font-size: 12px;
    height: 22px;
    justify-content: center;
    min-width: 22px;
    padding: 0 7px;
}

.dialog-header p {
    margin: 6px 0 0;
}

.back-link {
    display: inline-block;
    margin-bottom: 8px;
    text-decoration: none;
}

.details {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: right;
}

.message-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.message {
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 760px;
    padding: 12px 14px;
}

.message.customer {
    background: var(--customer);
}

.message.operator {
    align-self: flex-end;
    background: var(--operator);
}

.message.system {
    align-self: center;
    background: var(--surface);
}

.message-meta {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 6px;
}

.message p {
    margin: 0;
    white-space: normal;
    word-break: break-word;
}

.reply-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
}

textarea,
input[type="text"],
input[type="password"] {
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    padding: 10px 12px;
    width: 100%;
}

.reply-form button {
    align-self: flex-end;
}

.login-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin: 64px auto;
    max-width: 420px;
    padding: 24px;
}

.login-panel form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 20px;
}

.empty,
.flash-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.flash {
    margin-bottom: 16px;
}

@media (max-width: 720px) {
    .topbar,
    .toolbar,
    .dialog-header,
    .conversation-row {
        align-items: stretch;
        flex-direction: column;
    }

    .conversation-meta,
    .details {
        align-items: flex-start;
        text-align: left;
    }

    .page {
        padding: 16px;
    }
}
