:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-alt: #f8fafc;
  --text: #0b0b0c;
  --muted: #667085;
  --border: #e5e7eb;
  --border-strong: #d0d7de;
  --accent: #1177c5;
  --accent-strong: #0b5fa4;
  --accent-soft: #e8f3fb;
  --ok: #166534;
  --error: #b42318;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

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

main {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  margin: 0;
  padding: 90px 18px 24px;
  display: grid;
  gap: 2px;
}

.brand-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg);
  padding: 12px 18px;
}

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

.brand-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.view-switch {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #f4f7fb;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.icon {
  width: 18px;
  height: 18px;
  vertical-align: -2px;
  margin-right: 6px;
  flex: none;
  stroke: currentColor;
}

.view-tab {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.view-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 18px rgba(17, 119, 197, 0.18);
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

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

.brand-logo {
  display: block;
  width: 160px;
  height: auto;
  object-fit: contain;
  flex: none;
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  flex: none;
}

.brand-copy {
  display: grid;
  gap: 0;
}

.brand-copy h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1;
  letter-spacing: -0.03em;
}

@media (max-width: 820px) {
  .brand-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .view-switch {
    width: 100%;
    justify-content: flex-start;
  }
}

.header-query {
  flex: 1;
  min-width: min(100%, 560px);
  max-width: none;
  align-self: flex-start;
}

.header-query .response-shell {
  gap: 4px;
}

.brand-copy h1 {
  margin: 0;
  font-size: clamp(2.25rem, 3.2vw, 3.25rem);
  line-height: 0.95;
  letter-spacing: -0.05em;
  font-weight: 900;
}

.brand-copy .eyebrow {
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.brand-copy .label {
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.hero {
  padding: 8px 0 26px;
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  margin: 0;
  font-size: clamp(3.4rem, 8vw, 6.5rem);
  line-height: 0.92;
  letter-spacing: -0.07em;
  font-weight: 900;
}

.hero p {
  margin: 18px 0 0;
  max-width: 880px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

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

.stat-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 108px;
}

.stat-icon {
  width: 58px;
  height: 58px;
  border-radius: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}

.stat-copy {
  display: grid;
  gap: 2px;
}

.stat-copy .title {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.stat-copy .value {
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.05em;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.8fr);
  gap: 14px;
  align-items: stretch;
  min-height: calc(100vh - 250px);
  margin-top: 0;
  transition: grid-template-columns 0.2s ease;
}

.layout.debug-collapsed {
  grid-template-columns: 1fr;
}

.layout.debug-collapsed .debug-panel {
  display: none;
}

.upload-layout {
  display: grid;
  gap: 14px;
  margin-top: 0;
}

.upload-split {
  display: grid;
  grid-template-columns: 3fr 1fr;
  gap: 14px;
  align-items: stretch;
}

.upload-instructions-field {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.upload-instructions-field textarea {
  flex: 1;
  min-height: 0;
  max-height: none;
  height: 100%;
}

.panel {
  padding: 14px;
  height: 100%;
  min-height: 0;
}

.chat-panel,
.debug-panel,
.upload-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-panel .response-shell,
.debug-panel .response-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.chat-panel-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.chat-panel-header-actions .secondary {
  padding: 6px 10px;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-panel .response-shell {
  display: flex;
  flex-direction: column;
}

.debug-panel .response-shell {
  display: flex;
  flex-direction: column;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

form {
  display: grid;
  gap: 10px;
}

#chat-form {
  grid-template-columns: minmax(0, 1.8fr) repeat(2, minmax(140px, 0.55fr)) auto;
  align-items: end;
  gap: 8px;
}

#chat-form>label:first-child {
  gap: 4px;
}

#chat-form>label:first-child h2 {
  margin-bottom: 0;
}

#chat-form .grid {
  display: contents;
}

#chat-form .actions {
  padding-top: 0;
  align-self: end;
  justify-content: flex-start;
}

label {
  display: grid;
  gap: 4px;
  font-size: 0.88rem;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--panel-alt);
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(17, 119, 197, 0.45);
  box-shadow: 0 0 0 4px rgba(17, 119, 197, 0.12);
}

textarea {
  min-height: 46px;
  max-height: 46px;
  resize: vertical;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

button {
  border: 0;
  border-radius: 0;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
  transform: none;
}

.primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 10px 18px rgba(17, 119, 197, 0.18);
}

.secondary {
  background: #f2f5f8;
  color: var(--text);
}

.status {
  min-height: 18px;
  font-size: 0.84rem;
  color: var(--muted);
}

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

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

.response-shell {
  display: grid;
  gap: 10px;
}

.chat-thread-shell {
  position: relative;
  min-height: 0;
  height: 100%;
}

.conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-thread {
  display: grid;
  grid-auto-rows: min-content;
  align-content: start;
  justify-items: start;
  gap: 10px;
  padding: 14px;
  border-radius: 0;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(17, 119, 197, 0.04), rgba(255, 255, 255, 0)),
    #fff;
  box-shadow: var(--shadow);
  line-height: 1.5;
  min-height: 0;
  height: 100%;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(17, 119, 197, 0.45) rgba(17, 119, 197, 0.08);
}

.chat-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 0;
  background: transparent;
  pointer-events: none;
}

.chat-loading[hidden] {
  display: none;
}

.chat-spinner {
  width: 42px;
  height: 42px;
  border-radius: 0;
  border: 4px solid rgba(17, 119, 197, 0.16);
  border-top-color: var(--accent);
  animation: chat-spin 0.85s linear infinite;
  box-shadow: 0 8px 18px rgba(17, 119, 197, 0.12);
}

@keyframes chat-spin {
  to {
    transform: rotate(360deg);
  }
}

.chat-thread::-webkit-scrollbar {
  width: 12px;
}

.chat-thread::-webkit-scrollbar-track {
  background: rgba(17, 119, 197, 0.08);
  border-radius: 0;
}

.chat-thread::-webkit-scrollbar-thumb {
  background: rgba(17, 119, 197, 0.4);
  border-radius: 0;
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.chat-thread::-webkit-scrollbar-thumb:hover {
  background: rgba(17, 119, 197, 0.58);
}

.chat-empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
}

.chat-message {
  display: grid;
  width: 100%;
  align-self: start;
}

.chat-meta {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-bottom: 8px;
  padding: 3px 8px;
  border: 1px solid currentColor;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.chat-bubble {
  width: 100%;
  max-width: none;
  padding: 12px 14px;
  border-radius: 0;
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 0.94rem;
}

.chat-user .chat-bubble {
  background: linear-gradient(180deg, rgba(17, 119, 197, 0.08), rgba(17, 119, 197, 0.02));
  border-color: rgba(17, 119, 197, 0.18);
  border-left-color: var(--accent);
}

.chat-assistant .chat-bubble {
  background: #ffffff;
  border-left-color: #9aa4b2;
}

.chat-user .chat-meta {
  color: var(--accent-strong);
}

.chat-assistant .chat-meta {
  color: #475467;
}

.chat-bubble p {
  margin: 0;
  color: var(--text);
}

.chat-bubble a {
  color: var(--accent-strong);
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.chat-bubble strong {
  font-weight: 800;
}

.answer-heading {
  margin: 0;
  color: var(--text);
  letter-spacing: -0.03em;
}

.chat-bubble h2.answer-heading {
  font-size: 1.25rem;
}

.chat-bubble h3.answer-heading {
  font-size: 1.12rem;
}

.chat-bubble h4.answer-heading {
  font-size: 1rem;
}

.answer-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text);
}

.answer-list li+li {
  margin-top: 0.35rem;
}

.answer-code {
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  border-radius: 0;
  background: #0b1220;
  color: #e5eefb;
  border: 1px solid #1f2a37;
}

.answer-code code {
  font-family: "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92rem;
}

.answer-empty {
  color: var(--muted);
  margin: 0;
}

.response-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.pill strong {
  color: var(--text);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: #0b1220;
  color: #e5eefb;
  padding: 12px;
  border-radius: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  border: 1px solid #1f2a37;
  scrollbar-width: thin;
  scrollbar-color: rgba(17, 119, 197, 0.45) rgba(17, 119, 197, 0.08);
  font-size: 0.84rem;
}

pre::-webkit-scrollbar {
  width: 12px;
}

pre::-webkit-scrollbar-track {
  background: rgba(17, 119, 197, 0.08);
  border-radius: 0;
}

pre::-webkit-scrollbar-thumb {
  background: rgba(17, 119, 197, 0.4);
  border-radius: 0;
  border: 2px solid rgba(11, 18, 32, 0.95);
}

pre::-webkit-scrollbar-thumb:hover {
  background: rgba(17, 119, 197, 0.58);
}

.note {
  margin-top: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.upload-form {
  gap: 14px;
}

.upload-panel .response-shell {
  position: relative;
}

.upload-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.upload-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.84rem;
  font-weight: 600;
}

.upload-controls select,
.upload-controls input {
  padding: 8px 10px;
  font-size: 0.92rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--panel-alt);
  color: var(--text);
  outline: none;
  transition: border-color 0.14s ease;
}

.upload-controls select:focus,
.upload-controls input:focus {
  border-color: var(--accent);
}

.upload-instructions-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 600;
}

.upload-instructions-field textarea {
  min-height: 112px;
  padding: 10px 12px;
  font-size: 0.92rem;
  line-height: 1.5;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--panel-alt);
  color: var(--text);
  outline: none;
  resize: vertical;
  transition: border-color 0.14s ease;
}

.upload-instructions-field textarea:focus {
  border-color: var(--accent);
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 240px;
  border: 2px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--panel-alt);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  padding: 24px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop-icon {
  width: 48px;
  height: 48px;
  color: var(--muted);
  stroke: currentColor;
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  color: var(--accent);
}

.drop-text {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text);
}

.drop-hint {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.upload-file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(17, 119, 197, 0.2);
  border-radius: 4px;
}

.upload-file-info span {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.upload-actions button {
  padding: 8px 14px;
  font-size: 0.88rem;
}

.upload-review {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(17, 119, 197, 0.05), rgba(255, 255, 255, 0)),
    #fff;
  box-shadow: var(--shadow);
}

.upload-summary-editor {
  min-height: 360px;
  max-height: none;
  resize: vertical;
  font-family: "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.55;
}

.records-layout {
  display: grid;
  gap: 14px;
  margin-top: 0;
}

.records-panel {
  min-height: 0;
}

.records-form {
  gap: 12px;
}

.records-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.records-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.84rem;
  font-weight: 600;
}

.records-controls select,
.records-controls input {
  padding: 8px 10px;
  font-size: 0.92rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--panel-alt);
  color: var(--text);
  outline: none;
  transition: border-color 0.14s ease;
}

.records-controls select:focus,
.records-controls input:focus {
  border-color: var(--accent);
}

.records-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

.records-actions button {
  padding: 8px 14px;
  font-size: 0.88rem;
}

.records-results-shell {
  position: relative;
  min-height: 0;
  height: 100%;
  display: grid;
  gap: 12px;
}

.records-files-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(17, 119, 197, 0.04), rgba(255, 255, 255, 0)),
    #fff;
  box-shadow: var(--shadow);
}

.records-files-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.records-files-header h3 {
  margin: 0;
  font-size: 0.98rem;
}

.records-files-path {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.records-files-list {
  overflow: auto;
  border: 1px solid var(--border);
  background: #fff;
}

.records-files-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

.records-files-table thead th {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-strong);
  background: linear-gradient(180deg, #f4f7fb, #eef4f9);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
  position: sticky;
  top: 0;
}

.records-files-table tbody tr:nth-child(odd) {
  background: rgba(17, 119, 197, 0.025);
}

.records-files-table tbody tr:hover {
  background: rgba(17, 119, 197, 0.07);
}

.records-files-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  vertical-align: top;
}

.records-file-name {
  min-width: 180px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-word;
}

.records-file-meta {
  word-break: break-word;
}

.records-file-size {
  white-space: nowrap;
  font-weight: 700;
  color: var(--accent-strong);
}

.records-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  align-content: start;
  padding: 14px;
  border-radius: 0;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(17, 119, 197, 0.04), rgba(255, 255, 255, 0)),
    #fff;
  box-shadow: var(--shadow);
  min-height: 0;
  height: 100%;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(17, 119, 197, 0.45) rgba(17, 119, 197, 0.08);
}

.records-results::-webkit-scrollbar {
  width: 12px;
}

.records-results::-webkit-scrollbar-track {
  background: rgba(17, 119, 197, 0.08);
  border-radius: 0;
}

.records-results::-webkit-scrollbar-thumb {
  background: rgba(17, 119, 197, 0.4);
  border-radius: 0;
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.records-card {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  line-height: 1.45;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.records-card:hover {
  border-color: rgba(17, 119, 197, 0.35);
  box-shadow: 0 6px 16px rgba(17, 119, 197, 0.1);
}

.records-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.records-card-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.records-card-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.records-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.records-badge.kind {
  background: var(--accent-soft);
  border-color: rgba(17, 119, 197, 0.25);
  color: var(--accent-strong);
}

.records-card-body {
  color: var(--muted);
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.records-card-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--muted);
}

.records-card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.records-empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
  grid-column: 1 / -1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 32, 0.65);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: 0 24px 64px rgba(11, 18, 32, 0.25);
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.modal-close {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px 8px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.14s ease, color 0.14s ease;
}

.modal-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-body {
  padding: 20px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(17, 119, 197, 0.45) rgba(17, 119, 197, 0.08);
}

.modal-body::-webkit-scrollbar {
  width: 12px;
}

.modal-body::-webkit-scrollbar-track {
  background: rgba(17, 119, 197, 0.08);
}

.modal-body::-webkit-scrollbar-thumb {
  background: rgba(17, 119, 197, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.9);
}

.modal-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.modal-badge.kind {
  background: var(--accent-soft);
  border-color: rgba(17, 119, 197, 0.25);
  color: var(--accent-strong);
}

.modal-section {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.modal-section label {
  display: grid;
  gap: 4px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.modal-section input,
.modal-section select,
.modal-section textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--panel-alt);
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.modal-section input:focus,
.modal-section select:focus,
.modal-section textarea:focus {
  border-color: rgba(17, 119, 197, 0.45);
  box-shadow: 0 0 0 4px rgba(17, 119, 197, 0.12);
}

.modal-section textarea {
  min-height: 120px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88rem;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--panel-alt);
}

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

.modal-actions .primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 18px rgba(17, 119, 197, 0.18);
}

.modal-actions .secondary {
  background: #f2f5f8;
  color: var(--text);
}

.modal-actions .secondary:hover {
  background: #e8ebef;
}

.records-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--panel-alt);
}

.records-pagination .secondary {
  padding: 6px 12px;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.records-page-info {
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.upload-summary {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: linear-gradient(180deg, rgba(17, 119, 197, 0.04), rgba(255, 255, 255, 0.9));
}

.upload-summary h3 {
  margin: 0;
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}

.summary-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.summary-list div {
  padding: 10px 12px;
  border-radius: 0;
  background: #fff;
  border: 1px solid var(--border);
}

.summary-list dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.summary-list dd {
  margin: 0;
  color: var(--text);
  font-weight: 600;
  word-break: break-word;
}

@media (max-width: 860px) {
  main {
    width: min(100% - 24px, 1400px);
    padding-top: 90px;
  }

  .brand-row {
    flex-direction: column;
    align-items: stretch;
  }

  .header-query {
    min-width: 0;
    max-width: none;
  }

  #chat-form {
    grid-template-columns: 1fr;
  }

  #chat-form .grid {
    display: grid;
  }

  .stats,
  .layout {
    grid-template-columns: 1fr;
  }

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

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

  .upload-controls {
    grid-template-columns: 1fr;
  }

  .upload-split {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .records-controls {
    grid-template-columns: 1fr;
  }

  .records-results {
    grid-template-columns: 1fr;
  }

  .drop-zone {
    min-height: 180px;
  }

  .hero h1 {
    font-size: clamp(2.6rem, 12vw, 4.2rem);
  }
}

@media (max-width: 560px) {
  .brand-row {
    align-items: flex-start;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .panel,
  .stat-card {
    padding: 16px;
  }
}