:root {
  color-scheme: light;
  font-family: "Segoe UI", "Trebuchet MS", Arial, sans-serif;
  --ink: #0a2348;
  --muted: #536985;
  --line: rgba(25, 99, 215, 0.16);
  --line-strong: rgba(0, 109, 255, 0.32);
  --surface: #f8fbff;
  --surface-soft: #eef6ff;
  --panel: #ffffff;
  --accent: #006dff;
  --accent-strong: #0054e9;
  --accent-soft: #dff2ff;
  --cyan: #19d8ff;
  --navy: #071b46;
  --navy-deep: #031c42;
  --warn: #9a5b00;
  --error: #8a1f2d;
  --shadow-soft: 0 16px 34px rgba(29, 82, 145, 0.1);
  --shadow-tight: 0 10px 22px rgba(13, 63, 128, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
  color: var(--ink);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
textarea:disabled,
input:disabled,
select:disabled {
  cursor: wait;
  opacity: 0.68;
}

.shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
  padding: 24px;
  background:
    linear-gradient(180deg, #05255d 0%, #031c42 100%);
  color: #f4f9ff;
  border-right: 1px solid rgba(25, 216, 255, 0.12);
  box-shadow: 18px 0 42px rgba(4, 22, 56, 0.14);
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(25, 216, 255, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(135deg, #006dff 0%, #19d8ff 100%);
  color: #ffffff;
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(0, 109, 255, 0.28);
}

.brand strong {
  color: #ffffff;
}

.brand span,
.session span {
  display: block;
  color: rgba(237, 246, 255, 0.72);
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.nav-item,
.ghost {
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(237, 246, 255, 0.76);
  text-align: left;
}

.nav-item.active,
.nav-item:hover,
.ghost:hover {
  border-color: rgba(25, 216, 255, 0.2);
  background: rgba(25, 216, 255, 0.12);
  color: #fff;
}

.session {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

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

.auth-panel {
  display: grid;
  place-items: center;
}

.auth-box {
  width: 100%;
  max-width: 420px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.12;
}

h1 {
  margin-bottom: 18px;
  font-size: 34px;
}

h2 {
  font-size: 24px;
}

h3 {
  margin-bottom: 14px;
  font-size: 17px;
}

.stack {
  display: grid;
  gap: 14px;
}

.stack.compact {
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--line-strong);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 109, 255, 0.12);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
  align-items: center;
}

.page-filter {
  margin-bottom: 14px;
}

.pagination-row {
  display: grid;
  grid-template-columns: auto minmax(110px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.pagination-row span {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.compact-pagination {
  margin-top: 10px;
}

.primary,
.secondary {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 700;
}

.primary {
  border: 1px solid rgba(73, 143, 255, 0.42);
  background: linear-gradient(135deg, #0054e9 0%, #087bff 100%);
  color: #fff;
  box-shadow: 0 12px 24px rgba(0, 109, 255, 0.18);
}

.primary:hover {
  background: linear-gradient(135deg, #0049cc 0%, #006dff 100%);
}

.secondary {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  color: #0f4f99;
}

.secondary:hover {
  border-color: var(--line-strong);
  background: #eef6ff;
}

.message {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--error);
}

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

.view[hidden],
.admin-only[hidden],
[hidden] {
  display: none !important;
}

.chat-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  height: calc(100vh - 112px);
}

.history-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  height: calc(100vh - 112px);
}

.history-list-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.conversation-list,
.conversation,
.admin-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-tight);
}

.conversation-list {
  overflow: auto;
  padding: 8px;
}

.conversation-item {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.conversation-item.active,
.conversation-item:hover {
  background: var(--surface-soft);
  color: #075ecf;
}

.conversation-item span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.conversation {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
}

.history-title {
  max-height: 112px;
  overflow: auto;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-weight: 700;
}

.history-conversation {
  grid-template-rows: auto minmax(0, 1fr);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 18px;
}

.bubble {
  max-width: min(760px, 92%);
  padding: 12px 14px;
  border-radius: 8px;
  background: #f2f7fc;
  white-space: pre-wrap;
}

.bubble.assistant {
  align-self: flex-start;
  background: #eef6ff;
  border: 1px solid rgba(0, 109, 255, 0.12);
}

.bubble.thinking {
  color: #075ecf;
}

.bubble.thinking::after {
  content: "";
  display: inline-block;
  width: 1.4em;
  text-align: left;
  animation: thinkingDots 1.1s steps(4, end) infinite;
}

.bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #0054e9 0%, #087bff 100%);
  color: #fff;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.stream-metrics {
  min-height: 28px;
  padding: 0 14px 12px;
  color: var(--muted);
  font-size: 12px;
}

.starter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 12px;
}

.starter {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: #0f4f99;
  font-size: 13px;
  font-weight: 700;
}

.starter:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.admin-section {
  padding: 18px;
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.user-filter-row {
  margin-top: 16px;
}

.list-info {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.list-item,
.metric {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.prompt-info {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: #075ecf;
  font-size: 13px;
}

.prompt-version {
  width: 100%;
  color: var(--ink);
  text-align: left;
}

.inline-action {
  margin-top: 8px;
  margin-right: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #0f4f99;
  font-size: 13px;
}

.inline-action.danger {
  color: var(--error);
}

.reset-form {
  margin-top: 12px;
}

.form-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.permissions-list {
  display: grid;
  gap: 8px;
}

.permission-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.permission-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.list-item span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

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

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #031c42;
  color: #fff;
  box-shadow: 0 16px 40px rgba(3, 28, 66, 0.24);
}

@keyframes thinkingDots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75%,
  100% {
    content: "...";
  }
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    align-content: start;
    min-height: auto;
  }

  .sidebar {
    align-self: start;
    height: auto;
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 14px;
    padding: 14px 18px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .nav {
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  }

  .session {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-top: 0;
    align-items: center;
  }

  .chat-layout,
  .history-layout,
  .admin-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .conversation {
    min-height: 460px;
  }

  .conversation-list {
    max-height: 300px;
  }

  .chat-layout .conversation {
    order: -1;
  }

  .chat-layout .conversation-list {
    max-height: 240px;
  }
}

@media (max-width: 640px) {
  .panel,
  .workspace {
    padding: 18px;
  }

  .auth-box {
    width: min(100%, calc(100vw - 48px));
  }

  .sidebar {
    padding: 12px;
  }

  .brand {
    gap: 10px;
  }

  .nav {
    display: flex;
    gap: 8px;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item,
  .ghost {
    flex: 0 0 auto;
    min-width: 108px;
    min-height: 38px;
    padding: 8px 10px;
  }

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

  .chat-layout .conversation {
    grid-template-rows: minmax(160px, 1fr) auto auto auto;
    height: 520px;
    min-height: 0;
  }

  .toolbar {
    display: grid;
  }

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

  .field-grid {
    grid-template-columns: 1fr;
  }

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