:root {
  --ink: #142321;
  --muted: #667875;
  --soft: #eef3f1;
  --line: #d9e3df;
  --surface: #ffffff;
  --canvas: #f4f7f5;
  --brand: #0f7166;
  --brand-deep: #0a574f;
  --brand-soft: #e4f2ee;
  --blue: #2266a5;
  --blue-soft: #eaf2fa;
  --amber: #a9610a;
  --amber-soft: #fff2dc;
  --red: #b54136;
  --red-soft: #fcedea;
  --violet: #7354a4;
  --violet-soft: #f1ecf9;
  --shadow: 0 8px 28px rgba(34, 61, 56, 0.08);
  --radius: 16px;
  --sidebar: 264px;
  --topbar: 72px;
  --font: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 113, 102, 0.24);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 42%) minmax(480px, 58%);
  background: var(--surface);
}

.auth-story {
  padding: clamp(42px, 7vw, 92px);
  background: linear-gradient(145deg, #0b514a, #0f7166 62%, #168777);
  color: #fff;
}

.auth-mark {
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 26px;
  font-weight: 800;
}

.auth-kicker {
  margin: 56px 0 10px;
  color: #bce5db;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.auth-story h1 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(34px, 4vw, 58px);
  line-height: 1.15;
  letter-spacing: -0.035em;
}

.auth-story > p {
  max-width: 620px;
  margin: 22px 0 0;
  color: #d9f0eb;
  font-size: 17px;
  line-height: 1.9;
}

.auth-values {
  max-width: 620px;
  margin: 48px 0 0;
  padding: 0;
  list-style: none;
}

.auth-values li {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.auth-values strong {
  display: block;
  margin-bottom: 3px;
}

.auth-values span {
  color: #c8e9e1;
}

.auth-form-wrap {
  padding: clamp(42px, 8vw, 112px);
  background: #fbfcfb;
}

.auth-form {
  width: min(100%, 520px);
}

.auth-form h2 {
  margin: 0 0 10px;
  font-size: 30px;
  line-height: 1.25;
}

.auth-form > p {
  margin: 0 0 34px;
  color: var(--muted);
  font-size: 15px;
}

.setup-note,
.inline-note,
.environment-banner,
.callout {
  border-radius: 12px;
  padding: 14px 16px;
}

.setup-note {
  margin-bottom: 20px;
  background: var(--amber-soft);
  color: #74430a;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.field label,
.field-label {
  font-weight: 700;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
}

.control {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.control:hover,
.control:focus {
  border-color: #91bdb4;
  box-shadow: 0 0 0 3px rgba(15, 113, 102, 0.08);
}

textarea.control {
  min-height: 112px;
  resize: vertical;
}

textarea.control-tall {
  min-height: 260px;
}

.check-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
}

.check-row span {
  display: grid;
  gap: 4px;
}

.check-row small {
  color: var(--muted);
  line-height: 1.55;
}

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  transition: background 0.16s, border-color 0.16s, color 0.16s, transform 0.16s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--brand-deep);
}

.btn-secondary {
  border-color: #b6cec8;
  background: var(--surface);
  color: var(--brand-deep);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--brand-deep);
}

.btn-danger {
  border-color: #e7b8b2;
  background: var(--red-soft);
  color: var(--red);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.form-error {
  margin: 0 0 16px;
  border-left: 3px solid var(--red);
  background: var(--red-soft);
  padding: 10px 12px;
  color: #7f2c24;
}

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar);
  overflow-y: auto;
  border-right: 1px solid #153f3a;
  background: #0d403a;
  color: #dcece8;
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  padding: 20px 20px 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: #e4f2ee;
  color: var(--brand-deep);
  font-size: 20px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 1px;
  color: #a9ccc4;
}

.nav-section {
  padding: 8px 12px;
}

.nav-section-title {
  margin: 0 10px 7px;
  color: #81aaa1;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.nav-link {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-radius: 9px;
  padding: 9px 10px;
  color: #d7e8e4;
  cursor: pointer;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.nav-link.active {
  box-shadow: inset 3px 0 0 #74d0c0;
}

.nav-icon,
.topbar-icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.main-column {
  min-width: 0;
  grid-column: 2;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  min-height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  padding: 12px 28px;
  backdrop-filter: blur(12px);
}

.topbar-context {
  min-width: 0;
}

.topbar-context strong,
.topbar-context small {
  display: block;
}

.topbar-context small {
  color: var(--muted);
}

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

.env-chip,
.user-chip {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 7px 10px;
}

.user-chip,
.user-copy {
  text-align: left;
}

.env-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3aa476;
}

.user-avatar {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-weight: 900;
}

.customer-identity,
.customer-profile-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.customer-profile-summary {
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.customer-profile-summary .customer-identity {
  flex: 1;
}

.customer-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: block;
  border-radius: 12px;
  object-fit: cover;
  background: var(--brand-soft);
}

.customer-avatar-lg {
  width: 64px;
  height: 64px;
  flex-basis: 64px;
  border-radius: 18px;
}

.customer-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-deep);
  font-weight: 900;
}

.user-profile-meta {
  margin-top: 7px;
}

.main-content {
  padding: 28px;
}

.page-container {
  width: 100%;
  max-width: 1500px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.page-eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.page-header h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.page-header p {
  max-width: 820px;
  margin: 7px 0 0;
  color: var(--muted);
}

.page-actions,
.toolbar,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.environment-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 18px;
  background: var(--blue-soft);
  color: #234e75;
}

.environment-banner.warning {
  background: var(--amber-soft);
  color: #74430a;
}

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

.metric-card,
.card,
.panel,
.table-card,
.empty-state,
.error-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 128px;
  padding: 18px;
}

.metric-label {
  color: var(--muted);
  font-weight: 700;
}

.metric-value {
  margin-top: 12px;
  font-size: 31px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.metric-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.dashboard-grid,
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 1fr);
  gap: 18px;
}

.card,
.panel {
  padding: 20px;
}

.card-header,
.panel-header,
.detail-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.card-header h2,
.panel-header h2,
.detail-section-header h2,
.card h3 {
  margin: 0;
  line-height: 1.3;
}

.card-header p,
.panel-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

.compact-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.compact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}

.compact-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.compact-row strong,
.compact-row span {
  display: block;
}

.compact-row span,
.secondary-text {
  color: var(--muted);
}

.attention-number {
  min-width: 34px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 800;
}

.toolbar {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px;
}

.toolbar .control {
  width: auto;
  min-width: 160px;
}

.toolbar .search-control {
  min-width: min(100%, 300px);
  flex: 1;
}

.table-card {
  overflow: hidden;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

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

th {
  background: #f7f9f8;
  color: #52635f;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

tbody tr:hover {
  background: #f8fbfa;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.cell-title {
  font-weight: 750;
}

.cell-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--soft);
  color: #52635f;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status.success,
.status.active,
.status.ready,
.status.member,
.status.resolved,
.status.paid,
.status.paid_tokens,
.status.healthy {
  background: var(--brand-soft);
  color: var(--brand-deep);
}

.status.warning,
.status.pending,
.status.processing,
.status.review,
.status.payment_review,
.status.attention,
.status.refund_query_required,
.status.needs_prompt_review {
  background: var(--amber-soft);
  color: var(--amber);
}

.status.danger,
.status.failed,
.status.blocked,
.status.disabled,
.status.deletion_pending {
  background: var(--red-soft);
  color: var(--red);
}

.status.info,
.status.admin,
.status.free {
  background: var(--blue-soft);
  color: var(--blue);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  color: var(--muted);
}

.empty-state,
.error-state {
  padding: 28px;
}

.empty-state h2,
.error-state h2 {
  margin: 0 0 8px;
}

.empty-state p,
.error-state p {
  margin: 0 0 18px;
  color: var(--muted);
}

.skeleton {
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, #edf2f0 25%, #f7f9f8 50%, #edf2f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
}

.breadcrumbs a {
  color: var(--brand);
  font-weight: 700;
}

.definition-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}

.definition-item {
  min-height: 88px;
  background: var(--surface);
  padding: 14px;
}

.definition-item dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.definition-item dd {
  margin: 7px 0 0;
  font-weight: 750;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.tab {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  padding: 8px 12px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.tab.active {
  border-bottom-color: var(--brand);
  color: var(--brand-deep);
}

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

.case-group {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 16px;
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 11px 0;
}

.tool-row:first-of-type {
  margin-top: 10px;
}

.chat-thread {
  display: grid;
  gap: 12px;
}

.message {
  max-width: 880px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  padding: 14px 16px;
}

.message.assistant {
  border-color: #b8d8d1;
  background: #f2f9f7;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.citation-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.citation {
  border-left: 3px solid #8cc8bc;
  background: #e7f3f0;
  padding: 8px 10px;
  color: #395b55;
  font-size: 12px;
}

.ledger-positive {
  color: var(--brand);
  font-weight: 800;
}

.ledger-negative {
  color: var(--red);
  font-weight: 800;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 60;
  width: min(560px, 100vw);
  height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 50px rgba(22, 48, 43, 0.16);
  padding: 24px;
  transform: translateX(105%);
  transition: transform 0.2s ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
  padding-bottom: 16px;
}

.drawer-header h2 {
  margin: 0;
}

.drawer-actions {
  display: flex;
  gap: 8px;
  margin-top: 22px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: grid;
  gap: 8px;
}

.toast {
  width: min(380px, calc(100vw - 40px));
  border: 1px solid #b5d6ce;
  border-radius: 10px;
  background: #f2faf8;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  color: var(--brand-deep);
}

.toast.error {
  border-color: #e6b3ad;
  background: var(--red-soft);
  color: var(--red);
}

.mobile-menu {
  display: none;
}

@media (max-width: 1180px) {
  :root { --sidebar: 220px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .definition-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-story { min-height: auto; padding: 38px 26px; }
  .auth-kicker { margin-top: 28px; }
  .auth-values { display: none; }
  .auth-form-wrap { padding: 38px 26px 60px; }
  .shell { display: block; }
  .sidebar { transform: translateX(-105%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .main-column { width: 100%; }
  .mobile-menu { display: flex; }
  .dashboard-grid,
  .detail-grid,
  .case-groups { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; }
  .main-content { padding: 20px 16px; }
  .env-chip { display: none; }
}

@media (max-width: 620px) {
  .metric-grid { grid-template-columns: 1fr; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .definition-grid { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar .control { width: 100%; }
  .topbar-context small,
  .user-chip .user-copy { display: none; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .drawer { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
