:root {
  --bg: #f3f6fb;
  --surface: #fff;
  --text: #0f172a;
  --muted: #5b6b80;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --cyan: #06b6d4;
  --ink: #0f172a;
  --paper: #fbf7ee;
  --danger: #b42318;
  --ok: #10b981;
  --warn: #b54708;
  --radius: 18px;
  --radius-control: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Poppins, "Segoe UI", system-ui, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

[hidden] { display: none !important; }

.skip {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 20;
  transform: translateY(-140%);
  background: var(--ink);
  color: #fff;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  text-decoration: none;
}

.skip:focus { transform: none; }

code {
  font-family: var(--mono);
  font-size: 0.9em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; margin: 0.4rem 0 0; }
.ok { color: var(--ok); font-size: 0.9rem; }

.wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1.02;
}

.wordmark strong {
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--ink);
}

.wordmark em {
  font-style: normal;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(90deg, #2563eb 10%, #06b6d4 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand,
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.brand img,
.login-brand img { display: block; }

.login-brand .wordmark strong { font-size: 1.35rem; }
.login-brand .wordmark em { font-size: 1.15rem; }
.login-brand:hover { text-decoration: none; }

.login-wrap {
  height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  overflow: auto;
  background:
    radial-gradient(900px 420px at 12% -10%, rgba(37, 99, 235, 0.16), transparent 55%),
    radial-gradient(700px 380px at 100% 100%, rgba(6, 182, 212, 0.18), transparent 50%),
    #e7eef6;
}

.login-shell {
  width: min(1080px, 100%);
  min-height: min(680px, calc(100dvh - 2.5rem));
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(340px, 1.08fr);
  background: var(--paper);
  border-radius: 28px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 28px 70px rgba(15, 23, 42, 0.14);
  overflow: hidden;
}

.login-panel {
  display: flex;
  flex-direction: column;
  padding: 1.75rem 2.25rem 1.4rem;
  min-height: 100%;
}

.login-card {
  width: min(380px, 100%);
  margin: auto;
  animation: rise 0.7s var(--ease) both;
}

.login-card h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.1;
  text-wrap: balance;
}

.login-lead {
  margin: 0.55rem 0 1.35rem;
  max-width: 32ch;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.login-card label {
  margin-top: 0.85rem;
  color: #334155;
  font-weight: 500;
}

.login-card input {
  height: 52px;
  border-radius: 999px;
  padding: 0 1.1rem;
  background: #fff;
  border-color: #efe6d4;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.login-card button {
  width: 100%;
  height: 52px;
  margin-top: 1.25rem;
  border-radius: 999px;
  font-size: 1rem;
  background: linear-gradient(180deg, #3b82f6 0%, var(--accent) 100%);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.28);
}

.login-card button:hover {
  background: linear-gradient(180deg, #2563eb 0%, var(--accent-hover) 100%);
}

.login-legal {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
}

.login-legal a { color: #475569; }
.login-legal a:hover { color: var(--accent); }

.login-stage {
  padding: 0.85rem 0.85rem 0.85rem 0;
  display: flex;
}

.stage-frame {
  position: relative;
  flex: 1;
  border-radius: 22px;
  overflow: hidden;
  background: #123a86;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.stage-scene {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 280px at 78% 18%, rgba(255, 255, 255, 0.38), transparent 60%),
    radial-gradient(380px 320px at 18% 88%, rgba(16, 185, 129, 0.35), transparent 62%),
    linear-gradient(145deg, #1d4ed8 0%, #2563eb 38%, #06b6d4 100%);
}

.stage-scene::after {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  right: -40px;
  bottom: -70px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.stage-mark {
  position: absolute;
  width: 168px;
  height: 168px;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 18px 30px rgba(15, 23, 42, 0.28));
}

.stage-chip,
.stage-card,
.stage-faces {
  position: absolute;
  z-index: 2;
}

.stage-chip {
  top: 1.35rem;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.55rem 0.9rem 0.55rem 0.7rem;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.stage-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18);
}

.stage-card .stage-faces {
  position: static;
  margin-top: 0.8rem;
  display: flex;
}

.stage-faces span {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #fff;
  margin-left: -10px;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.16);
}

.stage-faces span:first-child { margin-left: 0; background: #0f172a; }
.stage-faces span:nth-child(2) { background: #06b6d4; }
.stage-faces span:nth-child(3) { background: #93c5fd; }

.stage-card {
  left: 1.15rem;
  bottom: 1.2rem;
  width: min(230px, 70%);
  background: rgba(255, 255, 255, 0.94);
  border-radius: 16px;
  padding: 0.9rem 1rem 1rem;
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.18);
}

.stage-card p {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

.stage-card h2 {
  margin: 0.15rem 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.stage-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100%;
  background: var(--bg);
}

.sidebar {
  background:
    radial-gradient(280px 180px at 0% 0%, rgba(6, 182, 212, 0.18), transparent 70%),
    var(--ink);
  color: #e8eef4;
  padding: 1.15rem 0.9rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  overflow: auto;
}

.sidebar .brand:hover { text-decoration: none; }

.sidebar .wordmark strong {
  color: #fff;
  font-size: 1.02rem;
}

.sidebar .wordmark em { font-size: 0.92rem; }

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.sidebar nav a {
  color: #d5e0ea;
  padding: 0.62rem 0.8rem;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 500;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-decoration: none;
}

.sidebar nav a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--cyan);
}

.sidebar-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  padding-top: 0.4rem;
}

.sidebar-terms {
  color: #93a4b5;
  font-size: 0.8rem;
  text-decoration: none;
}

.sidebar-terms:hover { color: #fff; }

.sidebar .btn-ghost {
  width: 100%;
  margin-top: 0.35rem;
  border-radius: 12px;
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar .btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

body.legal-page {
  height: auto;
  min-height: 100%;
  overflow: auto;
  background:
    radial-gradient(700px 280px at 0% 0%, rgba(37, 99, 235, 0.08), transparent 60%),
    var(--bg);
}

.legal {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.legal h1 {
  margin: 0 0 0.75rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.legal-brand { margin-bottom: 1.25rem; }
.legal-brand .wordmark strong { font-size: 1.15rem; }
.legal-brand .wordmark em { font-size: 1rem; }
.legal-brand:hover { text-decoration: none; }
.legal-back { margin: 0 0 1.25rem; }
.legal-body { line-height: 1.65; }
.legal-body p { margin: 0 0 0.9rem; }
.legal-body h2 {
  margin: 1.5rem 0 0.45rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.legal-body ul {
  margin: 0 0 0.9rem;
  padding-left: 1.2rem;
}
.legal-body li { margin: 0.25rem 0; }

.content {
  width: 100%;
  min-width: 0;
  padding: 1.6rem 1.85rem 2.6rem;
  overflow: auto;
  background:
    radial-gradient(720px 240px at 100% 0%, rgba(6, 182, 212, 0.1), transparent 60%),
    var(--bg);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
}

.card h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.grid {
  display: grid;
  gap: 1rem;
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.stat {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  gap: 0.2rem;
  min-height: 108px;
  justify-content: flex-end;
  padding-left: 1.35rem;
}

.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
}

.grid-3 .stat:nth-child(2)::before { background: var(--cyan); }
.grid-3 .stat:nth-child(3)::before { background: var(--ok); }

.stat .label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

.stat .value {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.72rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr { transition: background 0.2s var(--ease); }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-ok { background: #ecfdf3; color: #067647; }
.badge-off { background: #fef3f2; color: var(--danger); }
.badge-warn { background: #fffaeb; color: var(--warn); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 0.95rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

button:hover, .btn:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

button:active, .btn:active { transform: scale(0.98); }
button:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: #d7e2ec;
  border: 1px solid #334155;
}

.btn-ghost:hover { background: #1c2b3a; }

.btn-secondary {
  background: #eef3f8;
  color: var(--text);
}

.btn-secondary:hover { background: #e2eaf2; }

.btn-danger { background: #b42318; }
.btn-danger:hover { background: #912018; }
.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.82rem; border-radius: 10px; }

.actions { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; }

form.stack, .stack { display: grid; gap: 0.75rem; }

label {
  font-size: 0.82rem;
  font-weight: 500;
  display: block;
  margin-bottom: 0.3rem;
  color: #334155;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}

.check input { width: auto; margin-top: 0.2rem; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
select,
textarea {
  width: 100%;
  font: inherit;
  padding: 0.62rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

input::placeholder,
textarea::placeholder { color: #64748b; }

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16);
}

textarea {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
  resize: vertical;
}

textarea.prompt { min-height: 280px; }
textarea.json { min-height: 140px; }

.hint { font-size: 0.8rem; color: var(--muted); margin: 0.2rem 0 0; }

.tabs {
  display: flex;
  gap: 0.15rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tabs a, .tabs button {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.6rem 0.8rem;
  box-shadow: none;
}

.tabs a:hover, .tabs button:hover {
  background: transparent;
  color: var(--text);
}

.tabs a.active, .tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

.empty {
  padding: 1.75rem 1rem;
  text-align: center;
  color: var(--muted);
}

.flash {
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  margin-bottom: 0.85rem;
  font-weight: 500;
}

.flash-ok { background: #ecfdf3; color: #067647; }
.flash-err { background: #fef3f2; color: var(--danger); }

.assistant-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 1rem;
  align-items: start;
}

.playground-card {
  position: sticky;
  top: 0;
  min-height: 420px;
  max-height: calc(100vh - 8rem);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.playground-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.playground-log {
  flex: 1;
  overflow: auto;
  min-height: 240px;
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #f4f7fb;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.playground-empty { margin: auto; text-align: center; }

.playground-msg {
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.45;
}

.playground-msg.user {
  align-self: flex-end;
  background: #dbeafe;
  color: var(--ink);
  border-bottom-right-radius: 4px;
}

.playground-msg.user.pending {
  opacity: 0.72;
  border: 1px dashed #93c5fd;
}

.playground-status-msg {
  align-self: center;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.playground-msg.assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.playground-badge {
  align-self: flex-start;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}

.session-preview {
  max-width: 22rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.transcript-card { padding: 1rem; }
.transcript-log {
  max-height: min(70vh, 720px);
}

.session-meta p { margin: 0; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin: 0.35rem 0 0.85rem;
}

.pager-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.pager .btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.playground-badge-ok { background: #ecfdf3; color: #067647; }
.playground-badge-err { background: #fef3f2; color: var(--danger); }

.playground-composer {
  display: grid;
  gap: 0.5rem;
}

.playground-composer textarea {
  font-family: var(--sans);
  min-height: 72px;
  resize: vertical;
}

pre.muted {
  background: #f4f7fb;
  border-radius: 12px;
  padding: 0.85rem;
  overflow: auto;
}

@media (max-width: 960px) {
  .assistant-layout { grid-template-columns: 1fr; }
  .playground-card { position: static; max-height: none; }
}

@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; min-height: 0; }
  .login-stage { display: none; }
  .login-panel { padding: 1.35rem 1.15rem 1.15rem; }
  .login-card { margin: 1.5rem 0; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .sidebar nav a.active { box-shadow: inset 0 -2px 0 var(--cyan); }
  .sidebar-foot { width: 100%; align-items: center; }
  .sidebar .btn-ghost { width: auto; }
  .content { padding: 1rem; }
}

body.vincular-page {
  height: auto;
  min-height: 100%;
  overflow: auto;
}

.vincular-card {
  margin-top: 1.5rem;
}

.vincular-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.vincular-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 1rem;
}

.invite-box {
  display: grid;
  gap: 0.55rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #f8fafc;
}

.invite-box code {
  word-break: break-all;
  font-size: 0.82rem;
}
