:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #607080;
  --line: #d8dee6;
  --blue: #1f5f99;
  --green: #227451;
  --amber: #a66700;
  --red: #b42318;
  --soft-blue: #eaf3fb;
  --soft-green: #eaf7f0;
  --soft-amber: #fff5dd;
  --soft-red: #fff0ee;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

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

button.success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

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

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

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

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

.page {
  min-height: 100vh;
}

.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  padding: 18px;
  max-width: 1480px;
  margin: 0 auto;
}

.layout > div,
.section,
.right-panel {
  min-width: 0;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

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

.section-body {
  padding: 14px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

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

.login {
  width: min(420px, calc(100vw - 30px));
  margin: 70px auto 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.login h1 {
  margin: 0 0 5px;
  font-size: 22px;
}

.login form {
  display: grid;
  gap: 13px;
  margin-top: 18px;
}

.item-shell {
  overflow-x: auto;
}

.table-note {
  min-width: 720px;
  margin-bottom: 8px;
}

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

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

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  background: #f9fafb;
}

.items-table input,
.items-table select {
  min-width: 116px;
}

.items-table textarea {
  min-width: 220px;
}

.right-panel {
  position: sticky;
  top: 76px;
  align-self: start;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.metric strong {
  display: block;
  font-size: 16px;
}

.notice-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.notice {
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.notice.warn {
  background: var(--soft-amber);
  color: #5f3e00;
}

.notice.error {
  background: var(--soft-red);
  color: var(--red);
}

.notice.ok {
  background: var(--soft-green);
  color: var(--green);
}

.quote-list {
  display: grid;
  gap: 8px;
}

.chat-section .section-body {
  padding: 12px;
}

.chat-head {
  align-items: flex-end;
}

.chat-head-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-head-controls label {
  min-width: 220px;
}

.chat-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 12px;
}

.chat-box {
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
  margin-bottom: 10px;
  padding-right: 3px;
}

.chat-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #fff;
  font-size: 12px;
  white-space: pre-line;
}

.chat-message.assistant {
  background: var(--soft-blue);
  border-color: #c9dff0;
}

.chat-message.user {
  background: #f9fafb;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.quick-replies button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
  border-color: #c9dff0;
  background: #ffffff;
  color: var(--blue);
}

.chat-actions {
  margin-top: 8px;
}

.chat-context {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
  padding: 10px;
  align-self: start;
}

.context-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
}

.context-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.context-row span {
  color: var(--muted);
}

.context-row strong {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.quote-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
  background: #fff;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  background: var(--soft-blue);
  color: var(--blue);
}

.status.generated {
  background: var(--soft-green);
  color: var(--green);
}

.status.pending_approval,
.status.blocked {
  background: var(--soft-amber);
  color: var(--amber);
}

.hidden {
  display: none !important;
}

@media (max-width: 1050px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .right-panel {
    position: static;
  }

  .chat-workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }

  .topbar {
    height: auto;
    align-items: flex-start;
    padding: 14px;
    flex-direction: column;
  }

  .chat-head {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-head-controls,
  .chat-head-controls label {
    width: 100%;
  }
}
