:root {
  color-scheme: light;
  --ink: #17211a;
  --muted: #667069;
  --line: #e4e9e5;
  --paper: #ffffff;
  --canvas: #f4f7f4;
  --green: #1f7a4d;
  --green-dark: #155b39;
  --green-soft: #e7f4ec;
  --shadow: 0 18px 44px rgba(32, 57, 42, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: inherit; }
.topbar {
  height: 68px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  gap: 26px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}
.brand-wrap { margin-right: auto; }
.brand { font-weight: 750; text-decoration: none; letter-spacing: .02em; }
.brand-note { margin-left: 10px; color: var(--muted); font-size: 12px; }
.main-nav { display: flex; align-items: center; gap: 6px; }
.main-nav a {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}
.main-nav a:hover, .main-nav a.active { color: var(--green-dark); background: var(--green-soft); }
.shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 72px; }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; }
h1 { font-size: clamp(28px, 4vw, 44px); margin: 5px 0 10px; letter-spacing: -.04em; }
h2 { font-size: 18px; margin-top: 32px; }
p { color: var(--muted); }
.eyebrow { color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.sync-state { padding: 9px 13px; border: 1px solid #cbe2d3; border-radius: 999px; color: var(--green-dark); background: var(--green-soft); font-size: 13px; white-space: nowrap; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #31a66b; margin-right: 6px; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 28px 0 18px; }
.metrics article { padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); }
.metrics span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 9px; }
.metrics strong { font-size: 26px; }
.metrics strong.small { font-size: 14px; }
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.field { min-width: 132px; }
.field.grow { flex: 1; min-width: 220px; }
label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 650; }
input, select {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid #d8ded9;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus { outline: 2px solid #aad4bc; border-color: var(--green); }
button, .primary, .secondary {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.primary { border: 1px solid var(--green); color: #fff; background: var(--green); }
.primary:hover { background: var(--green-dark); }
.primary.inline { min-height: 36px; }
.primary.compact, .secondary.compact { min-height: 34px; padding: 0 12px; font-size: 12px; }
.secondary { border: 1px solid var(--line); background: #fff; }
.link-button { border: 0; background: transparent; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: 18px 0; }
.search-form { flex: 1; display: flex; gap: 10px; }
.search-form input { flex: 1; }
.with-count { gap: 8px; white-space: nowrap; }
.with-count span { min-width: 24px; height: 24px; display: grid; place-items: center; padding: 0 6px; border-radius: 999px; color: var(--green-dark); background: var(--green-soft); font-size: 11px; }
.archive-list { margin-top: 18px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--paper); }
.list-heading { padding: 14px 18px; display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }
.message-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 14px; padding: 18px; text-decoration: none; border-bottom: 1px solid var(--line); }
.message-row:last-child { border-bottom: 0; }
.message-row:hover { background: #fafcfb; }
.avatar { width: 40px; height: 40px; display: grid; place-items: center; color: var(--green-dark); background: var(--green-soft); border-radius: 11px; font-weight: 800; }
.message-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.message-meta strong { color: var(--ink); font-size: 14px; }
.message-main p { margin: 8px 0 0; line-height: 1.55; font-size: 14px; overflow-wrap: anywhere; }
.type-pill, .media-badge, .room-pill { padding: 3px 7px; border-radius: 999px; background: #eef1ef; color: #59625c; font-size: 11px; }
.message-time { text-align: right; color: var(--muted); font-size: 12px; white-space: nowrap; }
.message-time .media-badge { display: inline-block; margin-top: 9px; }
.empty { padding: 70px 20px; text-align: center; }
.pagination { display: flex; justify-content: center; gap: 10px; margin-top: 22px; }
.pagination a, .back-link { color: var(--green-dark); font-weight: 700; text-decoration: none; }
.login-card { width: min(460px, 100%); margin: 8vh auto; padding: 38px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: var(--shadow); }
.login-card h1 { font-size: 34px; }
.login-form { margin-top: 30px; }
.login-form .primary { width: 100%; margin-top: 14px; }
.flash { width: min(460px, 100%); margin: 0 auto 14px; padding: 12px 14px; border-radius: 8px; }
.flash.error { color: #8d2d2d; background: #fae9e9; }
.flash.success { color: var(--green-dark); background: var(--green-soft); }
.detail-card { margin-top: 18px; padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); }
.detail-header { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.detail-header h1 { font-size: 30px; }
.detail-grid { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 12px; margin: 26px 0; }
.detail-grid div { padding: 14px; background: var(--canvas); border-radius: 10px; overflow-wrap: anywhere; }
dt { color: var(--muted); font-size: 11px; margin-bottom: 7px; }
dd { margin: 0; font-size: 13px; }
.json { padding: 18px; max-height: 560px; overflow: auto; color: #dbe8df; background: #17211a; border-radius: 12px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.media-panel { padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--canvas); }
.media-panel img, .media-panel video { max-width: 100%; max-height: 560px; border-radius: 8px; }
.media-panel audio { width: 100%; }

.conversation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.conversation-card {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: inherit;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(32, 57, 42, .045);
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.conversation-card:hover { transform: translateY(-2px); border-color: #bad5c4; box-shadow: var(--shadow); }
.card-topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.card-topline > time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.customer-identity { min-width: 0; display: flex; align-items: center; gap: 12px; }
.customer-avatar { flex: 0 0 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; color: #fff; background: linear-gradient(145deg, var(--green), #42a273); font-weight: 800; }
.customer-identity h2 { margin: 0 0 4px; color: var(--ink); font-size: 17px; overflow-wrap: anywhere; }
.customer-identity p { margin: 0; font-size: 12px; line-height: 1.45; }
.requirement-brief { min-height: 82px; margin: 20px 0 13px; padding: 14px; border-radius: 12px; background: #f6f8f6; }
.brief-label { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.requirement-brief p { margin: 7px 0 0; color: var(--ink); font-size: 13px; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.spec-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.spec-chips span, .direction-pill { padding: 4px 8px; border-radius: 999px; color: #3f5e4a; background: var(--green-soft); font-size: 11px; }
.spec-chips .muted-chip { color: var(--muted); background: #eef1ef; }
.customer-note { margin: 13px 0 0; padding: 9px 11px; border-left: 3px solid #b8d8c4; color: var(--muted); background: #fbfcfb; font-size: 12px; }
.card-footer { display: grid; grid-template-columns: auto auto 1fr auto; gap: 9px; align-items: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.card-footer .file-count { color: var(--green-dark); font-weight: 750; }
.card-footer .latest-preview { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-footer strong { color: var(--green-dark); white-space: nowrap; }
.wide { grid-column: 1 / -1; }

.customer-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-top: 16px; }
.customer-header h1 { margin-bottom: 6px; }
.customer-header p { margin: 0; }
.profile-editor { margin-top: 18px; border: 1px solid var(--line); border-radius: 13px; background: var(--paper); }
.profile-editor summary { padding: 13px 16px; color: var(--green-dark); cursor: pointer; font-size: 13px; font-weight: 750; }
.profile-editor form { display: flex; gap: 10px; align-items: flex-end; padding: 0 16px 16px; }
.profile-editor .field:first-of-type { width: min(260px, 35%); }
.auto-name-hint { max-width: 210px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.summary-panel { margin-top: 20px; padding: 24px; border-radius: 18px; color: #fff; background: linear-gradient(135deg, #153e2a, #1f7049); box-shadow: 0 18px 45px rgba(20, 70, 43, .16); }
.summary-panel h2 { margin: 4px 0 0; color: #fff; }
.summary-panel .eyebrow { color: #9ce1ba; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.section-title h2 { margin: 4px 0 0; }
.summary-note { color: #c7dfd0; font-size: 11px; }
.summary-overview { margin: 22px 0; color: #fff; font-size: 16px; font-weight: 650; line-height: 1.75; }
.requirements-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; }
.requirements-grid div { min-width: 0; padding: 12px; border: 1px solid rgba(255,255,255,.14); border-radius: 11px; background: rgba(255,255,255,.07); }
.requirements-grid dt { color: #b7dbc5; }
.requirements-grid dd { color: #fff; line-height: 1.45; overflow-wrap: anywhere; }
.section-block { margin-top: 30px; }

.file-list { margin-top: 14px; border: 1px solid var(--line); border-radius: 15px; overflow: hidden; background: var(--paper); }
.file-list.standalone { margin-top: 18px; box-shadow: var(--shadow); }
.file-row { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 15px; align-items: start; padding: 18px; border-bottom: 1px solid var(--line); }
.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: #fbfcfb; }
.file-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 12px; color: #845f2a; background: #f9efdc; font-size: 10px; font-weight: 850; }
.file-main { min-width: 0; }
.file-main > strong, .file-title-line strong { display: block; color: var(--ink); overflow-wrap: anywhere; font-size: 14px; line-height: 1.45; }
.file-main > span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.file-main > p { margin: 9px 0; color: #425049; font-size: 12px; line-height: 1.55; }
.file-title-line { display: flex; align-items: flex-start; gap: 9px; }
.direction-pill { flex: 0 0 auto; }
.file-meta { min-width: 152px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; color: var(--muted); font-size: 11px; }
.file-meta .primary { white-space: nowrap; }
.customer-link { max-width: 180px; color: var(--green-dark); font-weight: 750; text-align: right; text-decoration: none; overflow-wrap: anywhere; }
.compact-list .file-main > p { margin-bottom: 0; }
.file-filters { margin-top: 24px; }
.customer-select { min-width: 280px; }
.empty.slim { padding: 32px 20px; }

.chat-timeline { margin-top: 14px; padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: #eaf0eb; }
.chat-message { width: min(72%, 720px); margin-bottom: 14px; padding: 13px 15px; border-radius: 6px 16px 16px 16px; background: #fff; box-shadow: 0 5px 15px rgba(22, 54, 35, .05); }
.chat-message.outgoing { margin-left: auto; border-radius: 16px 6px 16px 16px; background: #dff2e6; }
.chat-meta { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 8px; color: var(--muted); font-size: 10px; }
.chat-meta strong { color: var(--green-dark); }
.chat-message > p { margin: 0; color: var(--ink); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.raw-link { display: inline-block; margin-top: 8px; color: #7a847d; font-size: 10px; text-decoration: none; }
.chat-file { display: grid; gap: 5px; padding: 11px; border: 1px solid rgba(31,122,77,.18); border-radius: 10px; background: rgba(255,255,255,.68); }
.chat-file > span { color: var(--green); font-size: 10px; font-weight: 800; }
.chat-file strong, .chat-file small { overflow-wrap: anywhere; }
.chat-file small { color: var(--muted); }
.chat-file a { color: var(--green-dark); font-size: 12px; font-weight: 750; }
.chat-image-link { display: block; }
.chat-image-link img { display: block; max-width: min(100%, 360px); max-height: 320px; border-radius: 9px; }

@media (max-width: 820px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .message-row { grid-template-columns: 40px 1fr; }
  .message-time { grid-column: 2; text-align: left; }
  .detail-grid { grid-template-columns: 1fr; }
  .conversation-grid { grid-template-columns: 1fr; }
  .requirements-grid { grid-template-columns: repeat(2, 1fr); }
  .file-row { grid-template-columns: 42px minmax(0, 1fr); }
  .file-icon { width: 42px; height: 42px; }
  .file-meta { grid-column: 2; min-width: 0; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .chat-message { width: 86%; }
}

@media (max-width: 520px) {
  .shell { width: min(100% - 24px, 1180px); padding-top: 28px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics article { padding: 14px; }
  .login-card { padding: 26px; }
  .topbar { height: auto; min-height: 62px; padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .brand-note { display: none; }
  .main-nav { order: 3; width: 100%; }
  .main-nav a { flex: 1; text-align: center; }
  .toolbar, .search-form, .profile-editor form, .section-title { align-items: stretch; flex-direction: column; }
  .profile-editor .field:first-of-type { width: 100%; }
  .card-footer { grid-template-columns: auto auto 1fr; }
  .card-footer strong { grid-column: 1 / -1; }
  .requirements-grid { grid-template-columns: 1fr; }
  .summary-panel { padding: 19px; }
  .customer-select { min-width: 100%; }
  .chat-timeline { padding: 12px; }
  .chat-message { width: 94%; }
}
