/* Design tokens — shared across every page.
   Neutral + indigo scale follows a standard 50-900 ramp so every tint/shade
   used across the app is drawn from one considered palette instead of ad
   hoc hex values. */
:root {
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-900: #111827;

  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-200: #c7d2fe;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;
  --indigo-800: #3730a3;

  --color-bg: var(--gray-50);
  --color-surface: #ffffff;
  --color-border: var(--gray-200);
  --color-border-strong: var(--gray-300);
  --color-text: var(--gray-900);
  --color-text-muted: var(--gray-600);
  --color-text-faint: var(--gray-500);

  --color-primary: var(--indigo-600);
  --color-primary-hover: var(--indigo-700);
  --color-primary-soft: var(--indigo-50);
  --color-primary-ring: var(--indigo-200);

  --color-success: #059669;
  --color-success-soft: #d1fae5;
  --color-danger: #dc2626;
  --color-danger-soft: #fee2e2;
  --color-warning: #d97706;
  --color-warning-soft: #fef3c7;

  --color-nav-bg: #0c0d12;

  --radius-sm: 7px;
  --radius-md: 11px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.1);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, 0.2);
  --shadow-primary: 0 4px 12px rgba(79, 70, 229, 0.28);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  margin: 0;
  font-family: var(--font-sans);
  /* Faint brand-gradient wash echoing the login page's mesh, fixed to the
     viewport so the glass cards/sidebar/nav always have something to blend
     with as the page scrolls. */
  background:
    radial-gradient(1200px 600px at 8% -10%, rgba(99, 102, 241, 0.06), transparent 60%),
    radial-gradient(1000px 520px at 100% 0%, rgba(139, 92, 246, 0.05), transparent 60%),
    radial-gradient(900px 500px at 50% 100%, rgba(99, 102, 241, 0.035), transparent 65%),
    var(--color-bg);
  background-attachment: fixed;
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px;
}

header h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--color-text-muted);
  font-size: 14px;
}

/* ---------------------------------------------------------------
   Buttons
   --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  white-space: nowrap;
}
.btn:active:not(:disabled) { transition-duration: 0.05s; transform: translateY(1px) !important; box-shadow: none !important; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.btn-primary { background: var(--color-text); color: white; }
.btn-primary:hover:not(:disabled) { background: #000; transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-accent { background: linear-gradient(135deg, var(--color-primary), #8b5cf6); color: white; }
.btn-accent:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); box-shadow: var(--shadow-primary); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--gray-50); border-color: var(--color-text-faint); transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.btn-danger-outline { background: var(--color-surface); color: var(--color-danger); border-color: #fecaca; }
.btn-danger-outline:hover:not(:disabled) { background: var(--color-danger-soft); border-color: var(--color-danger); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: var(--radius-sm); }

/* ---------------------------------------------------------------
   Forms
   --------------------------------------------------------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--color-text-muted); font-weight: 500; }

input, select, textarea { font-family: inherit; }

.field input,
.field select,
#prompt-input,
.company-grid input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus,
.field select:focus,
#prompt-input:focus,
.company-grid input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

/* ---------------------------------------------------------------
   Cards, badges, tables — shared components
   --------------------------------------------------------------- */
.card {
  /* Frosted glass, same recipe as the login card — bumped to 0.84 opacity
     (from 0.72) so text sits on a more solid surface and stays readable
     even where the page's corner wash shows through. */
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-md);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: box-shadow 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.25s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card:hover {
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 0 0 1px rgba(99, 102, 241, 0.1);
  transform: translateY(-3px);
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Lets wide tables (e.g. the Users/Companies admin tables, with inline
   edit inputs) scroll horizontally on narrow screens instead of squeezing
   their last column — including action buttons like Save — off-screen
   with no way to reach it. */
.table-scroll { width: 100%; overflow-x: auto; }
.table-scroll table { min-width: 560px; }

table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th {
  text-align: left;
  padding: 10px 8px;
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--color-border);
}
td { padding: 10px 8px; border-bottom: 1px solid var(--color-border); }
tbody tr { transition: background-color 0.12s ease, box-shadow 0.12s ease; }
tbody tr:not([aria-hidden]):hover { background: var(--color-bg); box-shadow: inset 3px 0 0 var(--color-primary); }

code {
  background: #f1f2f6;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12px;
  color: #3a3f4b;
}

/* ---------------------------------------------------------------
   AI page — prompt form and results
   --------------------------------------------------------------- */
#prompt-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#prompt-input { flex: 1; font-size: 15px; padding: 12px 14px; min-width: 200px; }

/* Below this, the input + mic + Ask row gets too cramped for comfortable
   typing/tapping — put the input on its own row, buttons below it. */
@media (max-width: 520px) {
  #prompt-input { flex-basis: 100%; }
  #mic-btn, #submit-btn { flex: 1; }
}

#mic-btn, #submit-btn {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

#mic-btn { background: var(--color-surface); border-color: var(--color-border-strong); transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1); }
#mic-btn:hover { background: #f9fafb; transform: translateY(-1px); }
#mic-btn.listening {
  background: var(--color-danger-soft);
  border-color: #f3d3ce;
  animation: micPulse 1.4s ease-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  #mic-btn.listening { animation: none; }
}
@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.35); }
  70% { box-shadow: 0 0 0 9px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

#submit-btn { background: linear-gradient(135deg, var(--color-primary), #8b5cf6); color: white; border: none; font-weight: 500; transition: filter 0.15s ease, transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.15s ease; }
#submit-btn:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); box-shadow: var(--shadow-primary); }

.status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--color-text-muted);
  min-height: 18px;
}
.status.thinking::after {
  content: "";
  display: inline-block;
  width: 1em;
  text-align: left;
  animation: ellipsis 1.2s steps(4, end) infinite;
}
@media (prefers-reduced-motion: reduce) {
  .status.thinking::after { animation: none; content: "…"; }
}
@keyframes ellipsis {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

.results {
  margin-top: 24px;
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-md);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.hidden { display: none !important; }

.summary {
  font-size: 15px;
  line-height: 1.6;
  margin-top: 0;
}

canvas { max-height: 320px; margin: 16px 0; }

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

#sql-details {
  margin-top: 16px;
  font-size: 12px;
  color: var(--color-text-muted);
}
#sql-details summary { cursor: pointer; }

#sql-text {
  white-space: pre-wrap;
  background: #f6f7fa;
  border: 1px solid var(--color-border);
  padding: 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text);
}

.error {
  color: var(--color-danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

/* ---------------------------------------------------------------
   Motion & loading — used across pages for a less "static" feel
   --------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  .fade-in { animation: fadeIn 0.32s cubic-bezier(0.2, 0.8, 0.2, 1); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, #eef0f3 37%, var(--color-border) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: skeletonShine 1.4s ease infinite;
}
@keyframes skeletonShine {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: var(--color-border); }
}

/* ---------------------------------------------------------------
   Toggle switch — a more tactile alternative to a plain checkbox
   --------------------------------------------------------------- */
.toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-muted);
  user-select: none;
}
.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-slider {
  position: relative;
  width: 34px;
  height: 20px;
  flex-shrink: 0;
  background: var(--color-border-strong);
  border-radius: 999px;
  transition: background-color 0.2s ease;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.25);
  transition: transform 0.2s ease;
}
.toggle-switch input:checked + .toggle-slider { background: var(--color-primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(14px); }
.toggle-switch input:focus-visible + .toggle-slider { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* ---------------------------------------------------------------
   Dark mode — opt-in via the header toggle (persisted in
   localStorage), same navy + indigo/purple palette as the login page.
   The topnav is intentionally always-dark in both modes, so it isn't
   touched here.
   --------------------------------------------------------------- */
html[data-theme="dark"] {
  --color-bg: #050914;
  --color-surface: #10152a;
  --color-border: rgba(255, 255, 255, 0.12);
  --color-border-strong: rgba(255, 255, 255, 0.22);
  --color-text: #f1f5f9;
  --color-text-muted: rgba(226, 232, 240, 0.65);
  --color-text-faint: rgba(226, 232, 240, 0.45);

  --color-primary: #6366f1;
  --color-primary-hover: #818cf8;
  --color-primary-soft: rgba(99, 102, 241, 0.18);
  --color-primary-ring: rgba(99, 102, 241, 0.35);

  --color-success: #34d399;
  --color-success-soft: rgba(52, 211, 153, 0.16);
  --color-danger: #f87171;
  --color-danger-soft: rgba(248, 113, 113, 0.16);
  --color-warning: #fbbf24;
  --color-warning-soft: rgba(251, 191, 36, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  --shadow-primary: 0 4px 16px rgba(99, 102, 241, 0.4);
}

html[data-theme="dark"] body {
  background:
    radial-gradient(1200px 600px at 8% -10%, rgba(99, 102, 241, 0.16), transparent 60%),
    radial-gradient(1000px 520px at 100% 0%, rgba(139, 92, 246, 0.13), transparent 60%),
    radial-gradient(900px 500px at 50% 100%, rgba(99, 102, 241, 0.08), transparent 65%),
    var(--color-bg);
}

html[data-theme="dark"] .btn-primary { background: #f1f5f9; color: #0f172a; }
html[data-theme="dark"] .btn-primary:hover:not(:disabled) { background: #ffffff; }

html[data-theme="dark"] .btn-secondary:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); }

html[data-theme="dark"] .btn-danger-outline { border-color: rgba(248, 113, 113, 0.35); }

html[data-theme="dark"] .field input,
html[data-theme="dark"] .field select,
html[data-theme="dark"] #prompt-input,
html[data-theme="dark"] .company-grid input {
  background: rgba(255, 255, 255, 0.05);
}
html[data-theme="dark"] .field input:focus,
html[data-theme="dark"] .field select:focus,
html[data-theme="dark"] #prompt-input:focus,
html[data-theme="dark"] .company-grid input:focus {
  background: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .card {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.68), rgba(15, 23, 42, 0.72));
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
html[data-theme="dark"] .card:hover {
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 0 1px rgba(99, 102, 241, 0.22);
}

html[data-theme="dark"] .results {
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.68), rgba(15, 23, 42, 0.72));
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] tbody tr:not([aria-hidden]):hover { background: rgba(255, 255, 255, 0.05); }

html[data-theme="dark"] code { background: rgba(255, 255, 255, 0.08); color: #e2e8f0; }

html[data-theme="dark"] #mic-btn:hover { background: rgba(255, 255, 255, 0.06); }
html[data-theme="dark"] #mic-btn.listening { border-color: rgba(248, 113, 113, 0.4); }

html[data-theme="dark"] #sql-text { background: rgba(255, 255, 255, 0.05); }

html[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, rgba(255, 255, 255, 0.22) 37%, var(--color-border) 63%);
  background-size: 400% 100%;
}
