/* ═══════════════════════════════════════════════════════════
   AnalAIser — app + report CSS override layer
   Built on top of senseability.main.css (design tokens).
   ═══════════════════════════════════════════════════════════ */

/* ── Topbar / chrome ── */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 2rem;
  background: var(--navy);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-topbar a { color: #fff; }
.app-topbar__brand { display: flex; flex-direction: column; gap: 2px; }
.app-topbar__brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.app-topbar__brand-logo {
  height: 28px;
  width: auto;
  max-height: 28px;
  max-width: 120px;
  display: block;
  object-fit: contain;
}
.app-topbar__brand-name {
  font-weight: 800;
  font-size: 1.4rem;
  letter-spacing: -.02em;
  color: #fff;
  line-height: 1;
}
.app-topbar__brand-accent { color: var(--orange); }
.app-topbar__sub {
  font-size: .7rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255,255,255,.6);
}
.app-topbar__nav { display: flex; gap: 1.25rem; }
.app-topbar__nav a {
  font-size: .9rem;
  font-weight: 600;
  padding: .35rem .2rem;
  border-bottom: 2px solid transparent;
}
.app-topbar__nav a:hover { border-color: var(--orange); }
.app-topbar__user {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .85rem;
  color: rgba(255,255,255,.8);
}

/* ── Main / footer ── */
.app-main { min-height: calc(100vh - 200px); padding-bottom: 4rem; }
.app-footer {
  background: var(--navy);
  color: rgba(255,255,255,.7);
  padding: 1.5rem 2rem;
  font-size: .85rem;
}
.app-footer__inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.app-footer__links a { color: var(--orange-lt); }

/* ── Hero (dashboard) ── */
.hero--navy {
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
  color: #fff;
  padding: 5rem 2rem 4.5rem;
}
.hero__inner { max-width: 800px; margin: 0 auto; }
.hero__inner h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  line-height: 1.1;
  margin-bottom: 1rem;
}
.hero__inner .hl-orange { color: var(--orange); }
.hero__lede {
  font-size: 1.1rem;
  line-height: 1.7;
  color: rgba(255,255,255,.85);
  max-width: 640px;
  margin-bottom: 2rem;
}
.hero__actions { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ── Layout helpers ── */
.container { max-width: 1200px; margin: 3rem auto; padding: 0 2rem; }
.section-title {
  font-size: 1.5rem;
  color: var(--navy);
  margin-bottom: 1.5rem;
  font-weight: 700;
}
.grid { display: grid; gap: 1.5rem; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .grid--3 { grid-template-columns: 1fr; } }

.prod-card { padding: 1.5rem; }
.prod-card__body h3 {
  color: var(--navy);
  margin-bottom: .5rem;
  font-size: 1.15rem;
}
.prod-card__body p { color: var(--grey); font-size: .95rem; }

/* ── 3-step workflow (dashboard) ───────────────────────────── */
.step-flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 1rem;
  align-items: stretch;
  margin-top: 2rem;
}
.step-card {
  padding: 2rem 1.5rem;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 4px 24px rgba(11, 42, 107, .08);
  position: relative;
}
.step-card__num {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  color: var(--navy);
  opacity: .85;
}
.step-card__phase {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted, #5a6a8a);
}
.step-card__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
  margin: 0;
  line-height: 1.3;
}
.step-card__desc {
  font-size: .9rem;
  color: var(--grey, #5a6a8a);
  flex: 1;
  line-height: 1.5;
}
.step-card .btn {
  align-self: flex-start;
  margin-top: 0.5rem;
}
.step-flow__arrow {
  align-self: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--orange, #f47c20);
  padding: 0 .25rem;
}
.section-lede {
  color: var(--grey, #5a6a8a);
  font-size: 1rem;
  margin-top: -0.5rem;
  margin-bottom: 1rem;
  max-width: 720px;
}
@media (max-width: 900px) {
  .step-flow {
    grid-template-columns: 1fr;
  }
  .step-flow__arrow {
    transform: rotate(90deg);
    align-self: center;
    justify-self: center;
    padding: .25rem 0;
  }
}

/* ── Stat row ── */
.stat-row {
  display: flex;
  gap: 2rem;
  margin: 2.5rem 0;
  padding: 1.5rem 2rem;
  background: var(--off-white);
  border-radius: var(--radius);
}
.stat-row__item { display: flex; flex-direction: column; }
.stat-row__num {
  font-size: 2rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
}
.stat-row__label {
  font-size: .75rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--grey);
  margin-top: .35rem;
}

/* ── Health card / data tables ── */
.health-card {
  margin-top: 1.5rem;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.health-card h3 { color: var(--navy); margin-bottom: 1rem; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.data-table th {
  text-align: left;
  padding: .65rem .75rem;
  background: var(--off-white);
  color: var(--navy);
  font-size: .75rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--grey-lt);
}
.data-table td {
  padding: .75rem;
  border-bottom: 1px solid var(--grey-lt);
}
.data-table code {
  background: var(--blue-pale);
  padding: .15rem .4rem;
  border-radius: 4px;
  font-size: .82rem;
  color: var(--navy);
}

/* ── Status dots ── */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: .4rem;
}
.status-dot--ok { background: #10b981; }
.status-dot--warn { background: var(--orange); }
.status-dot--err { background: #ef4444; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--blue-pale);
  color: var(--navy);
}
.badge--draft { background: #fef3c7; color: #92400e; }
.badge--graduated { background: #dcfce7; color: #166534; }
.badge--production { background: var(--blue); color: #fff; }

/* ── Buttons (size variants) ── */
.btn--block { width: 100%; justify-content: center; }
.btn-sm { padding: .4rem .85rem; font-size: .8rem; }
.select-sm {
  padding: .35rem .5rem;
  font-size: .8rem;
  border: 1px solid var(--grey-lt);
  border-radius: 6px;
  background: #fff;
  vertical-align: middle;
  font-family: inherit;
}
.input-sm {
  padding: .35rem .5rem;
  font-size: .8rem;
  height: auto;            /* override native date/number UA defaults */
  line-height: 1.2;
  border: 1px solid var(--grey-lt);
  border-radius: 6px;
  background: #fff;
  vertical-align: middle;
  font-family: inherit;
  color: var(--navy);
  box-sizing: border-box;
}

/* ── Builder refresh-data cluster ──────────────────────────────── */
.builder__refresh {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: nowrap;
}
.builder__refresh .select-sm,
.builder__refresh .input-sm,
.builder__refresh .btn {
  /* Match the .btn-sm height (≈2rem) so all controls share one baseline.
     Without this the native <input type="date"> box overflows and the
     Refresh button wraps to a second line. */
  height: 2rem;
  flex-shrink: 0;            /* keep controls readable when row is tight */
  white-space: nowrap;       /* stop button text from wrapping */
}
.builder__refresh .input-sm[type="date"] {
  /* date inputs in Chromium honour width but not height; min-width keeps
     them readable, padding trims the native chrome. */
  padding: 0 .5rem;
  min-width: 8.5rem;
}
.builder__refresh .input-sm[type="number"] {
  /* step multiplier — keep narrow. */
  padding: 0 .5rem;
}
.builder__refresh .select-sm { padding: 0 .5rem; }
.builder__refresh-step { width: 4rem; }
.builder__refresh-date { width: 9.5rem; }

/* Trim default inline-form gap so the form sits flush with the other
   .btn-sm siblings in .builder__head-actions. */
.builder__head-actions > form.builder__refresh { margin: 0; }

/* ── Login ── */
.login-wrap {
  min-height: calc(100vh - 60px);
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--navy), var(--blue));
  padding: 2rem;
}
.login-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}
.login-card h1 {
  color: var(--navy);
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}
.login-card .eyebrow { margin-bottom: .5rem; }

/* ── Form fields ── */
.field {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-bottom: 1rem;
}
.field span {
  font-size: .8rem;
  font-weight: 600;
  color: var(--navy);
}
.field input, .field select, .field textarea {
  padding: .65rem .75rem;
  border: 1px solid var(--grey-lt);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-pale);
}

/* ── Alerts ── */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.alert--error { background: #fee2e2; color: #991b1b; }
.alert--warn { background: #fef3c7; color: #92400e; }

/* ── Admin layout ── */
.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 2rem;
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 2rem;
}
@media (max-width: 800px) { .admin-layout { grid-template-columns: 1fr; } }
.admin-side {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  height: fit-content;
}
.admin-side h3 {
  color: var(--navy);
  font-size: .75rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: .75rem;
}
.admin-side a {
  display: block;
  padding: .55rem .75rem;
  border-radius: 8px;
  font-size: .9rem;
  color: var(--dark);
}
.admin-side a:hover { background: var(--off-white); }
.admin-side a.is-active {
  background: var(--blue-pale);
  color: var(--navy);
  font-weight: 600;
}
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.admin-head h1 { color: var(--navy); font-size: 1.5rem; }
.admin-head__actions { display: flex; gap: .5rem; }
.muted { color: var(--grey); font-size: .9rem; }

/* ── Run-result metadata bar + report frame ── */
.run-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem 2.5rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  background: #fff;
  border: 1px solid var(--line, #e0e8f4);
  border-radius: var(--radius);
}
.run-meta__item { display: flex; flex-direction: column; gap: .15rem; }
.run-meta__label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--grey);
}
.run-meta__value { font-size: .95rem; color: var(--navy); }
.run-result__frame {
  width: 100%;
  min-height: 75vh;
  border: 1px solid var(--line, #e0e8f4);
  border-radius: var(--radius);
  background: #fff;
}

/* ── Modals (native <dialog>) ── */
.modal {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: min(90vw, 480px);
}
.modal::backdrop { background: rgba(11,42,107,.4); backdrop-filter: blur(2px); }
.modal-form h2 { color: var(--navy); margin-bottom: 1.25rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1.25rem;
}

/* ── Helpers ── */
.hint { font-size: .82rem; color: var(--grey); margin-bottom: 1rem; }
.hint code { font-size: .78rem; }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: .35rem;
}
.modal--wide { width: min(92vw, 720px); }
.row-actions { display: flex; gap: .35rem; align-items: center; }

/* ── Builder meta chips ── */
.builder__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .65rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .6rem;
  background: var(--blue-pale);
  border-radius: 999px;
  font-size: .8rem;
  color: var(--navy);
}
.chip code { background: none; padding: 0; }
.chip--warn { background: #fef3c7; color: #92400e; }

/* ── Sensor picker checklist ── */
.sensor-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .75rem;
  background: var(--off-white);
  border-radius: 10px;
  margin-bottom: .65rem;
  max-height: 240px;
  overflow-y: auto;
}
.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .7rem;
  background: #fff;
  border: 1px solid var(--grey-lt);
  border-radius: 999px;
  font-size: .82rem;
  cursor: pointer;
  transition: all .15s;
}
.checkbox-pill:hover { border-color: var(--blue-light); }
.checkbox-pill input[type="checkbox"] {
  accent-color: var(--orange);
  width: 14px;
  height: 14px;
}
.checkbox-pill input[type="checkbox"]:checked + span {
  color: var(--navy);
  font-weight: 600;
}
.checkbox-pill small {
  font-size: .72rem;
  color: var(--grey);
}
.checkbox-pill small.muted { color: var(--grey); }
.sensor-text-fallback { margin-top: .35rem; font-size: .82rem; color: var(--grey); }
.sensor-text-fallback input {
  width: 100%;
  padding: .5rem;
  margin-top: .35rem;
  border: 1px solid var(--grey-lt);
  border-radius: 6px;
  font-family: inherit;
}

/* ── Sensor mapping (canonical → actual, drag-and-drop) ── */
.sensor-mapping {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.sensor-mapping__column {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid var(--grey-lt);
  border-radius: 10px;
  background: var(--off-white);
  overflow: hidden;
}
.sensor-mapping__column-head {
  padding: .5rem .75rem;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--grey);
  background: #fff;
  border-bottom: 1px solid var(--grey-lt);
}
.sensor-mapping__slot { padding: .5rem .75rem; }
.sensor-mapping__slot-head {
  font-size: .78rem;
  margin-bottom: .3rem;
  color: var(--navy);
}
.sensor-mapping__slot-head code { background: none; padding: 0; font-weight: 600; }
.sensor-mapping__slot.is-auto .sensor-mapping__slot-head::after {
  content: "auto-matched by name";
  margin-left: .4rem;
  padding: .05rem .35rem;
  border-radius: 999px;
  background: var(--blue-pale);
  color: var(--navy);
  font-size: .68rem;
  font-weight: 600;
}
.sensor-mapping__dropzone {
  min-height: 42px;
  padding: .3rem;
  border: 2px dashed #f0c26a;
  border-radius: 8px;
  background: #fffbeb;
}
.sensor-mapping__dropzone.is-filled {
  border-style: solid;
  border-color: var(--grey-lt);
  background: #fff;
}
.sensor-mapping__dropzone:empty::before {
  content: "⚠ unmapped — drag a sensor here";
  display: block;
  padding: .35rem .2rem;
  font-size: .78rem;
  color: #92400e;
}
.sensor-mapping__pool {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  padding: .5rem .75rem;
  max-height: 320px;
  overflow-y: auto;
}
.sensor-mapping__chip {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .35rem .55rem;
  background: #fff;
  border: 1px solid var(--grey-lt);
  border-radius: 8px;
  font-size: .82rem;
  cursor: grab;
}
.sensor-mapping__chip:hover { border-color: var(--blue-light); }
.sensor-mapping__chip-name {
  font-weight: 600;
  color: var(--navy);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sensor-mapping__chip small { font-size: .72rem; color: var(--grey); }
.sensor-mapping__chip small.muted { margin-left: auto; }
.sensor-mapping__grip { color: var(--grey-lt); cursor: grab; }
.sensor-mapping__clear {
  border: none;
  background: none;
  padding: 0 .2rem;
  font-size: .8rem;
  line-height: 1;
  color: var(--grey);
  cursor: pointer;
}
.sensor-mapping__clear:hover { color: var(--orange); }
/* The ✕ only makes sense on a mapped chip — hide it in the available pool. */
.sensor-mapping__pool .sensor-mapping__clear { display: none; }
.sensor-mapping__pool .sensor-mapping__chip small.muted { margin-left: auto; }
.sensor-mapping__warn {
  padding: .6rem .8rem;
  margin-bottom: .65rem;
  background: #fef3c7;
  color: #92400e;
  border-radius: 8px;
  font-size: .85rem;
}
.sensor-mapping__save { margin-top: .65rem; }
@media (max-width: 720px) {
  .sensor-mapping { flex-direction: column; }
  .sensor-mapping__column { width: 100%; }
}

/* ── Builder workspace ── */
.builder {
  max-width: 1600px;
  margin: 1.5rem auto;
  padding: 0 2rem;
}
.builder__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.builder__head h1 { color: var(--navy); font-size: 1.5rem; }
.builder__head-actions { display: flex; gap: .5rem; flex-wrap: nowrap; align-items: center; }
.builder__head-actions .btn { white-space: nowrap; flex-shrink: 0; }

.builder__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  height: calc(100vh - 240px);
  min-height: 600px;
}
@media (max-width: 1100px) {
  .builder__grid { grid-template-columns: 1fr; height: auto; }
}

/* ── Chat panel ── */
.builder__chat {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 500px;
}
.builder__chat h2,
.builder__preview-head h2 {
  font-size: .8rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--navy);
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--grey-lt);
  margin: 0;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--off-white);
}
.chat-empty {
  color: var(--grey);
  text-align: center;
  margin: auto;
  font-size: .9rem;
  max-width: 320px;
}
.chat-msg {
  max-width: 88%;
  padding: .75rem 1rem;
  border-radius: 12px;
  font-size: .92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg__role {
  font-size: .68rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--grey);
  margin-bottom: .35rem;
}
.chat-msg--user {
  align-self: flex-end;
  background: var(--blue);
  color: #fff;
}
.chat-msg--user .chat-msg__role { color: rgba(255,255,255,.7); }
.chat-msg--assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--grey-lt);
}
.chat-msg--system {
  align-self: center;
  background: #f6f8fc;
  border: 1px dashed var(--grey-lt);
  color: #666;
  font-size: .82rem;
  font-style: italic;
  max-width: 80%;
  text-align: center;
}
.chat-msg--assistant.streaming::after {
  content: '▌';
  color: var(--orange);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input {
  border-top: 1px solid var(--grey-lt);
  padding: 1rem 1.25rem;
  background: #fff;
}
.chat-input textarea {
  width: 100%;
  border: 1px solid var(--grey-lt);
  border-radius: 10px;
  padding: .65rem .75rem;
  font-family: inherit;
  font-size: .95rem;
  resize: vertical;
}
.chat-input textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-pale);
}
.chat-input__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: .65rem;
}
.chat-status {
  font-size: .8rem;
  color: var(--grey);
}
.chat-status--error { color: #ef4444; }
.chat-status--ok { color: #10b981; }

/* ── Preview panel ── */
.builder__preview {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 500px;
}
.builder__preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 1.25rem;
  border-bottom: 1px solid var(--grey-lt);
}
.builder__preview iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--off-white);
}
