:root {
  color-scheme: light;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --canvas: #f5f8fc;
  --card: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #dfe6ef;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --green: #15803d;
  --green-soft: #f0fdf4;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--canvas); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 15% 18%, rgba(37, 99, 235, .12), transparent 30%),
    radial-gradient(circle at 85% 82%, rgba(59, 130, 246, .1), transparent 28%),
    #f7faff;
}

.login-card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid rgba(210, 220, 233, .8);
  border-radius: 24px;
  padding: 38px;
  box-shadow: 0 24px 70px rgba(30, 64, 175, .12);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-login { margin-bottom: 28px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.logo {
  width: 46px; height: 46px; border-radius: 15px; flex: 0 0 auto;
  display: grid; place-items: center; position: relative;
  color: white; background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  box-shadow: 0 10px 24px rgba(37, 99, 235, .25);
}
.logo i {
  width: 23px; height: 16px; border-radius: 9px; background: white;
  position: absolute; left: 9px; bottom: 10px;
}
.logo i::after {
  content: ""; position: absolute; left: 4px; bottom: -4px;
  width: 7px; height: 7px; background: white; transform: rotate(45deg);
}
.logo b { position: absolute; right: 6px; top: 4px; font-size: 14px; }
.eyebrow, .kicker {
  margin: 0 0 5px; color: var(--blue); text-transform: uppercase;
  font-size: 12px; font-weight: 800; letter-spacing: .08em;
}
.login-intro { margin: 0 0 26px; color: var(--muted); line-height: 1.7; }
.login-form, .admin-form { display: grid; gap: 18px; }
label { display: grid; gap: 8px; }
label > span { font-size: 14px; font-weight: 700; }
input, textarea {
  width: 100%; border: 1px solid #cad5e3; border-radius: 12px;
  background: white; color: var(--ink); outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input { min-height: 48px; padding: 0 14px; }
textarea { padding: 14px; resize: vertical; }
input:focus, textarea:focus {
  border-color: var(--blue); box-shadow: 0 0 0 4px rgba(37, 99, 235, .1);
}
.form-error { color: var(--red); margin: -6px 0 0; font-size: 13px; }
.form-success {
  margin: -6px 0 0; padding: 11px 13px; border: 1px solid #bbf7d0;
  border-radius: 11px; color: #166534; background: var(--green-soft);
  font-size: 13px; font-weight: 700; line-height: 1.5;
}
.privacy-note {
  display: flex; gap: 9px; align-items: center; justify-content: center;
  margin-top: 24px; color: var(--muted); font-size: 13px;
}
.privacy-note span:first-child {
  display: grid; place-items: center; width: 20px; height: 20px;
  border-radius: 50%; color: var(--green); background: var(--green-soft); font-weight: 900;
}

.button {
  min-height: 44px; border: 1px solid transparent; border-radius: 11px;
  padding: 0 17px; font-weight: 750; transition: .18s ease;
}
.button:disabled { opacity: .55; cursor: wait; }
.button.primary { color: white; background: var(--blue); }
.button.primary:hover { background: var(--blue-dark); }
.button.ghost { color: #475467; border-color: var(--line); background: white; }
.button.ghost:hover { border-color: #a9bad0; background: #f8fafc; }
.button.danger { color: white; background: var(--red); }
.button.danger-outline { color: var(--red); background: white; border-color: #fecaca; }
.button.wide { width: 100%; }
.button.small { min-height: 36px; padding: 0 12px; font-size: 13px; }

.app-page { min-height: 100vh; padding-bottom: max(32px, env(safe-area-inset-bottom)); }
.app-header {
  min-height: 78px; display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 14px max(24px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,.94);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px);
}
.account { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: var(--blue-soft); color: var(--blue); font-weight: 900;
}
.account-copy { display: grid; min-width: 94px; }
.account-copy strong { font-size: 14px; }
.account-copy small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.admin-nav {
  display: flex; gap: 7px; padding: 12px max(24px, calc((100vw - 1240px) / 2));
  border-bottom: 1px solid var(--line); background: white;
}
.nav-button {
  border: 0; border-radius: 9px; padding: 9px 15px;
  background: transparent; color: var(--muted); font-weight: 750;
}
.nav-button.active { color: var(--blue); background: var(--blue-soft); }
.page-shell { width: min(1240px, calc(100% - 48px)); margin: 28px auto 0; }
.workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px; box-shadow: 0 8px 28px rgba(28, 48, 78, .055);
}
.section-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 19px;
}
.section-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.private-badge {
  white-space: nowrap; padding: 6px 9px; border-radius: 999px;
  color: var(--green); background: var(--green-soft); font-size: 12px; font-weight: 800;
}
.message-box { position: relative; }
.message-box textarea { min-height: 214px; padding-bottom: 36px; line-height: 1.65; }
.message-box small {
  position: absolute; right: 12px; bottom: 10px; color: var(--muted);
}
.generate { width: 100%; margin-top: 16px; display: flex; justify-content: center; gap: 8px; align-items: center; }
.helper { margin: 12px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
.result-card { min-height: 425px; }
.empty-result {
  min-height: 375px; display: grid; place-content: center; justify-items: center;
  text-align: center; color: var(--muted);
}
.empty-icon {
  width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center;
  margin-bottom: 17px; color: var(--blue); background: var(--blue-soft); font-size: 25px;
}
.empty-result h2 { margin: 0; color: #344054; font-size: 18px; }
.empty-result p { margin: 9px 0 0; max-width: 300px; font-size: 13px; line-height: 1.6; }
.risk-badge {
  white-space: nowrap; padding: 6px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 850;
}
.risk-badge.low { color: var(--green); background: var(--green-soft); }
.risk-badge.medium { color: var(--amber); background: var(--amber-soft); }
.risk-badge.high { color: var(--red); background: var(--red-soft); }
.reply-text {
  min-height: 144px; padding: 18px; border: 1px solid #bfdbfe;
  border-radius: 14px; background: #f8fbff; line-height: 1.75; white-space: pre-wrap;
}
.result-actions { display: flex; gap: 10px; margin-top: 14px; }
.reason-box {
  margin-top: 15px; padding: 13px 15px; border-radius: 12px;
  background: #f8fafc; color: var(--muted); font-size: 12px; line-height: 1.55;
}
.reason-box strong { color: #344054; }
.reason-box p { margin: 4px 0 0; }
.history-card { margin-top: 22px; }
.records-list, .users-list, .escalations-list { display: grid; gap: 11px; }
.empty-list {
  padding: 26px; border: 1px dashed #cdd8e6; border-radius: 13px;
  text-align: center; color: var(--muted); font-size: 13px;
}
.record {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px; padding: 15px 16px; border: 1px solid #e7ecf3; border-radius: 13px;
}
.record-main { min-width: 0; }
.record-title { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 750; }
.record-reply {
  margin: 7px 0 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--muted); font-size: 13px;
}
.record-meta { display: grid; justify-items: end; align-content: space-between; gap: 8px; }
.record-meta time { color: var(--muted); font-size: 11px; }
.record-owner { color: var(--blue); font-size: 12px; font-weight: 800; }

.admin-grid { display: grid; grid-template-columns: minmax(300px, .7fr) minmax(420px, 1.3fr); gap: 22px; }
.admin-form input { min-height: 45px; }
.user-row, .escalation {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 13px 14px; border: 1px solid #e7ecf3; border-radius: 12px;
}
.user-copy { min-width: 0; display: grid; gap: 3px; }
.user-copy strong { overflow: hidden; text-overflow: ellipsis; }
.user-copy small { color: var(--muted); }
.status {
  padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800;
}
.status.active { color: var(--green); background: var(--green-soft); }
.status.inactive { color: var(--muted); background: #f2f4f7; }
.summary-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 22px; }
.metric { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 28px; }
.escalations-list { margin-bottom: 22px; }
.escalation { align-items: flex-start; border-color: #fecaca; background: var(--red-soft); }
.escalation p { margin: 4px 0 0; color: #7f1d1d; font-size: 13px; }
.escalation small { color: #991b1b; }
.admin-records { max-height: 640px; overflow: auto; }

.toast {
  position: fixed; left: 50%; bottom: 30px; z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 11px 16px; border-radius: 10px; color: white; background: #172033;
  box-shadow: 0 12px 34px rgba(15,23,42,.24); transition: .2s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
dialog { border: 0; padding: 0; border-radius: 18px; box-shadow: 0 28px 80px rgba(15,23,42,.24); }
dialog::backdrop { background: rgba(15,23,42,.45); backdrop-filter: blur(3px); }
.dialog-card { width: min(520px, calc(100vw - 32px)); padding: 25px; }
.dialog-card h2 { margin: 0; }
.dialog-card p:not(.kicker) { color: var(--muted); line-height: 1.6; }
.dialog-card textarea { min-height: 100px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.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;
}

@media (max-width: 900px) {
  .workspace, .admin-grid { grid-template-columns: 1fr; }
  .page-shell { width: min(760px, calc(100% - 32px)); margin-top: 20px; }
  .result-card { min-height: 360px; }
  .empty-result { min-height: 310px; }
}

@media (max-width: 640px) {
  .login-page { padding: 18px 14px; place-items: center; }
  .login-card { padding: 26px 20px; border-radius: 20px; }
  .app-header { min-height: 68px; padding: 11px 14px; }
  .app-header .brand p, .account-copy small { display: none; }
  .app-header .brand h1 { font-size: 17px; }
  .logo { width: 39px; height: 39px; border-radius: 12px; }
  .account { gap: 7px; }
  .avatar { width: 34px; height: 34px; }
  .account-copy { min-width: 0; max-width: 68px; }
  .account-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .admin-nav {
    overflow-x: auto; padding: 9px 14px; position: sticky; top: 68px; z-index: 9;
  }
  .nav-button { flex: 0 0 auto; min-height: 40px; }
  .page-shell { width: calc(100% - 24px); margin-top: 12px; }
  .card { padding: 18px 15px; border-radius: 15px; }
  .section-head h2 { font-size: 17px; }
  .private-badge { font-size: 10px; }
  .message-box textarea { min-height: 180px; }
  .button { min-height: 46px; }
  .button.small { min-height: 38px; }
  .dialog-card { width: calc(100vw - 24px); padding: 22px 18px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dialog-actions .button { width: 100%; }
  .result-card { min-height: 330px; }
  .empty-result { min-height: 280px; }
  .result-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .record { grid-template-columns: minmax(0, 1fr); }
  .record-meta { display: flex; justify-content: space-between; }
  .summary-row { grid-template-columns: 1fr; gap: 9px; }
  .metric { padding: 15px; display: flex; align-items: center; justify-content: space-between; }
  .metric strong { margin: 0; font-size: 23px; }
  .user-row, .escalation { align-items: stretch; flex-direction: column; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; }
}
