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

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #dde1e7;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --msg-user-bg: #eff6ff;
    --msg-bot-bg: #f0fdf4;
    --msg-operator-bg: #fef9c3;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius: 6px;
}

body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

/* ---- Header ---- */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
}

nav {
    display: flex;
    gap: 20px;
    align-items: center;
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}

nav a:hover { color: var(--text); }

nav a.logout { color: var(--danger); }

/* ---- Container ---- */
.container {
    max-width: 960px;
    margin: 32px auto;
    padding: 0 24px;
}

/* ---- Page header ---- */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.page-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    padding: 4px 0;
}

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

.user-info {
    font-size: 13px;
    color: var(--text-muted);
    margin-left: auto;
}

/* ---- Badge ---- */
.badge-count {
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
}

/* ---- Table ---- */
.data-table {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-collapse: collapse;
    overflow: hidden;
}

.data-table th {
    background: #f8f9fb;
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td {
    background: #fafbfc;
}

.col-id { width: 52px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.col-user { width: 160px; }
.col-time { width: 90px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.col-action { width: 96px; text-align: right; }
.col-preview { max-width: 360px; color: var(--text-muted); }

.username { color: var(--text-muted); font-size: 12px; }

/* ---- Buttons ---- */
.btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: background 0.1s, border-color 0.1s;
    white-space: nowrap;
}

.btn:hover { background: var(--bg); border-color: #c0c5ce; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; text-align: center; }

/* ---- Empty state ---- */
.empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---- Thread ---- */
.thread {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
    max-height: 500px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.message {
    padding: 10px 14px;
    border-radius: var(--radius);
    max-width: 80%;
}

.message-user {
    background: var(--msg-user-bg);
    align-self: flex-start;
}

.message-bot {
    background: var(--msg-bot-bg);
    align-self: flex-start;
}

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

.message-meta {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.message-time { font-weight: 400; }

.message-body { font-size: 14px; white-space: pre-wrap; word-break: break-word; }

/* ---- Reply form ---- */
.reply-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.field input,
.field textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color 0.1s;
    resize: vertical;
}

.field input:focus,
.field textarea:focus {
    border-color: var(--accent);
    background: var(--surface);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Alerts ---- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: var(--danger);
}

/* ---- Login page ---- */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
    width: 340px;
}

.login-box h1 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    text-align: center;
}
