/* Totenschloss: a dark, bone-and-ember palette for a late-night data crypt. */

:root {
  --bg: #0c0d10;
  --panel: #15171c;
  --panel-raised: #1d2027;
  --line: #2a2e38;
  --text: #e9e4d6;
  --muted: #8d8a80;
  --ember: #d99a3a;
  --ember-soft: rgba(217, 154, 58, 0.14);
  --bone: #c9c2ad;
  --danger: #e06a5d;
  --radius: 10px;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(217, 154, 58, 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(120, 70, 200, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 960px;
  margin: 0 auto;
}

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.current-user {
  color: var(--bone);
  font: 13px/1 var(--mono);
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--bone);
}

.sigil {
  color: var(--ember);
  font-size: 18px;
}

.tagline {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Log */

.log {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}

.intro {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.intro p {
  margin: 0 0 8px;
}

.intro p:last-child {
  margin-bottom: 0;
}

.hint code,
code {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ember);
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.msg .bubble {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}

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

.msg.user .bubble {
  max-width: 80%;
  background: var(--panel-raised);
  border-color: #353a46;
}

.msg.assistant .bubble {
  border-left: 3px solid var(--ember);
  max-width: 100%;
}

.msg.assistant.no-text .bubble {
  display: none;
}

.msg.pending .bubble {
  color: var(--muted);
  font-style: italic;
  border-left: 3px solid var(--line);
  animation: pulse 1.4s ease-in-out infinite;
}

.msg.error .bubble {
  color: #f6c3bc;
  border-left: 3px solid var(--danger);
  background: rgba(224, 106, 93, 0.08);
}

@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}

/* Query blocks */

.query {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.query summary {
  cursor: pointer;
  padding: 8px 12px;
  color: var(--bone);
  font-size: 13px;
  user-select: none;
  background: var(--ember-soft);
}

.query[open] summary {
  border-bottom: 1px solid var(--line);
}

.query .sql {
  margin: 0;
  padding: 10px 12px;
  font: 13px/1.5 var(--mono);
  color: var(--bone);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #101216;
}

.query .error-text {
  margin: 0;
  padding: 10px 12px;
  color: #f6c3bc;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font: 13px/1.4 var(--mono);
}

th,
td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel-raised);
  color: var(--ember);
  font-weight: 600;
}

td {
  color: var(--text);
}

td.null {
  color: var(--muted);
  font-style: italic;
}

tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.note {
  margin: 0;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

/* Composer */

.composer-wrap {
  border-top: 1px solid var(--line);
  padding: 12px 20px 18px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.suggestions:empty {
  display: none;
}

.chip {
  font: 13px/1.3 var(--sans);
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:hover {
  color: var(--text);
  border-color: var(--ember);
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  padding: 11px 14px;
  font: 15px/1.4 var(--sans);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

textarea::placeholder {
  color: #5f6270;
}

textarea:focus {
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--ember-soft);
}

button {
  font: 14px/1 var(--sans);
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 11px 16px;
  color: var(--text);
  background: var(--panel-raised);
}

button:hover:not(:disabled) {
  border-color: var(--ember);
}

button:disabled {
  opacity: 0.5;
  cursor: progress;
}

button.primary {
  background: var(--ember);
  border-color: var(--ember);
  color: #1a1206;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #e6a94c;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  font-size: 13px;
}

/* Forms and dialogs */

input,
select {
  width: 100%;
  padding: 10px 12px;
  font: 15px/1.4 var(--sans);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--ember);
  box-shadow: 0 0 0 3px var(--ember-soft);
}

input::placeholder {
  color: #5f6270;
}

.muted {
  color: var(--muted);
}

.form-error {
  margin: 0;
  padding: 9px 11px;
  border-radius: 8px;
  background: rgba(224, 106, 93, 0.1);
  border: 1px solid rgba(224, 106, 93, 0.35);
  color: #f6c3bc;
  font-size: 13px;
}

/* Auth screens */

.auth-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.auth-sigil {
  margin: 0;
  text-align: center;
  color: var(--ember);
  font-size: 28px;
}

.auth-card h2 {
  margin: 6px 0 4px;
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.04em;
}

.auth-subtitle {
  margin: 0 0 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.auth-form button.primary {
  width: 100%;
  margin-top: 4px;
}

.auth-hint {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.auth-hint a {
  color: var(--ember);
}

/* Invite dialog */

.dialog {
  width: min(640px, calc(100% - 32px));
  max-height: min(82vh, 720px);
  overflow: auto;
  padding: 22px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

.dialog::backdrop {
  background: rgba(5, 6, 8, 0.72);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.dialog h3 {
  margin: 22px 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.invite-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.invite-form .field {
  max-width: 180px;
}

.invite-result {
  padding: 12px;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.invite-link {
  flex: 1;
  min-width: 0;
  font: 12px/1.4 var(--mono);
}

.invite-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #101216;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.invite-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.invite-info .muted {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.badge {
  align-self: flex-start;
  padding: 2px 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.badge.active {
  color: var(--ember);
  border-color: rgba(217, 154, 58, 0.4);
  background: var(--ember-soft);
}

.badge.used {
  color: #9fbf9a;
  border-color: rgba(120, 180, 110, 0.35);
}

/* Small screens */

@media (max-width: 600px) {
  .topbar {
    padding: 12px 14px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .current-user {
    display: none;
  }

  .auth-view {
    padding: 14px;
  }

  .auth-card {
    padding: 22px;
  }

  .tagline {
    display: none;
  }

  .log {
    padding: 16px 12px 8px;
  }

  .composer-wrap {
    padding: 10px 12px 14px;
  }

  .msg.user .bubble {
    max-width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .log {
    scroll-behavior: auto;
  }

  .msg.pending .bubble {
    animation: none;
  }
}
