:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #151b2d;
  --muted: #667085;
  --line: #e1e6ee;
  --primary: #d92d20;
  --primary-2: #b42318;
  --primary-soft: #fff1f1;
  --teal: #18794e;
  --rose: #c3262f;
  --amber: #b7791f;
  --charcoal: #172033;
  --shadow: 0 18px 46px rgba(31, 41, 55, 0.10);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 1.05fr) minmax(360px, 0.95fr);
  background: #f5f6f8;
}

.login-art {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(140deg, rgba(116, 16, 18, 0.92), rgba(18, 27, 44, 0.9)),
    url("/assets/mofa-shield-logo.jpg") center/cover;
}

.login-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(116, 16, 18, 0.35), rgba(9, 14, 25, 0.78)),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.06) 0 1px, transparent 1px 18px);
}

.login-orbit {
  position: relative;
  z-index: 1;
  min-height: 100%;
}

.panel-card {
  position: absolute;
  width: min(340px, 42vw);
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  padding: 22px;
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
}

.panel-card span,
.panel-card strong {
  display: block;
}

.panel-card span {
  opacity: 0.8;
  margin-bottom: 10px;
}

.panel-card strong {
  font-size: 24px;
}

.floating.one {
  top: 16%;
  left: 12%;
}

.floating.two {
  top: 42%;
  right: 12%;
}

.floating.three {
  bottom: 14%;
  left: 18%;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 48px;
}

.login-card {
  width: min(430px, 100%);
}

.mini-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
}

.mini-brand img,
.brand-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
  object-position: center;
  border-radius: 8px;
  background: #060606;
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.12);
}

.login-card h1 {
  margin: 34px 0 12px;
  font-size: 40px;
  line-height: 1.12;
}

.login-card p {
  color: var(--muted);
  margin: 0 0 32px;
}

.form-stack,
.agent-form,
.compact-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(217, 45, 32, 0.56);
  box-shadow: 0 0 0 4px rgba(217, 45, 32, 0.10);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.text-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  padding: 0 18px;
  box-shadow: 0 12px 24px rgba(217, 45, 32, 0.22);
}

.primary-button:hover {
  background: var(--primary-2);
}

.primary-button:disabled {
  opacity: 0.55;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 16px;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
  padding: 0 14px;
}

.text-button {
  min-height: auto;
  background: transparent;
  color: var(--primary);
  padding: 4px 6px;
}

.icon-button {
  width: 36px;
  height: 36px;
  background: var(--surface-2);
  color: var(--primary);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
  cursor: pointer;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

.brand strong,
.brand span,
.account strong,
.account span {
  display: block;
}

.brand span,
.account span,
.topbar span,
.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 8px;
  margin-top: 30px;
}

.side-nav button {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  text-align: left;
}

.side-nav button.active,
.side-nav button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-icon {
  width: 22px;
  text-align: center;
}

.account {
  display: grid;
  grid-template-columns: 38px 1fr 36px;
  align-items: center;
  gap: 10px;
  padding: 12px 6px 0;
  border-top: 1px solid var(--line);
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 900;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 246, 248, 0.92);
  backdrop-filter: blur(18px);
  padding: 0 32px;
}

.topbar strong,
.topbar span {
  display: block;
}

.hero-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  margin: 28px 32px 20px;
  padding: 34px;
  border-radius: var(--radius);
  background:
    linear-gradient(105deg, rgba(255,255,255,0.98), rgba(255,246,246,0.9)),
    linear-gradient(135deg, rgba(217,45,32,0.13), rgba(23,32,51,0.05));
  border: 1px solid rgba(225, 230, 238, 0.9);
  box-shadow: var(--shadow);
}

.eyebrow {
  display: inline-block;
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.hero-band h1 {
  margin: 0;
  max-width: 760px;
  font-size: 38px;
  line-height: 1.16;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(2, 150px);
  gap: 12px;
}

.hero-metrics div,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.9);
  padding: 18px;
}

.hero-metrics strong,
.hero-metrics span,
.metric strong,
.metric span {
  display: block;
}

.hero-metrics strong,
.metric strong {
  font-size: 24px;
}

.hero-metrics span,
.metric span {
  color: var(--muted);
  margin-top: 6px;
  font-size: 12px;
}

.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
  padding: 0 32px 32px;
}

.agent-card,
.admin-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 34px rgba(31, 41, 55, 0.07);
}

.agent-card {
  min-height: 238px;
  display: grid;
  align-content: space-between;
  gap: 16px;
  padding: 20px;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.agent-card:hover {
  transform: translateY(-2px);
  border-color: rgba(217, 45, 32, 0.28);
  box-shadow: 0 18px 42px rgba(31, 41, 55, 0.11);
}

.card-top,
.section-head,
.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.agent-badge,
.sort,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 900;
}

.agent-badge {
  background: var(--primary-soft);
  color: var(--primary);
}

.sort {
  background: #f5ecdc;
  color: var(--amber);
}

.agent-card h3 {
  margin: 2px 0 0;
  font-size: 22px;
}

.agent-card p {
  min-height: 72px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.chat-shell {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr);
}

.conversation-rail {
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 18px;
  overflow: auto;
}

.full {
  width: 100%;
}

.conversation-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.conversation-item {
  width: 100%;
  min-height: 68px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 12px;
  text-align: left;
}

.conversation-item strong,
.conversation-item span {
  display: block;
}

.conversation-item span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 7px;
}

.conversation-item.active,
.conversation-item:hover {
  border-color: var(--line);
  background: #fff7f7;
}

.chat-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: #f6f7f9;
}

.messages {
  overflow: auto;
  padding: 28px;
}

.empty-chat {
  max-width: 760px;
  margin: 18vh auto 0;
  text-align: center;
}

.empty-chat span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 0 12px;
  font-weight: 900;
}

.empty-chat h2 {
  margin: 20px 0 0;
  font-size: 28px;
  line-height: 1.35;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 820px);
  gap: 12px;
  margin: 0 auto 18px;
  max-width: 920px;
}

.message.user {
  grid-template-columns: minmax(0, 820px) 42px;
}

.message.user .message-avatar {
  grid-column: 2;
  background: var(--primary-soft);
  color: var(--primary);
}

.message.user .message-body {
  grid-column: 1;
  grid-row: 1;
  background: #fff7f7;
}

.message-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f2f4f7;
  color: var(--charcoal);
  font-size: 12px;
  font-weight: 900;
}

.message-body {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px 16px;
  box-shadow: 0 8px 22px rgba(22, 32, 51, 0.05);
}

.message-body pre {
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
  font-family: inherit;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.96);
  padding: 16px 28px;
}

.composer textarea {
  min-height: 54px;
  max-height: 180px;
}

.admin-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 16px;
  padding: 28px 32px 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding: 18px 32px 32px;
}

.admin-card {
  padding: 20px;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.admin-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), rgba(217, 45, 32, 0));
}

.admin-card.wide {
  grid-column: 1 / -1;
}

.section-head {
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 18px;
}

.agent-form {
  grid-template-columns: minmax(120px, 0.75fr) minmax(150px, 1fr) minmax(190px, 1.15fr) 110px 78px 116px;
  align-items: start;
}

.agent-form textarea {
  min-height: 44px;
  height: 44px;
}

.agent-form.editing {
  grid-template-columns: minmax(220px, 1fr) 150px 120px 150px 100px;
  gap: 14px;
  background: #fff7f7;
  border: 1px solid #ffd5d2;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.agent-form.editing textarea {
  grid-column: 1 / -1;
  width: 100%;
  height: auto;
}

.agent-form.editing textarea[name="guide_text"] {
  min-height: 96px;
}

.agent-form.editing textarea[name="system_prompt"] {
  min-height: 220px;
  line-height: 1.7;
}

.agent-form.editing .primary-button,
.agent-form.editing .secondary-button {
  min-height: 48px;
}

.row-actions {
  white-space: nowrap;
}

.compact-form {
  grid-template-columns: 1fr 1fr 94px 76px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.small {
  max-height: 300px;
}

.cost-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.cost-strip div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff7f7;
  padding: 12px 14px;
}

.cost-strip span,
.cost-strip strong {
  display: block;
}

.cost-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.cost-strip strong {
  margin-top: 6px;
  font-size: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #fafbfc;
  color: var(--muted);
  font-size: 12px;
}

tbody tr:hover {
  background: #fffafa;
}

td span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 5px;
}

td input,
td select {
  max-width: 140px;
}

.status.success {
  background: #ecfdf3;
  color: var(--teal);
}

.status.error {
  background: #fff1f1;
  color: var(--rose);
}

.empty-state {
  margin: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 32px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: 8px;
  background: var(--charcoal);
  color: #fff;
  padding: 13px 16px;
  box-shadow: var(--shadow);
  transition: opacity 0.18s, transform 0.18s;
  z-index: 10;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1040px) {
  .login-page,
  .shell,
  .chat-shell,
  .hero-band,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .login-art {
    min-height: 320px;
  }

  .sidebar {
    position: static;
    height: auto;
    grid-template-columns: 1fr;
  }

  .chat-shell {
    height: auto;
  }

  .conversation-rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(220px, 1fr);
    overflow-x: auto;
  }

  .admin-overview {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .agent-form,
  .compact-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .login-panel,
  .topbar,
  .hero-band,
  .messages,
  .composer,
  .admin-overview,
  .admin-grid,
  .agent-grid {
    padding-left: 18px;
    padding-right: 18px;
  }

  .hero-band {
    margin-left: 18px;
    margin-right: 18px;
  }

  .hero-band h1 {
    font-size: 30px;
  }

  .hero-metrics {
    grid-template-columns: 1fr;
  }

  .composer,
  .message,
  .message.user {
    grid-template-columns: 1fr;
  }

  .message-avatar {
    display: none;
  }

  .message.user .message-body {
    grid-column: auto;
  }

  .admin-overview {
    grid-template-columns: 1fr;
  }

  .cost-strip {
    grid-template-columns: 1fr;
  }
}
