:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #111827;
  --muted: #64748b;
  --line: #d8dee6;
  --brand: #0f766e;
  --brand-2: #0d9488;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #047857;
  --shadow: 0 10px 24px rgba(15, 23, 42, .08);
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #9aa6b2;
}

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

button.warn {
  background: #fff7ed;
  border-color: #fed7aa;
  color: var(--warn);
}

button.ghost {
  background: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

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

label span {
  color: var(--muted);
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 18px;
}

h4 {
  font-size: 15px;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  max-height: 420px;
  overflow: auto;
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 700;
}

.auth-shell {
  width: min(440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 42px 18px;
  display: grid;
  align-content: center;
  gap: 24px;
}

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

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #111827;
  color: white;
  font-weight: 800;
}

.panel,
.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.stepper {
  display: flex;
  gap: 8px;
}

.dot {
  width: 26px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.dot.active {
  background: var(--brand);
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 248, .94);
  backdrop-filter: blur(12px);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.user-chip button {
  min-height: 34px;
  padding: 0 10px;
}

main {
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.page {
  display: grid;
  gap: 16px;
}

.hero-band {
  min-height: 132px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-radius: 8px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
}

.hero-band .muted,
.hero-band .eyebrow {
  color: #cbd5e1;
}

.hero-band h3 {
  margin-top: 4px;
  font-size: 30px;
}

.hero-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  min-width: 190px;
}

.hero-actions button {
  width: 100%;
}

.assistant-cta {
  width: 100%;
  min-height: 88px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  text-align: left;
  background: var(--surface);
  border: 1px solid #99f6e4;
  box-shadow: var(--shadow);
}

.assistant-cta strong {
  display: block;
  margin-bottom: 5px;
  font-size: 18px;
}

.assistant-cta small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.assistant-cta-arrow {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--brand);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.assistant-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.assistant-messages {
  display: grid;
  gap: 10px;
  min-height: 220px;
  align-content: start;
}

.assistant-message {
  max-width: min(720px, 100%);
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
}

.assistant-message.user {
  justify-self: end;
  background: #dcfce7;
}

.assistant-message.assistant {
  justify-self: start;
}

.assistant-message p {
  line-height: 1.42;
}

.assistant-links,
.assistant-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.assistant-links a {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--brand);
  background: white;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.assistant-actions button {
  min-height: 38px;
}

.assistant-progress {
  display: grid;
  gap: 7px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 13px;
}

.assistant-progress span::before {
  content: "";
  width: 7px;
  height: 7px;
  display: inline-block;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--brand);
  animation: assistant-pulse 1.1s ease-in-out infinite;
}

.assistant-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

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

@keyframes assistant-pulse {
  0%, 100% { opacity: .35; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1); }
}

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

.status-card,
.list-item,
.banner,
.panel {
  padding: 14px;
}

.status-card,
.list-item,
.banner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-card {
  display: grid;
  gap: 9px;
}

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

.pill {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  background: #dcfce7;
  color: var(--ok);
}

.pill.warn {
  background: #fef3c7;
  color: var(--warn);
}

.pill.danger {
  background: #fee2e2;
  color: var(--danger);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.chart {
  min-height: 150px;
  display: flex;
  align-items: end;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.bar {
  flex: 1;
  min-width: 5px;
  display: grid;
  grid-template-rows: 18px 1fr 12px;
  gap: 2px;
  height: 132px;
}

.bar-count {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  min-height: 14px;
}

.bar-track {
  display: flex;
  align-items: end;
}

.bar-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 5px 5px 0 0;
  background: var(--brand-2);
}

.bar-label {
  font-size: 9px;
  color: var(--muted);
  text-align: center;
}

.split-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.split-actions.compact {
  grid-template-columns: 1fr 1fr;
}

.inline-create {
  display: grid;
  grid-template-columns: minmax(150px, 220px) auto;
  gap: 8px;
  align-items: center;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: grid;
  gap: 9px;
}

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

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.diagnostic-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  min-height: 28px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab.active {
  border-color: var(--brand);
  color: var(--brand);
  font-weight: 700;
}

.guide {
  display: grid;
  gap: 10px;
}

.guide-step {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.step-num {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-2);
  font-weight: 800;
}

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

.admin-grid .panel {
  display: grid;
  gap: 11px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check input {
  width: auto;
}

.guide-editor-panel {
  display: grid;
  gap: 12px;
}

.guide-editor-controls {
  display: grid;
  grid-template-columns: minmax(160px, 260px) minmax(140px, 220px);
  gap: 10px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.editor-toolbar button {
  min-height: 34px;
  padding: 0 10px;
  background: white;
}

.guide-editor {
  min-height: 260px;
  max-height: 620px;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  line-height: 1.5;
}

.guide-editor:focus {
  outline: 2px solid rgba(13, 148, 136, .25);
  border-color: var(--brand);
}

.guide-editor p,
.guide-preview p {
  margin: 0 0 10px;
}

.guide-editor h3,
.guide-preview h3 {
  margin: 12px 0 8px;
}

.guide-editor img,
.guide-preview img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.guide-editor img.selected-guide-image {
  outline: 3px solid rgba(13, 148, 136, .32);
  outline-offset: 3px;
  cursor: se-resize;
}

.guide-editor a,
.guide-preview a {
  color: var(--brand);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.image-tools {
  display: grid;
  grid-template-columns: max-content minmax(160px, 1fr) 48px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.image-tools input {
  min-height: 28px;
}

.guide-preview {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  transform: translateX(-50%);
  width: min(1060px, 100%);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}

.bottom-nav button {
  min-height: 48px;
  padding: 0 6px;
  font-size: 12px;
  border-color: transparent;
  background: transparent;
}

.bottom-nav button.active {
  background: var(--surface-2);
  color: var(--brand);
  font-weight: 800;
}

dialog {
  width: min(520px, calc(100% - 24px));
  border: 0;
  padding: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .3);
}

dialog::backdrop {
  background: rgba(15, 23, 42, .45);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.dialog-card.wide {
  width: min(760px, 100%);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  z-index: 30;
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 24px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: white;
  box-shadow: var(--shadow);
}

.banner.info {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.banner.warn {
  border-color: #fed7aa;
  background: #fff7ed;
}

.banner.danger {
  border-color: #fecaca;
  background: #fef2f2;
}

@media (max-width: 780px), (hover: none) and (pointer: coarse) {
  .topbar {
    align-items: start;
  }

  .user-chip {
    display: grid;
    justify-items: end;
  }

  .hero-band {
    display: grid;
  }

  .hero-actions {
    min-width: 0;
  }

  .status-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .guide-editor-controls {
    grid-template-columns: 1fr;
  }

  .split-actions {
    grid-template-columns: 1fr;
  }

  .assistant-cta {
    display: grid;
  }

  .assistant-cta-arrow {
    justify-content: center;
  }

  .assistant-form {
    grid-template-columns: 1fr;
  }

  .inline-create {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .bottom-nav {
    overflow-x: auto;
  }

  .bottom-nav button {
    min-width: 76px;
  }
}
