:root,
[data-theme="dark"] {
  --bg: #161616;
  --surface: #262626;
  --card: rgba(38, 38, 38, 0.65);
  --card-solid: #262626;
  --nav-bg: rgba(16, 16, 20, 0.78);
  --glass-bg: linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.04));
  --glass-border: rgba(255, 255, 255, 0.13);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -1px 0 rgba(255, 255, 255, 0.03);
  --glass-shadow-hover: 0 16px 52px rgba(0, 0, 0, 0.52), 0 4px 16px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --glass-blur: blur(22px) saturate(180%);
  --glass-blur-soft: blur(16px) saturate(165%);
  --accent: #4589ff;
  --accent-light: #78a9ff;
  --accent-hover: #0f62fe;
  --accent-dim: rgba(69, 137, 255, 0.15);
  --accent-border: rgba(69, 137, 255, 0.35);
  --text: #f4f4f4;
  --text-secondary: #c6c6c6;
  --muted: #a8a8a8;
  --border: #393939;
  --border-strong: #525252;
  --support-success: #42be65;
  --support-error: #fa4d56;
  --font-heading: "IBM Plex Sans", system-ui, sans-serif;
  --font-body: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(145deg, #0d0f18 0%, #161616 40%, #111318 70%, #0e1020 100%);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.65;
  overflow-x: hidden;
  text-rendering: optimizeSpeed;
}

body.signed-out {
  overflow: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  pointer-events: none;
  z-index: 0;
}

body::before {
  inset: 0;
  background-image: radial-gradient(circle, rgba(69, 137, 255, 0.22) 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.16;
  mask-image: radial-gradient(ellipse 86% 82% at 50% 50%, black 20%, transparent 100%);
}

body::after {
  width: 580px;
  height: 580px;
  left: -16%;
  top: -18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(69, 137, 255, 0.34) 0%, transparent 65%);
  filter: blur(92px);
  opacity: 0.48;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.noise-overlay {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 999;
  opacity: 0.12;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--glass-border);
  background: var(--nav-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: var(--glass-bg);
  box-shadow: var(--glass-shadow);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand strong,
h1,
h2 {
  font-family: var(--font-heading);
  letter-spacing: 0;
}

.brand strong {
  display: block;
  line-height: 1.1;
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

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

.nav-item,
.ghost-button,
.primary-button,
.danger-button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  background: transparent;
  padding: 0 14px;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-item {
  text-align: left;
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-weight: 600;
}

.nav-item.active,
.primary-button {
  border-color: var(--accent-border);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-heading);
  font-weight: 600;
}

.danger-button {
  color: var(--support-error);
  border-color: rgba(250, 77, 86, 0.45);
  background: rgba(250, 77, 86, 0.08);
  font-family: var(--font-heading);
  font-weight: 600;
}

.danger-button:hover {
  color: #fff;
  border-color: rgba(250, 77, 86, 0.8);
  background: rgba(250, 77, 86, 0.72);
}

.ghost-button:hover,
.nav-item:hover {
  border-color: var(--accent-border);
  background: var(--accent-dim);
  color: var(--accent-light);
  transform: translateY(-1px);
}

#signOut {
  margin-top: auto;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.signed-out .app-shell {
  display: block;
  min-height: 100vh;
}

.signed-out .sidebar,
.signed-out .topbar,
.signed-out .app-view {
  display: none;
}

.signed-out .workspace {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  place-items: center;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font: 600 0.625rem var(--font-heading);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.875rem, 5vw, 2.75rem);
  text-transform: uppercase;
}

h2 {
  font-size: 1rem;
}

.account-pill {
  max-width: 340px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur-soft);
  -webkit-backdrop-filter: var(--glass-blur-soft);
  padding: 8px 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-view {
  min-height: 62vh;
  display: grid;
  place-items: center;
}

.signed-out .login-view {
  width: min(560px, 100%);
  min-height: auto;
}

.login-panel,
.panel,
.metric,
.search-bar,
.dashboard-hero {
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
}

.login-panel {
  width: min(520px, 100%);
  padding: 34px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.login-panel::before,
.dashboard-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.12), transparent 42%);
  pointer-events: none;
}

.login-panel > *,
.dashboard-hero > * {
  position: relative;
  z-index: 1;
}

.login-logo {
  width: min(300px, 82%);
  height: auto;
  margin: 0 auto 28px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

#googleButton {
  display: flex;
  justify-content: center;
}

.status-line {
  min-height: 24px;
  color: var(--muted);
}

.view {
  display: none;
}

.app-view,
.view.active {
  display: block;
}

.hidden,
.app-view.hidden {
  display: none;
}

.dashboard-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
  padding: 24px;
  margin-bottom: 14px;
  overflow: hidden;
}

.dashboard-hero::after {
  content: "";
  position: absolute;
  width: 320px;
  height: 320px;
  right: -90px;
  top: -120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(69, 137, 255, 0.22) 0%, transparent 65%);
  filter: blur(34px);
}

.dashboard-logo {
  width: min(280px, 80%);
  height: auto;
  margin-bottom: 16px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.88;
}

.dashboard-hero h2 {
  font-size: clamp(1.6rem, 2.8vw, 3rem);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.dashboard-copy {
  margin: 0;
  color: var(--text-secondary);
  max-width: 58ch;
}

.dashboard-avatar {
  position: relative;
  z-index: 1;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  box-shadow: 0 0 0 8px rgba(69, 137, 255, 0.08), 0 18px 38px rgba(0, 0, 0, 0.28);
  object-fit: cover;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font: 700 2rem var(--font-heading);
}

.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 0.8fr);
  gap: 14px;
}

.panel {
  padding: 18px;
}

.panel-heading,
.dialog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

canvas {
  width: 100%;
  max-height: 280px;
}

.country-list,
.session-list,
.chat-transcript {
  display: grid;
  gap: 10px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 18px;
}

.pagination-button {
  min-width: 40px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 12px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.16);
  font-family: var(--font-heading);
  font-weight: 600;
}

.pagination-button:hover:not(:disabled),
.pagination-button.active {
  border-color: var(--accent-border);
  background: var(--accent);
  color: #fff;
}

.pagination-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.pagination-ellipsis {
  min-width: 24px;
  color: var(--muted);
  text-align: center;
}

.country-row,
.session-row,
.session-meta {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.16);
}

.country-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

.session-row {
  width: 100%;
  display: grid;
  grid-template-columns: 190px 70px 90px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  color: var(--text);
  text-align: left;
}

.session-row:hover {
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

.session-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 150px 150px 96px auto;
  gap: 10px;
  padding: 14px;
  margin-bottom: 14px;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 12px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
}

input:focus {
  outline: 2px solid var(--accent-border);
  border-color: var(--accent-border);
}

.session-dialog {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  background: var(--glass-bg), rgba(23, 23, 23, 0.94);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text);
  padding: 18px;
  overflow: auto;
}

.session-dialog::backdrop {
  background: rgba(0, 0, 0, 0.76);
  backdrop-filter: blur(8px);
}

.dialog-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.session-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 10px 12px;
  color: var(--muted);
  margin-bottom: 14px;
  font-size: 0.8rem;
}

.chat-transcript {
  overflow-x: hidden;
}

.message {
  width: min(84ch, 100%);
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-break: anywhere;
  line-height: 1.7;
}

.message.user {
  justify-self: end;
  border-color: var(--accent-border);
  background: var(--accent-dim);
}

.message.assistant {
  justify-self: start;
  background: rgba(255, 255, 255, 0.035);
}

.message-role {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-light);
  font: 600 0.625rem var(--font-heading);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  background: var(--card-solid);
  color: var(--text);
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  #signOut {
    margin-top: 0;
    margin-left: auto;
  }

  .metric-grid,
  .split-grid {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 680px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .metric-grid,
  .dashboard-hero,
  .split-grid,
  .search-bar {
    grid-template-columns: 1fr;
  }

  .dashboard-avatar {
    width: 84px;
    height: 84px;
  }

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

  .session-preview {
    white-space: normal;
  }
}
