:root {
  --brand: #1e5eff;
  --brand-dark: #1546c8;
  --accent: #00c08b;
  --warn: #ff8a00;
  --danger: #f04438;
  --text: #101828;
  --text-2: #475467;
  --text-3: #98a2b3;
  --line: #eaecf0;
  --bg: #f5f7fa;
  --card: #ffffff;
  --sidebar: #0f172a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
  text-decoration: none;
}

/* ------------------------------------------------------------------ 登录 */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1b2a4a 0%, #0b1220 55%, #070c17 100%);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #ffffff;
  border-radius: 18px;
  padding: 32px 28px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.login-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3a74ff, #1e5eff);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-name {
  font-size: 18px;
  font-weight: 600;
}

.login-sub {
  font-size: 12px;
  color: var(--text-3);
}

.login-form .field {
  display: block;
  margin-bottom: 16px;
}

.login-form .field span {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.login-form input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(30, 94, 255, 0.12);
}

.login-error {
  min-height: 18px;
  margin: 0 0 12px;
  color: var(--danger);
  font-size: 12px;
}

.login-hint {
  margin: 18px 0 0;
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
}

/* ------------------------------------------------------------------ 布局 */
.app-view {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
}

.sidebar-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3a74ff, #1e5eff);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-name {
  font-size: 14px;
  font-weight: 600;
  color: #f8fafc;
}

.sidebar-sub {
  font-size: 10px;
  color: #64748b;
  letter-spacing: 0.5px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: #94a3b8;
  text-align: left;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
}

.nav-item.active {
  background: rgba(30, 94, 255, 0.18);
  color: #ffffff;
  font-weight: 500;
}

.nav-badge {
  float: right;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  font-size: 11px;
  color: #64748b;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
}

.sidebar-footer a {
  color: #94a3b8;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.whoami {
  font-size: 12px;
  color: var(--text-3);
  margin-right: 6px;
}

.view {
  padding: 24px 28px 48px;
  flex: 1;
}

/* ------------------------------------------------------------------ 通用组件 */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 9px;
  height: 36px;
  padding: 0 16px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-ghost {
  background: #eef2ff;
  color: var(--brand);
}

.btn-outline {
  background: #fff;
  color: var(--text-2);
  border-color: var(--line);
}

.btn-danger {
  background: #fef0ef;
  color: var(--danger);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 7px;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  padding: 0 4px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
}

.stat-label {
  font-size: 12px;
  color: var(--text-3);
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  margin-top: 6px;
  letter-spacing: -0.5px;
}

.stat-sub {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-3);
}

.panel {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

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

.filters input,
.filters select {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 12px;
  outline: none;
  background: #fff;
}

.filters input:focus,
.filters select:focus {
  border-color: var(--brand);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 11px 18px;
  border-bottom: 1px solid #f2f4f7;
  vertical-align: middle;
}

th {
  background: #fafbfc;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

tbody tr:hover {
  background: #f8fafc;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

td.actions .btn + .btn {
  margin-left: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  background: #eef2ff;
  color: var(--brand);
}

.tag-ok {
  background: #e6faf3;
  color: #027a5a;
}

.tag-warn {
  background: #fff4e5;
  color: #b25e00;
}

.tag-danger {
  background: #fef0ef;
  color: var(--danger);
}

.tag-plain {
  background: #f2f4f7;
  color: var(--text-2);
}

.muted {
  color: var(--text-3);
}

.small {
  font-size: 12px;
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.loading-state {
  padding: 36px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* ------------------------------------------------------------------ 会话 */
.chat-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 180px);
  min-height: 460px;
}

.chat-list {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-y: auto;
}

.chat-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f2f4f7;
  cursor: pointer;
}

.chat-item:hover {
  background: #f8fafc;
}

.chat-item.active {
  background: #eef2ff;
}

.chat-item-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
}

.chat-item-title span:last-child {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
}

.chat-item-preview {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-panel-head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 74%;
  padding: 9px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-self {
  align-self: flex-end;
  background: #eef2ff;
  border-color: #dbe6ff;
}

.msg-system {
  align-self: center;
  background: #f2f4f7;
  border: 0;
  color: var(--text-3);
  font-size: 11px;
  max-width: 86%;
  text-align: center;
}

.msg-meta {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-3);
}

.msg img {
  max-width: 220px;
  border-radius: 8px;
  display: block;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.chat-input textarea {
  flex: 1;
  height: 46px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.chat-input textarea:focus {
  border-color: var(--brand);
}

/* ------------------------------------------------------------------ 表单 */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field span {
  font-size: 12px;
  color: var(--text-2);
}

.form-field input,
.form-field textarea,
.form-field select {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: #fff;
  width: 100%;
}

.form-field textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.6;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: var(--brand);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* ------------------------------------------------------------------ 模态 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-panel {
  position: relative;
  width: min(880px, 100%);
  max-height: 88vh;
  background: #fff;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 15px;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

/* ------------------------------------------------------------------ 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #101828;
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.toast-error {
  background: var(--danger);
}

/* ------------------------------------------------------------------ 其他 */
.detail-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #f2f4f7;
  font-size: 13px;
}

.detail-row .label {
  width: 96px;
  flex-shrink: 0;
  color: var(--text-3);
}

.detail-row .value {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

.proposal-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 12px;
}

.proposal-card h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.proposal-body {
  margin-top: 10px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.75;
  color: var(--text-2);
  white-space: pre-wrap;
  background: #fafbfc;
  border-radius: 8px;
  padding: 12px;
}

.thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.thumbs img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

@media (max-width: 1100px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-list {
    max-height: 240px;
  }

  .chat-panel {
    height: 520px;
  }
}
