:root {
  --bg: #f2f6f4;
  --bg-accent-a: #dcf1e9;
  --bg-accent-b: #fff0da;

  --surface: #ffffff;
  --surface-soft: #f7fbf9;
  --surface-muted: #eff6f2;

  --text: #20353c;
  --text-strong: #15272d;
  --text-muted: #4f666e;
  --text-soft: #657b82;

  --line: #cadbd4;
  --line-strong: #afc4bc;

  --brand-50: #e4f3ee;
  --brand-100: #c9e7dd;
  --brand-500: #1f8a70;
  --brand-600: #19745e;
  --brand-700: #145a49;
  --brand-rgb: 31, 138, 112;
  --schema-500: #1a8f78;
  --schema-600: #147562;

  --accent-50: #fff4e6;
  --accent-100: #ffe7c7;
  --accent-500: #d78b2a;
  --accent-600: #b56f19;

  --success-bg: #edf9f2;
  --success-line: #c8e8d6;
  --success-text: #215c46;

  --error-bg: #fff2f1;
  --error-line: #efc8c4;
  --error-text: #8a312c;

  --danger-500: #c44840;
  --danger-600: #a73a33;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;

  --shadow-sm: 0 2px 8px rgba(20, 42, 45, 0.08);
  --shadow-md: 0 10px 24px rgba(20, 42, 45, 0.1);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: 'IBM Plex Sans', 'Segoe UI', 'Noto Sans', sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 420px at 10% -10%, var(--bg-accent-a) 0%, transparent 55%),
    radial-gradient(1200px 420px at 90% -20%, var(--bg-accent-b) 0%, transparent 50%),
    var(--bg);
  font-size: 16px;
  line-height: 1.58;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5) var(--space-6);
}

.page-header {
  margin-bottom: var(--space-6);
}

.page-eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--brand-700);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-title {
  margin: 0;
  font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
  font-size: clamp(28px, 3.2vw, 42px);
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--text-strong);
}

.page-subtitle {
  margin: var(--space-3) 0 0;
  max-width: 82ch;
  color: var(--text-muted);
  font-size: 16px;
}

.panel {
  background: linear-gradient(180deg, var(--surface) 0%, #fcfefc 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.panel-title {
  margin: 0 0 var(--space-3);
  font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
  font-size: 21px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text-strong);
}

.auth-panel .explanation {
  margin-bottom: var(--space-2);
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

#googleLoginButton:empty {
  min-height: 40px;
}

.auth-user {
  margin: var(--space-2) 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.data-actions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-soft) 100%);
}

.data-actions-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.45;
}

label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: 14px;
  font-weight: 600;
  color: #2a444c;
}

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

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea {
  margin-top: 2px;
  min-height: 110px;
  resize: vertical;
  line-height: 1.55;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.2);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 11px;
  border: 1px solid transparent;
  min-height: 40px;
  padding: 10px 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.btn:focus-visible,
button:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(var(--brand-rgb), 0.34);
  outline-offset: 1px;
}

.btn-primary {
  background: linear-gradient(180deg, #2ca082 0%, var(--brand-500) 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(var(--brand-rgb), 0.28);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 11px 22px rgba(var(--brand-rgb), 0.34);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-schema {
  background: linear-gradient(180deg, #2ca084 0%, var(--schema-500) 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(var(--brand-rgb), 0.27);
}

.btn-schema:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #28967c 0%, var(--schema-600) 100%);
  box-shadow: 0 11px 22px rgba(var(--brand-rgb), 0.32);
}

.btn-schema:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--accent-50);
  border-color: var(--accent-100);
  color: #6e4512;
  box-shadow: none;
}

.btn-secondary:hover {
  background: var(--accent-100);
  transform: none;
  box-shadow: none;
}

.btn-uniques {
  background: linear-gradient(180deg, #efb75b 0%, var(--accent-500) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(215, 139, 42, 0.26);
}

.btn-uniques:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #e6ab4a 0%, var(--accent-600) 100%);
  box-shadow: 0 11px 22px rgba(181, 111, 25, 0.3);
}

.btn-uniques.active {
  background: linear-gradient(180deg, #2ca084 0%, var(--schema-500) 100%);
  box-shadow: 0 8px 18px rgba(var(--brand-rgb), 0.27);
}

.btn-ghost,
button.secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: #36525b;
  box-shadow: none;
}

.btn-ghost:hover,
button.secondary:hover {
  background: var(--surface-soft);
}

.btn-danger,
button.danger {
  background: linear-gradient(180deg, #cd5951 0%, var(--danger-500) 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(196, 72, 64, 0.24);
}

.btn-danger:hover,
button.danger:hover {
  background: linear-gradient(180deg, #bc4b44 0%, var(--danger-600) 100%);
}

button:disabled,
.btn:disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.mode-switch {
  margin-top: 0;
  padding: 5px;
  border-radius: 12px;
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
  display: inline-flex;
}

.mode-switch .mode-btn {
  min-height: 36px;
  border-radius: 9px;
  background: transparent;
  border: 1px solid transparent;
  color: #2d5b52;
  box-shadow: none;
  padding: 8px 14px;
}

.mode-switch .mode-btn:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.58);
}

.mode-switch .mode-btn.active {
  background: var(--surface);
  color: var(--brand-700);
  border-color: var(--brand-100);
  box-shadow: 0 2px 8px rgba(31, 91, 77, 0.14);
}

.chat {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  min-height: 210px;
  max-height: 350px;
  overflow: auto;
  padding: var(--space-3);
}

.msg {
  margin-bottom: var(--space-2);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  line-height: 1.52;
  color: var(--text);
}

.msg.user {
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
}

.msg.assistant {
  background: var(--accent-50);
  border: 1px solid var(--accent-100);
}

.explanation {
  background: var(--success-bg);
  border: 1px solid var(--success-line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  margin-bottom: var(--space-3);
  color: var(--success-text);
  font-size: 15px;
  line-height: 1.56;
  white-space: pre-line;
}

.table-wrap {
  max-width: 100%;
  max-height: 500px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.table-wrap table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}

.table-wrap th,
.table-wrap td {
  border-right: 1px solid #dde8e3;
  border-bottom: 1px solid #dde8e3;
  padding: 7px 8px;
  text-align: left;
  white-space: nowrap;
}

.table-wrap th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 700;
  font-size: 13px;
}

.table-wrap tbody tr:nth-child(2n) td {
  background: var(--surface-soft);
}

.table-wrap td {
  color: var(--text);
}

.table-wrap td:last-child,
.table-wrap th:last-child {
  border-right: none;
}

.result-toolbar label {
  margin-bottom: 0;
}

.aggregation-value {
  margin-bottom: var(--space-3);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--brand-100);
  background: linear-gradient(180deg, var(--brand-50) 0%, #f3f8f5 100%);
  font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 800;
  line-height: 1;
  color: var(--brand-700);
  letter-spacing: -0.02em;
}

.aggregation-value.compact {
  white-space: pre-line;
  font-size: clamp(18px, 2.8vw, 30px);
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: normal;
}

.aggregation-breakdowns {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.aggregation-breakdown-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.aggregation-breakdown-header {
  padding: 12px 14px;
  border-bottom: 1px solid #dbe6e1;
  background: linear-gradient(180deg, var(--surface-soft) 0%, var(--surface) 100%);
}

.aggregation-breakdown-title {
  margin: 0;
  font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
  font-size: 16px;
  color: var(--text-strong);
}

.aggregation-breakdown-meta {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-soft);
}

.aggregation-breakdown-empty {
  margin: 0;
  padding: 12px 14px;
  color: var(--text-soft);
  font-size: 14px;
}

.aggregation-breakdown-table-wrap {
  max-height: 360px;
  overflow: auto;
}

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

.aggregation-breakdown-table th,
.aggregation-breakdown-table td {
  border-bottom: 1px solid #dde8e3;
  padding: 7px 9px;
  text-align: left;
  white-space: nowrap;
}

.aggregation-breakdown-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--brand-50);
  color: var(--brand-700);
  font-weight: 700;
}

.aggregation-breakdown-table tbody tr:nth-child(2n) td {
  background: var(--surface-soft);
}

.request-processing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--brand-700);
}

.request-processing[hidden] {
  display: none;
}

.request-processing::before {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--brand-100);
  border-top-color: var(--brand-500);
  animation: request-spin 0.75s linear infinite;
}

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

#schemaPanel {
  overflow: hidden;
}

.schema-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: end;
  margin-bottom: var(--space-3);
  min-width: 0;
}

.schema-select-group {
  min-width: 0;
}

.schema-select-group label {
  margin-bottom: 6px;
}

.schema-select-group select {
  width: 100%;
  min-width: 0;
}

.schema-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.schema-actions .btn {
  white-space: nowrap;
}

.schema-status {
  color: #365a51;
  font-size: 14px;
  margin-bottom: var(--space-3);
  padding: 10px 12px;
  border: 1px solid var(--brand-100);
  border-radius: var(--radius-sm);
  background: var(--brand-50);
  overflow-wrap: anywhere;
}

.schema-view {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.schema-view > * {
  min-width: 0;
}

.schema-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-2);
}

.schema-card {
  border: 1px solid #dce7e2;
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-soft);
}

.schema-card .k {
  display: block;
  color: #56726b;
  font-size: 13px;
  margin-bottom: 4px;
}

.schema-card .v {
  font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
  font-size: 21px;
  font-weight: 700;
  color: #1c4c41;
  overflow-wrap: anywhere;
}

.schema-section {
  border: 1px solid #dce7e2;
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-3);
  overflow: hidden;
}

.schema-section-title {
  margin: 0 0 10px;
  font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
  font-size: 16px;
  color: #25544a;
}

.schema-columns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid #d2dfd9;
  background: #f8fcfa;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 13px;
  color: #365d54;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.schema-preview {
  border: 1px solid #dbe5e1;
  border-radius: var(--radius-sm);
  width: 100%;
  overflow: auto;
  max-height: 350px;
  background: var(--surface);
}

.schema-preview table {
  font-size: 13px;
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

.schema-preview th,
.schema-preview td {
  border: 1px solid #d6e1dd;
  padding: 6px 8px;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: top;
  min-width: 120px;
  max-width: 280px;
}

.schema-preview th {
  position: sticky;
  top: 0;
  background: var(--surface-muted);
  z-index: 1;
}

.schema-unique-columns {
  display: grid;
  gap: var(--space-2);
}

.schema-unique-card {
  border: 1px solid #dbe5e1;
  border-radius: var(--radius-sm);
  padding: 10px;
  background: #fbfdfc;
}

.schema-unique-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  color: #244f45;
  overflow-wrap: anywhere;
}

.schema-unique-meta {
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 8px;
}

.schema-empty {
  margin: 0;
  font-size: 14px;
  color: var(--text-soft);
}

pre {
  white-space: pre-wrap;
  font-size: 13px;
  max-height: 400px;
  overflow: auto;
}

@media (max-width: 900px) {
  .container {
    padding: var(--space-6) var(--space-4) var(--space-5);
  }

  .schema-toolbar {
    grid-template-columns: minmax(0, 1fr) 1fr;
  }

  .schema-select-group {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .container {
    padding: var(--space-5) var(--space-3) var(--space-4);
  }

  .panel {
    padding: var(--space-4);
  }

  .row {
    gap: var(--space-2);
  }

  .row > .btn,
  .row > button {
    width: 100%;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-switch .mode-btn {
    flex: 1;
  }

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

  .schema-toolbar button {
    width: 100%;
    white-space: normal;
  }

  .data-actions {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .schema-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .schema-actions .btn {
    width: 100%;
    white-space: normal;
  }

  .schema-card .v {
    font-size: 18px;
  }

  .schema-preview th,
  .schema-preview td {
    min-width: 100px;
    max-width: 220px;
  }
}
