:root {
  --target-red: #cc0000;
  --target-red-dark: #9f0000;
  --target-red-soft: #fff0f0;
  --ink: #1e1e24;
  --muted: #6b6f76;
  --line: #e8e8ec;
  --paper: #ffffff;
  --bg: #f7f7f9;
  --success: #147a3e;
  --success-soft: #eaf7ef;
  --warning: #b35b00;
  --warning-soft: #fff4e6;
  --danger: #a11515;
  --danger-soft: #fff0f0;
  --shadow: 0 12px 30px rgba(30, 30, 36, 0.08);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(204, 0, 0, 0.12), transparent 34rem),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 40%, #f2f2f5 100%);
  min-height: 100vh;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(204, 0, 0, 0.25);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 12px;
  margin: -18px -18px 14px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(232, 232, 236, 0.8);
}

.brand-mark {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--target-red), var(--target-red-dark));
  font-weight: 900;
  letter-spacing: -0.04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.topbar h1,
.hero-card h2,
.section-head h2,
.card h3 {
  margin: 0;
  line-height: 1.05;
}

.topbar h1 {
  font-size: clamp(1.45rem, 4vw, 2.1rem);
  letter-spacing: -0.04em;
}

.eyebrow,
.hero-label {
  margin: 0 0 4px;
  color: var(--target-red);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ghost-btn,
.secondary-btn,
.primary-btn,
.success-btn,
.warning-btn,
.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 800;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.ghost-btn:hover,
.secondary-btn:hover,
.primary-btn:hover,
.success-btn:hover,
.warning-btn:hover,
.danger-btn:hover {
  transform: translateY(-1px);
}

.ghost-btn {
  margin-left: auto;
  color: var(--target-red);
  background: var(--target-red-soft);
}

.primary-btn {
  color: #fff;
  background: var(--target-red);
  box-shadow: 0 10px 24px rgba(204, 0, 0, 0.25);
}

.primary-btn:hover {
  background: var(--target-red-dark);
}

.secondary-btn {
  color: var(--target-red);
  background: #fff;
  border: 1px solid rgba(204, 0, 0, 0.22);
}

.success-btn {
  color: #fff;
  background: var(--success);
}

.warning-btn {
  color: #fff;
  background: var(--warning);
}

.danger-btn {
  color: #fff;
  background: var(--danger);
}

.full {
  width: 100%;
}

.hero-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  padding: clamp(20px, 4vw, 34px);
  color: #fff;
  background:
    linear-gradient(135deg, rgba(204, 0, 0, 0.98), rgba(131, 0, 0, 0.98)),
    var(--target-red);
  border-radius: calc(var(--radius) + 8px);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -80px;
  top: -80px;
  width: 230px;
  height: 230px;
  border-radius: 999px;
  border: 34px solid rgba(255, 255, 255, 0.18);
}

.hero-card h2 {
  font-size: clamp(1.65rem, 5vw, 3rem);
  letter-spacing: -0.06em;
}

.hero-card p {
  margin: 10px 0 0;
  max-width: 680px;
  color: rgba(255, 255, 255, 0.9);
}

.hero-card .primary-btn {
  position: relative;
  z-index: 2;
  color: var(--target-red);
  background: #fff;
  box-shadow: none;
}

.hero-label {
  color: #fff;
  opacity: 0.92;
}

.tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 14px 2px 18px;
  scrollbar-width: thin;
}

.tab-btn {
  white-space: nowrap;
  padding: 11px 15px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 850;
}

.tab-btn.active {
  color: #fff;
  background: var(--target-red);
  border-color: var(--target-red);
  box-shadow: 0 10px 24px rgba(204, 0, 0, 0.16);
}

.tab-panel {
  display: none;
  animation: fadeIn 0.18s ease-out;
}

.tab-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 10px 0 14px;
}

.section-head h2 {
  font-size: clamp(1.45rem, 4vw, 2.1rem);
  letter-spacing: -0.045em;
}

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

.stat-card,
.card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(232, 232, 236, 0.94);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
}

.stat-card .value {
  display: block;
  margin-top: 8px;
  font-size: 2.3rem;
  line-height: 1;
  font-weight: 950;
  letter-spacing: -0.06em;
}

.stat-card .label {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.86rem;
}

.card {
  padding: 18px;
  margin-bottom: 14px;
}

.card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card h3 {
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 5px 9px;
  color: var(--target-red);
  background: var(--target-red-soft);
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 850;
  white-space: nowrap;
}

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

label,
legend {
  display: block;
  margin: 0 0 7px;
  font-size: 0.82rem;
  color: var(--ink);
  font-weight: 850;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

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

.search-card {
  display: grid;
  gap: 11px;
}

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

.form-grid.compact {
  margin-bottom: 14px;
}

.wide {
  grid-column: 1 / -1;
}

.fieldset-card {
  border: 1px dashed rgba(204, 0, 0, 0.28);
  border-radius: 18px;
  padding: 14px;
  background: var(--target-red-soft);
}

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

.checkbox-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 11px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-weight: 750;
  font-size: 0.88rem;
}

.checkbox-chip input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  accent-color: var(--target-red);
}

.step-list {
  margin: 0;
  padding-left: 22px;
}

.step-list li {
  margin: 0 0 10px;
  padding-left: 3px;
  font-weight: 730;
}

.stack-list,
.activity-list,
.queue-list,
.notes-list {
  display: grid;
  gap: 10px;
}

.list-item,
.activity-item,
.queue-item,
.note-item {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #fff;
}

.list-item strong,
.activity-item strong,
.queue-item strong,
.note-item strong {
  display: block;
  margin-bottom: 4px;
}

.meta-line {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.found,
.badge.resolved {
  color: var(--success);
  background: var(--success-soft);
}

.badge.not_found,
.badge.open {
  color: var(--danger);
  background: var(--danger-soft);
}

.badge.assist_needed,
.badge.working,
.badge.audit {
  color: var(--warning);
  background: var(--warning-soft);
}

.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.action-row.wrap {
  flex-wrap: wrap;
}

.queue-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.queue-actions button {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.8rem;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.empty-state:empty::before {
  content: "No data yet. Start by logging a rescue or adding a team note.";
  display: block;
  color: var(--muted);
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: #fff;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

.footer-note {
  padding: 22px 4px 8px;
  color: var(--muted);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
}

.footer-note span {
  color: var(--target-red);
  font-weight: 950;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 100;
  max-width: min(92vw, 520px);
  padding: 12px 16px;
  color: #fff;
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
  transform: translate(-50%, 90px);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  font-weight: 750;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal {
  width: min(92vw, 460px);
  border: 0;
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.22);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal h3 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.modal p {
  color: var(--muted);
  line-height: 1.55;
}

#auditSummary {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-height: 220px;
}

@media (max-width: 860px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-column,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    margin: -12px -12px 12px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    font-size: 0.92rem;
  }

  .hero-card {
    grid-template-columns: 1fr;
  }

  .hero-card .primary-btn {
    width: 100%;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-head .secondary-btn {
    width: 100%;
  }

  .stat-grid,
  .checklist-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar .ghost-btn {
    padding-inline: 12px;
  }
}
.top-actions{display:flex;align-items:center;gap:10px;margin-left:auto;flex-wrap:wrap;justify-content:flex-end}.inline-login{display:grid;grid-template-columns:1fr 1fr auto;gap:10px;width:min(620px,100%)}.inline-login input{min-width:0}.toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);background:#111827;color:#fff;padding:12px 16px;border-radius:999px;box-shadow:0 12px 30px rgba(0,0,0,.24);z-index:9999;font-weight:800}.stack-list:empty::before,.activity-list:empty::before{content:'No entries yet.';display:block;color:#64748b;padding:10px 0}.full-span{grid-column:1/-1}.mini-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}.link-btn{border:0;background:transparent;color:#cc0000;font-weight:800;cursor:pointer;padding:0}.status-dot{display:inline-block;width:8px;height:8px;border-radius:999px;background:#cc0000;margin-right:6px}.muted{color:#64748b}.danger-text{color:#b91c1c;font-weight:800}.success-text{color:#166534;font-weight:800}@media(max-width:720px){.inline-login{grid-template-columns:1fr}.top-actions{width:100%;justify-content:flex-start}.tab-btn{font-size:13px}}
.stat-card span{display:block;color:var(--muted);font-weight:800;font-size:.86rem}.stat-card strong{display:block;margin-top:8px;font-size:2.3rem;line-height:1;font-weight:950;letter-spacing:-.06em}.small{padding:8px 10px!important;border-radius:12px!important;font-size:.82rem!important}.stack-item{padding:13px;border:1px solid var(--line);border-radius:17px;background:#fff}.stack-item strong{display:block;margin-bottom:4px}.tab-panel{display:none}.tab-panel.active{display:block}

/* v3 Scan Assist */
.status-line {
  margin: 10px 0 14px;
  padding: 10px 12px;
  border-radius: 14px;
  color: var(--muted);
  background: #f4f4f6;
  border: 1px solid var(--line);
  font-size: 0.92rem;
  font-weight: 650;
}
.scan-preview-wrap {
  margin: 10px 0 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  max-height: 320px;
}
.scan-preview-wrap img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
}
.compact-form {
  grid-template-columns: 1fr;
  gap: 12px;
}
.scan-actions {
  margin-top: 14px;
}
input[type="file"] {
  width: 100%;
  padding: 12px;
  border: 1px dashed rgba(204, 0, 0, 0.35);
  border-radius: 16px;
  background: var(--target-red-soft);
}
.small {
  min-height: 34px;
  padding: 7px 12px;
  font-size: 0.86rem;
}
@media (max-width: 720px) {
  .scan-actions .secondary-btn,
  .scan-actions .warning-btn,
  .scan-actions .success-btn {
    width: 100%;
  }
}

/* v4 Schedule Planner */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}
.schedule-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}
.schedule-table th,
.schedule-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.schedule-table th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #fafafa;
}
.time-edit,
.notes-edit {
  width: 100%;
  min-width: 92px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.notes-edit {
  min-width: 170px;
}
.warning-line {
  padding: 11px 12px;
  border-radius: 14px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  font-weight: 750;
}
.coverage-grid {
  display: grid;
  grid-template-columns: 0.9fr 0.7fr 1.2fr 1.2fr;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  font-size: 0.92rem;
}
.coverage-grid > div {
  padding: 9px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.coverage-grid > div:nth-child(4n) {
  border-right: 0;
}
.coverage-head {
  color: var(--target-red);
  font-weight: 900;
  background: var(--target-red-soft) !important;
}
.small-text {
  font-size: 0.8rem;
}
@media print {
  body { background: #fff; }
  .topbar, .hero-card, .tabs, #scheduleForm, #autoScheduleBtn, #printScheduleBtn, .toast, .tab-panel:not(#schedulePlanner) { display: none !important; }
  #appPanel, #schedulePlanner, .tab-panel.active { display: block !important; }
  .app-shell { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .schedule-table { min-width: 0; font-size: 11px; }
  .schedule-table input { border: 0; padding: 0; }
}

/* v4.2 dedicated login flow */
body.login-mode {
  background:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,0.22), transparent 18rem),
    radial-gradient(circle at 78% 0%, rgba(255,255,255,0.18), transparent 22rem),
    linear-gradient(135deg, var(--target-red), var(--target-red-dark));
}

body.login-mode .app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-screen {
  width: min(620px, 100%);
}

.login-card {
  position: relative;
  overflow: hidden;
  padding: clamp(24px, 5vw, 42px);
  color: var(--ink);
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(255,255,255,0.65);
  border-radius: 32px;
  box-shadow: 0 28px 70px rgba(0,0,0,0.26);
}

.login-card::after {
  content: "";
  position: absolute;
  right: -80px;
  top: -80px;
  width: 210px;
  height: 210px;
  border-radius: 999px;
  border: 30px solid rgba(204,0,0,0.08);
  pointer-events: none;
}

.login-brand-row {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark.large {
  width: 64px;
  height: 64px;
  flex-basis: 64px;
  font-size: 1.2rem;
}

.login-card h1 {
  margin: 0;
  max-width: 460px;
  line-height: 1.02;
  letter-spacing: -0.055em;
  font-size: clamp(2rem, 7vw, 3.6rem);
}

.login-copy {
  position: relative;
  z-index: 1;
  margin: 0 0 22px;
  max-width: 520px;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.5;
}

.login-form {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 10px;
}

.login-form label {
  font-weight: 850;
  color: var(--ink);
}

.login-form input {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.install-note {
  position: relative;
  z-index: 1;
  margin: 18px 0 0;
  padding: 12px 14px;
  color: var(--muted);
  background: var(--target-red-soft);
  border: 1px solid rgba(204,0,0,0.12);
  border-radius: 16px;
  font-size: 0.92rem;
}

body.app-mode .topbar {
  display: flex;
}

@media (max-width: 640px) {
  .login-brand-row {
    align-items: flex-start;
  }
  .login-card {
    border-radius: 24px;
  }
}


/* v4.3 login header fix: never show command-center header on the login screen. */
[hidden] {
  display: none !important;
}

body.login-mode #appTopbar,
body.login-mode .topbar {
  display: none !important;
}
/* v4.6 Store Memory cards */
.memory-item .pill{display:inline-flex;margin:2px 0 6px 0}.success-pill{color:#166534!important;background:#dcfce7!important;border-color:#bbf7d0!important}.danger-pill{color:#991b1b!important;background:#fee2e2!important;border-color:#fecaca!important}

/* v4.7 OCR cleanup UI */
.raw-ocr-details { margin-top: 12px; }
.raw-ocr-details summary { cursor: pointer; font-weight: 800; margin-bottom: 8px; color: var(--muted); }
#scanCleanText { font-weight: 700; background: #fff; border-color: rgba(204,0,0,.25); }
