:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #eef2f1;
  --border: #d9dfdd;
  --text: #1d2524;
  --muted: #61706d;
  --accent: #147568;
  --accent-strong: #0f5c52;
  --warning: #9a6400;
  --danger: #b42318;
  --shadow: 0 8px 28px rgba(24, 37, 35, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-head,
.topbar,
.topbar-actions,
.section-head,
.panel-head,
.inline-controls,
.auth-actions,
.lang-switch,
.fact-form,
.row-actions {
  display: flex;
  align-items: center;
}

.auth-head,
.topbar,
.section-head,
.panel-head {
  justify-content: space-between;
  gap: 16px;
}

.auth-actions,
.topbar-actions,
.inline-controls,
.fact-form,
.row-actions {
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 24px;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.field-label {
  display: block;
  margin: 20px 0 6px;
  color: var(--muted);
  font-weight: 600;
}

.text-input,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.text-input {
  min-height: 36px;
  padding: 7px 10px;
}

.text-input.compact {
  width: min(220px, 100%);
}

.text-input.tiny {
  width: 72px;
}

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

.text-input:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 117, 104, 0.12);
}

.primary-button,
.ghost-button,
.nav-item,
.lang-button,
.danger-button {
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 34px;
  padding: 6px 12px;
  background: #fff;
  color: var(--text);
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.ghost-button:hover,
.nav-item:hover,
.lang-button:hover {
  border-color: var(--accent);
}

.danger-button {
  border-color: rgba(180, 35, 24, 0.3);
  color: var(--danger);
}

.danger-button:hover {
  border-color: var(--danger);
}

.lang-switch {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  background: var(--surface-muted);
}

.lang-button {
  min-height: 28px;
  padding: 3px 10px;
  border-color: transparent;
  background: transparent;
}

.lang-button.active {
  background: #fff;
  border-color: var(--border);
  color: var(--accent-strong);
  font-weight: 700;
}

.hint,
.status-text,
.admin-id,
.meta,
.empty-state {
  color: var(--muted);
}

.hint {
  margin: 14px 0 0;
}

.status-text.error {
  color: var(--danger);
}

.status-text.ok {
  color: var(--accent-strong);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 72px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #fbfcfc;
  padding: 16px;
}

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

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
}

.nav-item.active {
  border-color: var(--accent);
  background: #e8f3f1;
  color: var(--accent-strong);
  font-weight: 700;
}

.content {
  min-width: 0;
  padding: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.metric-value {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 800;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(280px, 38%) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.panel-head {
  min-height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 185px);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8faf9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.data-table tr.selectable:hover,
.data-table tr.selected {
  background: #eef8f6;
}

.data-table td {
  word-break: break-word;
}

.message-list {
  max-height: calc(100vh - 185px);
  overflow: auto;
  padding: 12px;
}

.message-row {
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

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

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-state {
  padding: 18px;
}

.memory-summary {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.fact-list,
.candidate-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.fact-row,
.candidate-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.fact-grid {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 80px auto;
  gap: 8px;
  align-items: start;
}

.fact-form {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.toast.error {
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--danger);
}

@media (max-width: 980px) {
  .workspace,
  .split-layout {
    grid-template-columns: 1fr;
  }

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

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

  .nav-item {
    text-align: center;
  }

  .fact-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .topbar,
  .topbar-actions,
  .auth-head,
  .section-head,
  .inline-controls,
  .fact-form {
    align-items: stretch;
    flex-direction: column;
  }

  .content {
    padding: 14px;
  }

  .nav-list {
    grid-template-columns: 1fr 1fr;
  }

  .text-input.compact,
  .text-input.tiny {
    width: 100%;
  }
}
