:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #617085;
  --line: #dbe3ef;
  --teal: #087f8c;
  --blue: #2952cc;
  --amber: #a15c00;
  --red: #b42318;
  --green: #087443;
  --shadow: 0 12px 30px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

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

button:hover {
  border-color: #9fb2cc;
}

button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

button.danger {
  border-color: #ffd4cd;
  color: var(--red);
}

button.ghost {
  background: transparent;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 88px;
  padding: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.15);
}

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

.boot,
.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.boot-panel,
.login-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.boot-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px;
}

.login-panel {
  padding: 22px;
}

.mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #102a43;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.25;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
}

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

.small {
  font-size: 12px;
}

.mono {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

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

.login-form {
  display: grid;
  gap: 12px;
}

.login-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.google-button {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.google-button:hover {
  border-color: #9fb2cc;
}

.google-button.disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.google-g {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #2952cc;
  font-weight: 900;
}

.setup-note {
  display: grid;
  gap: 6px;
  border: 1px solid #f6d28c;
  border-radius: 7px;
  background: #fff9ea;
  color: #6f4100;
  padding: 10px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.password-fallback {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.password-fallback summary {
  margin-bottom: 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.error {
  border: 1px solid #f6b7ad;
  border-radius: 7px;
  background: #fff4f2;
  color: var(--red);
  padding: 10px;
  font-size: 13px;
}

.shell {
  min-height: 100vh;
}

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

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.brand-copy {
  min-width: 0;
}

.brand-copy p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.user-chip {
  display: inline-flex;
  max-width: min(320px, 100%);
  min-height: 36px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 4px 9px 4px 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.user-chip span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: grid;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: #e9eefc;
  color: var(--blue);
  font-size: 11px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(360px, 1fr) minmax(300px, 390px);
  gap: 16px;
  padding: 16px;
}

.column {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

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

.panel-body {
  display: grid;
  gap: 12px;
  padding: 12px;
}

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

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 5px;
  font-size: 15px;
}

.status-row,
.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.kv-row span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.badge.green {
  background: #e7f6ee;
  color: var(--green);
}

.badge.blue {
  background: #e9eefc;
  color: var(--blue);
}

.badge.amber {
  background: #fff2d7;
  color: var(--amber);
}

.badge.red {
  background: #fff0ee;
  color: var(--red);
}

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

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

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

td.number,
th.number {
  text-align: right;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.chat-panel {
  min-height: calc(100vh - 104px);
}

.chat-stream {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 360px;
  max-height: calc(100vh - 330px);
  overflow-y: auto;
  padding: 12px;
}

.message {
  display: grid;
  gap: 6px;
  max-width: 92%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow-wrap: anywhere;
}

.message.user {
  justify-self: end;
  border-color: #bfd6dd;
  background: #f1fafb;
}

.message.assistant {
  justify-self: start;
  background: #fff;
}

.tool-call {
  border: 1px dashed #b9c5d4;
  border-radius: 7px;
  background: #f7f9fc;
  padding: 8px;
}

pre {
  max-height: 240px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

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

.sample-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.order-preview {
  border: 1px solid #bdd8ce;
  border-radius: 7px;
  background: #f4fbf8;
  padding: 10px;
}

.rule-list,
.audit-list,
.order-list {
  display: grid;
  gap: 8px;
}

.list-item {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  min-width: 0;
}

.list-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.list-title strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.warning-list {
  display: grid;
  gap: 6px;
}

.warning {
  border: 1px solid #f6d28c;
  border-radius: 7px;
  background: #fff9ea;
  color: #6f4100;
  padding: 8px;
  font-size: 12px;
}

.tool-lab-result {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0f172a;
  color: #e5e7eb;
  padding: 10px;
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: minmax(280px, 360px) minmax(360px, 1fr);
  }

  .right-col {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions button,
  .user-chip {
    flex: 1 1 auto;
  }

  .layout,
  .right-col {
    grid-template-columns: 1fr;
    padding: 10px;
  }

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

  .chat-panel {
    min-height: auto;
  }

  .chat-stream {
    max-height: none;
  }
}

.legal-page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 72px;
}

.legal-page h1 {
  margin: 18px 0 8px;
  font-size: 28px;
}

.legal-page h2 {
  margin: 28px 0 8px;
}

.legal-page p {
  color: var(--muted);
  line-height: 1.7;
}

.legal-back {
  color: var(--teal);
  font-weight: 800;
}
