:root {
    --ink: #17211c;
    --muted: #758078;
    --line: #e7ebe8;
    --paper: #ffffff;
    --canvas: #f3f6f3;
    --green: #16a66a;
    --green-dark: #0d8452;
    --green-soft: #e7f7ef;
    --dashboard-max-width: 1880px;
    --card-shadow: 0 18px 50px rgba(29, 61, 43, .07);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 8%, rgba(39, 196, 126, .09), transparent 28%),
        radial-gradient(circle at 88% 4%, rgba(71, 139, 219, .08), transparent 25%),
        var(--canvas);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.shell { min-height: 100vh; }

.login-card {
    width: min(640px, calc(100% - 32px));
    margin: clamp(96px, 17vh, 184px) auto 0;
    padding: 52px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: var(--paper);
    box-shadow: 0 30px 90px rgba(30, 55, 41, .12);
}

.brand, .eyebrow {
    color: var(--green-dark);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
.login-card h1 { margin: 14px 0 10px; font-size: clamp(32px, 3vw, 46px); letter-spacing: -.03em; }
.login-card > p, .section-heading p, .message-heading p { color: var(--muted); }
label { display: block; margin: 30px 0 9px; font-size: 13px; font-weight: 700; }

.token-row { display: flex; gap: 10px; }
input, select {
    min-width: 0;
    border: 1px solid #dce2de;
    border-radius: 11px;
    color: var(--ink);
    background: #fff;
    outline: none;
}
input { flex: 1; padding: 15px 16px; }
select { padding: 10px 34px 10px 13px; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }

button {
    border: 0;
    border-radius: 11px;
    padding: 12px 18px;
    color: #fff;
    background: var(--green);
    font-weight: 700;
}
button:hover { background: var(--green-dark); }
button.secondary { border: 1px solid var(--line); color: var(--ink); background: #fff; }
.error { min-height: 20px; margin-top: 10px; color: #c63e3e; font-size: 13px; }

.dashboard {
    width: min(var(--dashboard-max-width), calc(100% - clamp(40px, 6vw, 120px)));
    margin: 0 auto;
    padding: clamp(30px, 4vh, 52px) 0;
}
.topbar, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar { margin-bottom: clamp(24px, 2vw, 34px); }
.topbar h1 { margin: 5px 0 0; font-size: clamp(30px, 2.2vw, 38px); letter-spacing: -.025em; }
.topbar-actions { display: flex; gap: 10px; }

.chart-card, .conversation-card, .message-card {
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--paper);
    box-shadow: var(--card-shadow);
}
.chart-card { padding: clamp(24px, 2vw, 34px); }
.section-heading h2, .message-heading h2 { margin-bottom: 5px; font-size: 18px; }
.section-heading p, .message-heading p { margin-bottom: 0; font-size: 13px; }
.period-tabs { display: flex; padding: 4px; border-radius: 10px; background: var(--canvas); }
.period-tabs button, .conversation-tabs button { color: var(--muted); background: transparent; font-size: 13px; }
.period-tabs button { padding: 8px 12px; }
.period-tabs button.active, .conversation-tabs button.active { color: var(--green-dark); background: #fff; box-shadow: 0 2px 8px rgba(30, 55, 41, .08); }

.chart {
    display: flex;
    align-items: end;
    gap: 8px;
    height: clamp(190px, 20vh, 250px);
    margin-top: 22px;
    padding-top: 12px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
}
.bar-column { display: flex; flex: 1 0 42px; height: 100%; flex-direction: column; justify-content: end; align-items: center; gap: 7px; }
.bar-value { color: var(--muted); font-size: 11px; }
.bar { width: min(26px, 70%); min-height: 3px; border-radius: 7px 7px 2px 2px; background: linear-gradient(180deg, #2bc580, var(--green)); }
.bar-label { height: 19px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.chart-empty { margin: auto; color: var(--muted); }

.content-grid {
    display: grid;
    grid-template-columns: minmax(360px, .62fr) minmax(620px, 1.7fr);
    gap: clamp(18px, 1.4vw, 28px);
    margin-top: clamp(18px, 1.4vw, 28px);
}
.conversation-card, .message-card { height: clamp(620px, calc(100vh - 410px), 820px); overflow: hidden; }
.compact, .message-heading { min-height: 81px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.conversation-tabs { display: flex; flex: none; padding: 3px; border-radius: 9px; background: var(--canvas); }
.conversation-tabs button { padding: 7px 9px; }
.conversation-list, .message-list { height: calc(100% - 81px); overflow: auto; }

.conversation-item {
    display: grid;
    grid-template-columns: 46px 1fr auto;
    gap: 12px;
    width: 100%;
    padding: 15px 18px;
    border: 0;
    border-bottom: 1px solid #f0f2f0;
    border-radius: 0;
    color: var(--ink);
    text-align: left;
    background: transparent;
}
.conversation-item:hover, .conversation-item.active { background: #f0faf5; }
.avatar { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; color: var(--green-dark); background: var(--green-soft); font-weight: 800; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.conversation-main { min-width: 0; }
.conversation-name { display: flex; align-items: center; gap: 7px; margin: 2px 0 6px; font-weight: 700; }
.conversation-summary { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.conversation-time { padding-top: 3px; color: #9aa39d; font-size: 11px; }

.message-list { padding: 22px; background: #fafcfb; }
.message-row { display: flex; margin-bottom: 17px; }
.message-row.out { justify-content: flex-end; }
.message-bubble { max-width: 76%; }
.message-meta { margin: 0 3px 5px; color: var(--muted); font-size: 11px; }
.message-row.out .message-meta { text-align: right; }
.message-content { padding: 10px 13px; border: 1px solid var(--line); border-radius: 5px 14px 14px 14px; white-space: pre-wrap; overflow-wrap: anywhere; background: #fff; font-size: 14px; line-height: 1.55; }
.message-row.out .message-content { border-color: #bcebd4; border-radius: 14px 5px 14px 14px; background: #dff7eb; }
.message-image, .message-video { display: block; max-width: min(420px, 100%); max-height: 420px; border-radius: 9px; }
.message-content audio { display: block; max-width: 100%; }
.message-file { color: var(--green-dark); font-weight: 700; }
.empty-state { display: grid; place-items: center; color: var(--muted); }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 380px; padding: 13px 16px; border-radius: 10px; color: #fff; background: #b93c3c; box-shadow: 0 10px 30px rgba(0,0,0,.15); }

@media (min-width: 1600px) {
    .content-grid { grid-template-columns: minmax(420px, 470px) minmax(0, 1fr); }
    .conversation-card, .message-card { height: clamp(680px, calc(100vh - 430px), 880px); }
    .compact, .message-heading { padding-right: 28px; padding-left: 28px; }
    .conversation-item { padding: 17px 22px; }
    .message-list { padding: 30px; }
    .message-bubble { max-width: min(72%, 920px); }
}

@media (max-width: 900px) {
    .content-grid { grid-template-columns: 1fr; }
    .conversation-card, .message-card { height: 540px; }
}

@media (max-width: 620px) {
    .login-card { margin-top: 8vh; padding: 28px 22px; }
    .token-row, .topbar, .section-heading { align-items: stretch; flex-direction: column; }
    .dashboard { width: calc(100% - 20px); padding-top: 20px; }
    .topbar-actions { width: 100%; }
    .topbar-actions select { flex: 1; }
    .period-tabs { overflow-x: auto; }
    .period-tabs button { flex: 1 0 auto; }
    .content-grid { grid-template-columns: minmax(0, 1fr); }
}
