:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #182033;
  --muted: #687386;
  --line: #dfe5ee;
  --blue: #1d4ed8;
  --cyan: #0891b2;
  --green: #0f9f6e;
  --red: #d12f45;
  --yellow: #b7791f;
  --shadow: 0 18px 50px rgba(31, 42, 68, 0.10);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(135deg, rgba(24, 32, 51, 0.94), rgba(20, 60, 92, 0.88)),
    url("https://images.unsplash.com/photo-1551434678-e076c223a692?auto=format&fit=crop&w=1800&q=80") center/cover;
}

.login-panel {
  width: min(1060px, 100%);
  min-height: 620px;
  display: grid;
  grid-template-columns: 1.1fr 420px;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.64);
  box-shadow: var(--shadow);
}

.login-copy {
  padding: 58px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, #fff, #eef5ff);
}

.login-copy h1 {
  max-width: 560px;
  margin: 72px 0 16px;
  font-size: 44px;
  line-height: 1.1;
}

.login-copy p { max-width: 520px; color: var(--muted); font-size: 17px; line-height: 1.8; }

.login-card {
  padding: 52px 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.login-card h2 { margin: 6px 0 0; font-size: 28px; }

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

.brand b { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.brand.large b { font-size: 18px; }

.brand-mark, .agent-icon {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.metric-strip span {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
}

.metric-strip b { display: block; color: var(--text); font-size: 22px; margin-bottom: 4px; }

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.field.plain input, .field.plain textarea, .field.plain select, .input-wrap {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fff;
}

.field.plain input, .field.plain textarea, .field.plain select {
  padding: 10px 12px;
  color: var(--text);
}

.field textarea { min-height: 92px; resize: vertical; }
.field .prompt-input { min-height: 220px; line-height: 1.7; }

.input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
}

.input-wrap input {
  border: 0;
  outline: 0;
  flex: 1;
  min-width: 0;
}

.primary-btn, .secondary-btn, .card-action {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  padding: 0 16px;
  font-weight: 750;
}

.primary-btn {
  color: #fff;
  background: #182033;
}

.primary-btn:disabled { opacity: 0.56; cursor: not-allowed; }
.primary-btn.compact { min-height: 36px; padding: 0 14px; }

.secondary-btn {
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
}

.secondary-btn.full { width: 100%; }

.error-banner, .success-banner {
  padding: 12px 14px;
  border: 1px solid rgba(209, 47, 69, 0.22);
  background: rgba(209, 47, 69, 0.08);
  color: var(--red);
  font-size: 13px;
}

.success-banner {
  border-color: rgba(15, 159, 110, 0.24);
  background: rgba(15, 159, 110, 0.09);
  color: var(--green);
}

.error-banner.inline { margin: 0 18px; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  background: #101827;
  color: #f8fafc;
}

.sidebar .brand small, .sidebar .user-meta span { color: #99a6ba; }

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

.nav-item {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  color: #cbd5e1;
}

.nav-item span {
  white-space: nowrap;
  word-break: keep-all;
}

.nav-item.active, .nav-item:hover {
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
}

.sidebar-user {
  margin-top: auto;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 34px;
  gap: 10px;
  align-items: center;
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: #23314a;
  font-weight: 800;
}

.user-meta { min-width: 0; }
.user-meta strong, .user-meta span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 86px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar h1 { margin: 8px 0 0; font-size: 28px; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill, .tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.page-stack {
  display: grid;
  gap: 18px;
}

.preview-view {
  display: none !important;
}

.preview-view.active {
  display: grid !important;
}

.hero-band {
  min-height: 188px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 30px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.96), rgba(245,249,255,0.88)),
    url("https://images.unsplash.com/photo-1552664730-d307ca884978?auto=format&fit=crop&w=1600&q=80") center/cover;
  border: 1px solid var(--line);
}

.hero-band.admin {
  background:
    linear-gradient(90deg, rgba(255,255,255,0.98), rgba(238,247,244,0.9)),
    url("https://images.unsplash.com/photo-1556761175-b413da4baf72?auto=format&fit=crop&w=1600&q=80") center/cover;
}

.hero-band h2 { max-width: 760px; margin: 8px 0; font-size: 32px; }
.hero-band p { max-width: 740px; margin: 0; color: var(--muted); line-height: 1.8; }

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

.kpi {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 2px 12px;
  align-items: center;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
}

.kpi svg, .kpi > span:first-child { grid-row: span 2; color: var(--blue); }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi b { font-size: 24px; }

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

.agent-card {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: #fff;
  border: 1px solid var(--line);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.agent-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: rgba(29, 78, 216, 0.28);
}

.agent-card h3 { margin: 0 0 8px; font-size: 20px; }
.agent-card p { margin: 0; color: var(--muted); line-height: 1.7; }
.card-action { margin-top: auto; width: 100%; color: var(--blue); background: #eef5ff; }

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

.conversation-panel, .chat-main, .panel {
  background: #fff;
  border: 1px solid var(--line);
}

.conversation-panel {
  min-height: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.conversation-list {
  overflow: auto;
  display: grid;
  gap: 8px;
}

.conversation-item, .row-button {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  text-align: left;
  padding: 12px;
}

.conversation-item.active, .row-button.active {
  border-color: rgba(29, 78, 216, 0.34);
  background: #eef5ff;
}

.conversation-item span, .conversation-item small, .row-button small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item small, .row-button small { color: var(--muted); margin-top: 4px; }

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

.chat-head {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 36px;
  gap: 12px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.chat-head h2 { margin: 0; font-size: 20px; }
.chat-head p { margin: 5px 0 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages {
  min-height: 0;
  overflow: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-empty {
  margin: auto;
  max-width: 520px;
  text-align: center;
  color: var(--muted);
}

.chat-empty h3 { color: var(--text); margin-bottom: 8px; }

.chat-bubble {
  max-width: min(780px, 88%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.chat-bubble.user {
  align-self: flex-end;
  color: #fff;
  background: #182033;
  border-color: #182033;
}

.chat-bubble.assistant { align-self: flex-start; background: var(--panel-soft); }
.bubble-role { font-size: 12px; font-weight: 800; color: var(--cyan); margin-bottom: 8px; }
.chat-bubble.user .bubble-role { color: #b7d9ff; }
.chat-bubble pre { margin: 0; white-space: pre-wrap; word-break: break-word; line-height: 1.75; font-family: inherit; }

.copy-btn {
  margin-top: 12px;
  display: inline-flex;
  gap: 5px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 5px 8px;
  font-size: 12px;
}

.composer {
  margin: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.composer textarea {
  min-height: 72px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  padding: 12px;
}

.composer-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.icon-btn.danger:hover { color: var(--red); border-color: rgba(209,47,69,.4); }

.admin-grid {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel { padding: 18px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 { margin: 0; font-size: 22px; }
.table-list { display: grid; gap: 8px; }

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

.tag.active, .tag.success { color: var(--green); background: rgba(15,159,110,.1); border-color: rgba(15,159,110,.2); }
.tag.draft { color: var(--yellow); background: rgba(183,121,31,.1); border-color: rgba(183,121,31,.22); }
.tag.disabled, .tag.error { color: var(--red); background: rgba(209,47,69,.09); border-color: rgba(209,47,69,.2); }

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

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

.admin-entry {
  display: grid;
  gap: 10px;
  min-height: 170px;
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
}

.admin-entry svg { width: 24px; height: 24px; color: var(--blue); }
.admin-entry p { margin: 0; color: var(--muted); line-height: 1.6; }

.inline-edit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 8px;
}

.data-row, .usage-head, .usage-row {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.data-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

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

.usage-table { overflow: auto; }
.usage-head, .usage-row { grid-template-columns: 110px 110px 140px minmax(160px, 1fr) 180px; min-width: 760px; }
.usage-head { color: var(--muted); font-size: 12px; font-weight: 800; }
.usage-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  padding: 26px;
  background: #fff;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1080px) {
  .agent-grid, .admin-entry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .login-page { padding: 16px; }
  .login-panel { grid-template-columns: 1fr; }
  .login-copy { display: none; }
  .login-card { border-left: 0; padding: 32px 22px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    gap: 14px;
  }
  .nav {
    display: flex;
    flex: 0 0 auto;
  }
  .nav-item {
    flex: 0 0 auto;
    min-width: max-content;
    padding: 0 14px;
  }
  .sidebar-user { margin-left: auto; margin-top: 0; min-width: 210px; }
  .main { padding: 16px; }
  .topbar { min-height: auto; margin-bottom: 16px; }
  .topbar-actions { display: none; }
  .hero-band { flex-direction: column; align-items: flex-start; padding: 22px; }
  .hero-band h2 { font-size: 25px; }
  .kpi-grid, .agent-grid, .form-grid, .admin-entry-grid { grid-template-columns: 1fr; }
  .chat-layout {
    height: auto;
    grid-template-columns: 1fr;
  }
  .conversation-panel { max-height: 210px; }
  .chat-main { min-height: 620px; }
  .composer { grid-template-columns: 1fr; }
  .chat-bubble { max-width: 96%; }
}
