/* CodeImpact mobile companion (/m). Self-contained: no dependency on the website's CSS. */
:root {
  --bg: #0a0f1a; --surface: #111827; --card: #151e30; --card-press: #1b2639; --line: #233149;
  --ink: #e6ebf3; --muted: #8b9ab3; --accent: #fbd509; --accent-ink: #0a0f1a;
  --high: #f87171; --medium: #fbbf24; --low: #4ade80; --info: #93c5fd;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --bar: 62px; --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.m-app {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; overflow-x: hidden;
  padding-bottom: calc(var(--bar) + env(safe-area-inset-bottom) + 16px);
}
body.m-detail-open { overflow: hidden; }
button { font: inherit; color: inherit; }
.m-root { max-width: 720px; margin: 0 auto; }

/* Header */
.m-header {
  position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top);
  background: rgba(10, 15, 26, .94); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.m-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; }
.m-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.m-brand > div { min-width: 0; }
.m-brand strong { display: block; font-size: 19px; letter-spacing: -.01em; color: #fff; }
.m-brand small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-logo { flex: none; width: 34px; height: 34px; border-radius: 10px; background: url(/static/pwa/codeimpact-icon.svg) center/cover; }
.m-icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 20px; cursor: pointer;
}
.m-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 16px; background: #1e293b; font-size: 13px; }
.m-banner[hidden] { display: none; }
.m-offline { background: #7f1d1d; color: #fff; }

/* Content */
.m-main { padding: 14px 14px 0; }
.m-screen[hidden] { display: none; }
.m-section { margin-top: 22px; }
.m-section-title { margin: 0 0 10px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.m-list { display: grid; gap: 10px; }
.m-empty { padding: 22px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; display: grid; gap: 12px; justify-items: center; }
.m-failed { color: #fecaca; border-color: #7f1d1d; }

/* Stat tiles */
.m-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.m-stat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 84px; padding: 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); text-align: left; cursor: pointer;
}
.m-stat strong { font-size: 28px; line-height: 1.1; color: #fff; font-weight: 800; }
.m-stat span { font-size: 13px; color: var(--muted); }
.m-stat.warn strong { color: var(--high); }
.m-stat:active { background: var(--card-press); }

/* Cards */
.m-card {
  display: block; width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); text-align: left; min-width: 0; overflow-wrap: anywhere;
}
button.m-card { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button.m-card:active { background: var(--card-press); }
.m-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.m-card-title { font-size: 15px; font-weight: 650; color: #fff; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.m-card-meta { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.m-card-body { margin: 8px 0 0; font-size: 14px; color: #c3cdda;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.m-detail .m-card-body, .m-detail .m-card-title { -webkit-line-clamp: unset; display: block; }

/* Pills: risk and status */
.m-pill {
  flex: none; display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; text-transform: capitalize; border: 1px solid #3b4b62; color: #c3cdda; white-space: nowrap;
}
.m-pill.high, .m-pill.critical, .m-pill.failed, .m-pill.unhealthy, .m-pill.error, .m-pill.unavailable { color: var(--high); border-color: #7f1d1d; background: rgba(248, 113, 113, .08); }
.m-pill.medium, .m-pill.retrying, .m-pill.queued, .m-pill.running_, .m-pill.insufficient_evidence, .m-pill.stopped, .m-pill.paused, .m-pill.none { color: var(--medium); border-color: #78350f; background: rgba(251, 191, 36, .08); }
.m-pill.low, .m-pill.healthy, .m-pill.answered, .m-pill.completed, .m-pill.succeeded, .m-pill.running, .m-pill.resolved, .m-pill.monitoring { color: var(--low); border-color: #14532d; background: rgba(74, 222, 128, .08); }
.m-pill.info, .m-pill.unknown { color: var(--info); border-color: #1e3a8a; }

/* Filter chips */
.m-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.m-chips::-webkit-scrollbar { display: none; }
.m-chip {
  flex: none; min-height: 38px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.m-chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.m-chips + .m-list { margin-top: 10px; }

/* Buttons */
.m-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid #3a4960; background: #1a2539; color: var(--ink); font-size: 15px;
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.m-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.m-btn.danger { border-color: #7f1d1d; color: #fca5a5; }
.m-btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.m-btn.block { width: 100%; }
.m-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.m-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-radius: var(--radius); background: rgba(251, 213, 9, .08); border: 1px solid rgba(251, 213, 9, .3); font-size: 14px; }

/* Detail view */
.m-detail {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--bg);
  max-width: 720px; margin: 0 auto;
}
.m-detail[hidden] { display: none; }
.m-detail-head {
  display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  border-bottom: 1px solid var(--line); background: rgba(10, 15, 26, .96);
}
.m-detail-head strong { font-size: 17px; }
.m-detail-body { flex: 1; overflow-y: auto; padding: 16px 14px calc(env(safe-area-inset-bottom) + 28px); -webkit-overflow-scrolling: touch; }
.m-detail-hero h2 { margin: 10px 0 6px; font-size: 21px; line-height: 1.3; color: #fff; overflow-wrap: anywhere; }
.m-detail-body > .m-card { margin-top: 12px; }
.m-text { margin: 0; color: #d3dbe6; white-space: pre-wrap; overflow-wrap: anywhere; }
.m-answer { margin-top: 10px; display: grid; gap: 10px; }
.m-code, .m-command {
  display: block; margin: 0; padding: 10px 12px; border-radius: 10px; background: #070b14; border: 1px solid var(--line);
  font: 12.5px/1.5 var(--mono); color: #e2e8f0; overflow-x: auto; white-space: pre;
}
.m-command { margin-top: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.m-files { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.m-files li { padding: 9px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font: 13px/1.4 var(--mono); overflow-wrap: anywhere; }
.m-steps { margin: 10px 0 0; padding-left: 20px; color: #d3dbe6; font-size: 14px; display: grid; gap: 6px; }

/* Bottom tab bar */
.m-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--bar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(12, 19, 33, .97); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.m-tabbar button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; min-height: 44px; border: 0; background: transparent; color: #8796ad; font-size: 11.5px; font-weight: 600;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.m-tabbar button::before {
  content: ""; width: 24px; height: 24px; background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.m-tabbar button[aria-current="page"] { color: var(--accent); }
.m-tabbar button:focus-visible { outline: 2px solid #fff; outline-offset: -4px; border-radius: 10px; }
.m-tabbar button[data-badge]::after {
  content: attr(data-badge); position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--high); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
[data-tab="home"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3 2 11h3v9h5v-6h4v6h5v-9h3z'/%3E%3C/svg%3E"); }
[data-tab="analyses"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3h2v16h16v2H3zm4 10 4-4 3 3 5-6 1.5 1.3-6.4 7.5-3.1-3.1L8.4 14.4z'/%3E%3C/svg%3E"); }
[data-tab="questions"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 3h16a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H9l-5 4v-4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zm7.1 11.5h1.8v-1.8h-1.8zm.9-9a3.2 3.2 0 0 0-3.2 3h1.8a1.4 1.4 0 1 1 2 1.3c-.9.5-1.5 1.1-1.5 2.4h1.8c0-.8.3-1 .9-1.4a3.2 3.2 0 0 0-1.8-5.3z'/%3E%3C/svg%3E"); }
[data-tab="alerts"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 22a2.5 2.5 0 0 0 2.5-2.5h-5A2.5 2.5 0 0 0 12 22zm7-6v-5a7 7 0 0 0-5.5-6.8V3a1.5 1.5 0 0 0-3 0v1.2A7 7 0 0 0 5 11v5l-2 2v1h18v-1z'/%3E%3C/svg%3E"); }
[data-tab="more"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='5' cy='12' r='2.2'/%3E%3Ccircle cx='12' cy='12' r='2.2'/%3E%3Ccircle cx='19' cy='12' r='2.2'/%3E%3C/svg%3E"); }
.m-detail-open .m-tabbar { display: none; }

/* Sign-in dialog and toast */
.m-dialog {
  width: min(420px, calc(100% - 28px)); border: 1px solid #34445b; border-radius: 18px; background: var(--surface);
  color: var(--ink); padding: 0; box-shadow: 0 30px 90px rgba(0, 0, 0, .7);
}
.m-dialog::backdrop { background: rgba(2, 6, 12, .85); backdrop-filter: blur(4px); }
.m-dialog form { display: grid; gap: 14px; padding: 24px; }
.m-dialog h2 { margin: 0; font-size: 22px; color: #fff; }
.m-dialog p { margin: 0; color: var(--muted); font-size: 14px; }
.m-dialog label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: #a9b6c9; }
.m-dialog input {
  min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid #34445b; background: #070b14;
  color: var(--ink); font-size: 16px; /* 16px prevents iOS zoom on focus */
}
.m-dialog input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(251, 213, 9, .15); }
.m-error { min-height: 18px; color: #fca5a5; font-size: 13px; }
.m-link { text-align: center; color: #9fb0c8; font-size: 13px; }
.m-toast {
  position: fixed; left: 50%; bottom: calc(var(--bar) + env(safe-area-inset-bottom) + 14px); z-index: 60; transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--accent); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; overflow-wrap: anywhere;
}
.m-toast.show { opacity: 1; }
.m-toast.error { border-color: var(--high); color: #fecaca; }

@media (min-width: 721px) {
  .m-tabbar { left: 50%; right: auto; width: 720px; transform: translateX(-50%); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
