:root {
  --md-sys-color-primary: #0b57d0;
  --md-sys-color-primary-container: #d3e3fd;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-surface-container: #f8fafd;
  --md-sys-color-surface-container-low: #f8fafd;
  --md-sys-color-surface-container-high: #eef3fc;
  --md-sys-color-outline: #d5d9e3;
  --md-sys-color-text: #1f1f1f;
  --md-sys-color-on-surface: #1f1f1f;
  --md-sys-color-on-surface-variant: #4f5561;
  --md-sys-color-muted: #4f5561;
  --md-sys-color-secondary-container: #eef3fc;
  --md-sys-color-tertiary-container: #eef3fc;
  --radius-small: 10px;
  --radius-medium: 18px;
  --radius-large: 24px;
  --shadow-1: 0 2px 6px rgba(17, 24, 39, 0.12);
  --shadow-2: 0 6px 16px rgba(17, 24, 39, 0.12);
  --shadow-3: 0 12px 28px rgba(17, 24, 39, 0.16);
}

* {
  box-sizing: border-box;
  font-family: "Google Sans Text", system-ui, sans-serif;
}

body {
  margin: 0;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
}

.login-page {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--md-sys-color-surface-container);
}

.auth-card {
  width: min(460px, 100%);
  background: var(--md-sys-color-surface);
  border-radius: 16px;
  border: 1px solid var(--md-sys-color-outline);
  box-shadow: var(--shadow-3);
  padding: 36px;
  text-align: center;
}

.auth-logo {
  height: 120px;
  width: auto;
  object-fit: contain;
  margin-bottom: 12px;
}

.auth-title {
  font-size: 21px;
  font-weight: 700;
  color: var(--md-sys-color-text);
  margin: 0 0 8px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--md-sys-color-on-surface-variant);
  margin: 0 0 20px;
}

.auth-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-text);
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow-1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.auth-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.16);
}

.google-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
}

.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 32px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 18px 24px;
  background: var(--md-sys-color-surface);
  border-radius: var(--radius-large);
  border: 1px solid var(--md-sys-color-outline);
  box-shadow: var(--shadow-2);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.topbar-title {
  font-weight: 500;
  font-size: 1.25rem;
  color: var(--md-sys-color-text);
}

.topbar-center {
  display: flex;
  justify-content: center;
}

.topbar-context {
  background: var(--md-sys-color-surface-container-low);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--md-sys-color-text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.topbar-pill {
  background: var(--md-sys-color-surface-container-low);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  margin-top: 16px;
}

.left-rail {
  background: var(--md-sys-color-surface);
  border-radius: var(--radius-large);
  padding: 24px;
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-3);
  border: 1px solid var(--md-sys-color-outline);
}

.left-rail-icons {
  display: flex;
  gap: 8px;
}

.left-rail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.left-rail-title {
  font-weight: 600;
}

.chat-search {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline);
}

.chat-search:focus-within {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(11, 87, 208, 0.15);
}

.chat-search .search-icon {
  font-family: "Material Symbols Outlined", sans-serif;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
  font-size: 18px;
  color: var(--md-sys-color-on-surface-variant);
}

.chat-search input {
  width: 100%;
  border: none;
  outline: none;
  padding: 0;
  background: transparent;
  font-size: 0.9rem;
}

.chat-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-empty {
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface-variant);
  padding: 8px 4px;
}

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

.chat-item {
  flex: 1;
  background: transparent;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 0.92rem;
  color: var(--md-sys-color-on-surface-variant);
}

.chat-item.active {
  background: var(--md-sys-color-primary-container);
  border-color: var(--md-sys-color-outline);
  font-weight: 500;
  color: var(--md-sys-color-text);
}

.chat-panel {
  background: var(--md-sys-color-surface);
  border-radius: var(--radius-large);
  padding: 24px;
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  width: 100%;
  box-shadow: var(--shadow-3);
  border: 1px solid var(--md-sys-color-outline);
  position: relative;
}

.chat-panel.full-width {
  flex: 1 1 auto;
  margin-top: 16px;
}

.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 24px;
  padding-bottom: 120px;
  overflow-y: auto;
  max-height: 70vh;
}

.chat-messages::after {
  content: "";
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  display: block;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 1)
  );
}

.message {
  display: flex;
  flex-direction: column;
}

.message.user {
  align-items: flex-end;
}

.message .bubble {
  max-width: 80%;
  padding: 14px 18px 12px;
  border-radius: 16px 16px 16px 4px;
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  white-space: pre-wrap;
  position: relative;
  line-height: 1.35;
  box-shadow: var(--shadow-1);
}

.message .bubble.status-bubble {
  color: var(--md-sys-color-on-surface-variant);
  font-style: italic;
}

.message .bubble.typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.message .bubble p {
  margin: 0 !important;
}

.message .bubble ul,
.message .bubble ol {
  margin: 0 0 0 1rem;
}

.message.user .bubble {
  background: var(--md-sys-color-primary-container);
  border-radius: 16px 16px 4px 16px;
  padding-bottom: 18px;
}

.message .bubble.editing {
  outline: 2px solid rgba(11, 87, 208, 0.35);
}

.message-edit {
  align-self: flex-end;
  margin-top: 4px;
  font-size: 16px;
  opacity: 0.7;
}

.message-actions {
  position: absolute;
  top: 6px;
  right: 6px;
}

.chat-input-wrap {
  position: sticky;
  bottom: 0;
  background: var(--md-sys-color-surface);
  padding-top: 8px;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  background: var(--md-sys-color-surface);
}

#chat-input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline);
  padding: 10px 16px;
  background: var(--md-sys-color-surface-container-low);
  font-size: 1rem;
}

.chat-options {
  position: sticky;
  bottom: 0;
  background: var(--md-sys-color-surface);
  padding-bottom: 8px;
  margin-top: 4px;
}

.pill-button {
  border: 1px solid var(--md-sys-color-primary);
  border-radius: 999px;
  background: var(--md-sys-color-primary);
  color: #ffffff;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pill-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.16);
}

.icon-button {
  font-family: "Material Symbols Outlined", sans-serif;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--md-sys-color-on-surface-variant);
}

.dropdown {
  position: relative;
}

.dropdown-content {
  display: none;
  position: absolute;
  right: -8px;
  background: var(--md-sys-color-surface);
  border-radius: 12px;
  box-shadow: none;
  padding: 8px;
  min-width: 160px;
  top: 28px;
  z-index: 1000;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-content a {
  display: block;
  padding: 8px;
  text-decoration: none;
  color: var(--md-sys-color-on-surface);
}

.code-block {
  background: var(--md-sys-color-surface);
  border-radius: var(--radius-medium);
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--md-sys-color-outline);
  box-shadow: var(--shadow-2);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-medium);
  overflow: hidden;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--md-sys-color-outline);
  padding: 8px;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--md-sys-color-muted);
}

.metric-card {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-large);
  padding: 20px;
  box-shadow: var(--shadow-1);
  margin-bottom: 16px;
}

.source-list {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface-variant);
}

.source-link {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.form-row input,
.form-row select {
  border-radius: var(--radius-medium);
  border: 1px solid var(--md-sys-color-outline);
  padding: 8px 10px;
  background: var(--md-sys-color-surface-container-low);
}

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

.permission-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--radius-large);
  padding: 20px;
  border: 1px solid var(--md-sys-color-outline);
  box-shadow: var(--shadow-2);
}

.status-banner {
  background: var(--md-sys-color-secondary-container);
  border-radius: var(--radius-medium);
  padding: 8px 12px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-1);
  border: 1px solid var(--md-sys-color-outline);
}

.prompt-textarea {
  width: 100%;
  border-radius: var(--radius-medium);
  border: 1px solid var(--md-sys-color-outline);
  padding: 12px 14px;
  background: var(--md-sys-color-surface);
  font-family: "Google Sans Text", system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.4;
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.search-row input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline);
  padding: 8px 12px;
  background: var(--md-sys-color-surface-container-low);
}

.pagination {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.source-panel {
  margin-top: 8px;
  background: var(--md-sys-color-surface);
  border-radius: var(--radius-medium);
  padding: 8px 12px;
  border: 1px solid var(--md-sys-color-outline);
}

.source-panel summary {
  cursor: pointer;
  font-weight: 500;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.source-panel summary::before {
  content: "expand_more";
  font-family: "Material Symbols Outlined", sans-serif;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 20;
  font-size: 18px;
}

.source-panel[open] summary::before {
  content: "expand_less";
}

.source-list div {
  padding: 6px 0;
  border-top: 1px solid #ececec;
}
