:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --ink: #14201d;
  --muted: #62726e;
  --line: #d8e5df;
  --green: #14533a;
  --green-2: #2f7d57;
  --blue: #2e6ea6;
  --amber: #ba7a18;
  --red: #b34c4c;
  --violet: #7058a6;
  --shadow: 0 18px 44px rgba(20, 32, 29, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(244, 247, 245, 0.96)),
    radial-gradient(circle at 18% 12%, rgba(46, 110, 166, 0.13), transparent 32%),
    var(--bg);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-page-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 12px clamp(18px, 4vw, 54px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: var(--green);
  border-radius: 8px;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  line-height: 1.25;
}

.brand small {
  color: var(--muted);
  font-size: 0.82rem;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.94rem;
}

.topnav a {
  padding: 8px 10px;
  border-radius: 6px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.topnav a:hover,
.topnav a:focus-visible,
.topnav a.is-active {
  color: var(--green);
  background: #e9f3ee;
  outline: none;
}

.topnav a.is-active {
  font-weight: 800;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.backend-menu {
  position: relative;
}

.backend-menu summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 8px 10px;
  color: var(--green);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.94rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
}

.backend-menu summary::-webkit-details-marker {
  display: none;
}

.backend-menu summary:hover,
.backend-menu summary:focus-visible,
.backend-menu[open] summary {
  background: #e9f3ee;
  outline: none;
}

.backend-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: grid;
  min-width: 280px;
  max-height: min(70vh, 620px);
  overflow-y: auto;
  padding: 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(20, 32, 29, 0.16);
}

.backend-menu-group {
  padding: 9px 11px 5px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

.backend-menu-panel a {
  padding: 10px 11px;
  color: var(--ink);
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
}

.backend-menu-panel a:hover,
.backend-menu-panel a:focus-visible {
  color: var(--green);
  background: #e9f3ee;
  outline: none;
}

.app-stage {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(280px, 520px);
  gap: clamp(24px, 5vw, 72px);
  align-items: center;
  width: min(1120px, calc(100% - 32px));
  min-height: calc(100vh - 72px);
  margin: 0 auto;
  padding: clamp(24px, 5vw, 58px) 0;
}

.phone-shell {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  width: min(100%, 390px);
  min-height: 780px;
  margin: 0 auto;
  overflow: hidden;
  background: #f9fbfa;
  border: 10px solid #15201d;
  border-radius: 34px;
  box-shadow: var(--shadow);
}

.app-screen {
  grid-row: 1;
  display: none;
  min-height: 644px;
  padding: 10px 16px 88px;
  min-width: 0;
  overflow-y: auto;
}

.app-screen.is-active {
  display: block;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.mobile-header > div {
  min-width: 0;
  flex: 1 1 auto;
}

.mobile-header small {
  color: var(--green-2);
  font-weight: 800;
}

.mobile-header h1 {
  margin: 2px 0 0;
  font-size: 1.7rem;
  line-height: 1.15;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 44px;
  height: 40px;
  padding: 0 12px;
  color: var(--green);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  flex: 0 0 auto;
}

.field-switcher,
.filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.field-switcher button,
.filter-tabs button {
  min-height: 36px;
  min-width: 0;
  padding: 0 8px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.field-switcher button.is-active,
.filter-tabs button.is-active {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.live-card,
.mobile-panel,
.task-list article,
.record-list article,
.alert-list article,
.consult-list article,
.summary-row article,
.record-stats article,
.telemetry-grid article {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(20, 32, 29, 0.06);
}

.live-card {
  overflow: hidden;
}

.scan-view {
  position: relative;
  display: grid;
  align-content: end;
  min-height: 250px;
  padding: 18px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(20, 83, 58, 0.1), rgba(13, 24, 22, 0.84)),
    url("../fiddle-leaf-fig.jpg") center 38% / cover no-repeat;
}

.scan-view.is-analyzing .scan-reticle {
  animation: scanPulse 900ms ease-in-out infinite;
}

.scan-reticle {
  position: absolute;
  top: 44%;
  left: 50%;
  width: 112px;
  height: 76px;
  border: 2px solid #76e2af;
  transform: translate(-50%, -50%);
}

.scan-overlay {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 4px;
}

.scan-overlay span {
  width: max-content;
  padding: 4px 8px;
  background: rgba(20, 83, 58, 0.8);
  border-radius: 8px;
  font-size: 0.76rem;
  font-weight: 900;
}

.scan-overlay strong {
  font-size: 1.35rem;
}

.scan-overlay small {
  color: #d9fff0;
}

.voice-command {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  color: var(--green);
  font-weight: 800;
}

.voice-command b {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

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

.action-grid button,
.quick-actions button {
  min-height: 48px;
  min-width: 0;
  color: #fff;
  background: var(--green);
  border: 0;
  border-radius: 12px;
  font-weight: 800;
}

.primary-actions button:nth-child(2) {
  background: var(--blue);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.quick-actions button {
  min-height: 40px;
  color: var(--green);
  background: #e9f3ee;
  font-size: 0.82rem;
}

.mobile-panel {
  padding: 16px;
}

.app-screen > .mobile-panel + .mobile-panel {
  margin-top: 12px;
}

.app-screen > .mobile-panel + .telemetry-grid,
.app-screen > .mobile-panel + .summary-row,
.app-screen > .mobile-panel + .record-stats,
.app-screen > .mobile-panel + .task-list,
.app-screen > .mobile-panel + .alert-list,
.app-screen > .mobile-panel + .record-list,
.app-screen > .mobile-panel + .consult-list {
  margin-top: 14px;
}

[data-module] {
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

[data-module].is-highlighted {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(20, 83, 58, 0.13), 0 12px 28px rgba(20, 32, 29, 0.1);
  transform: translateY(-1px);
}

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

.mobile-panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.mobile-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}

.risk-pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  color: #fff;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 900;
}

.risk-pill.high,
.risk.high {
  background: var(--red);
}

.risk-pill.medium,
.risk.medium {
  background: var(--amber);
}

.risk-pill.low,
.risk.low {
  background: var(--blue);
}

.risk-pill.done {
  background: var(--green-2);
}

.check-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.86rem;
}

.check-list li {
  position: relative;
  padding-left: 18px;
}

.check-list li::before {
  position: absolute;
  left: 0;
  color: var(--green);
  content: "✓";
  font-weight: 900;
}

.telemetry-grid,
.summary-row,
.record-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.telemetry-grid article,
.summary-row article,
.record-stats article {
  min-width: 0;
  padding: 14px 12px;
}

.telemetry-grid span,
.summary-row span,
.record-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.telemetry-grid strong,
.summary-row strong,
.record-stats strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.task-list,
.record-list,
.alert-list {
  display: grid;
  gap: 12px;
}

.task-list article,
.alert-list article {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
}

.risk {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #fff;
  border-radius: 10px;
  font-weight: 800;
}

.item-body strong,
.record-list strong {
  display: block;
  margin-bottom: 4px;
}

.item-body small,
.record-list small {
  color: var(--muted);
  line-height: 1.5;
}

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

.item-actions button {
  min-height: 32px;
  padding: 0 10px;
  color: var(--green);
  background: #e9f3ee;
  border: 0;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 900;
}

.alert-summary {
  display: grid;
  place-items: center;
  min-height: 170px;
  margin-bottom: 14px;
  padding: 20px;
  color: #fff;
  text-align: center;
  background: linear-gradient(135deg, var(--red), var(--amber));
  border-radius: 18px;
}

.alert-summary strong {
  font-size: 4rem;
  line-height: 1;
}

.alert-summary small {
  max-width: 240px;
  color: rgba(255, 255, 255, 0.82);
}

.mini-map {
  position: relative;
  height: 210px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.8) 1px, transparent 1px) 0 0 / 30px 30px,
    linear-gradient(rgba(255, 255, 255, 0.8) 1px, transparent 1px) 0 0 / 30px 30px,
    #e8f1ef;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.mini-map span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: calc(40px * var(--s));
  height: calc(40px * var(--s));
  background: rgba(179, 76, 76, 0.68);
  border: 8px solid rgba(179, 76, 76, 0.18);
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.search-box {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.record-list article {
  padding: 15px;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.record-meta span {
  padding: 4px 8px;
  color: var(--muted);
  background: #f1f6f3;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
}

#tasks .mobile-header,
#records .mobile-header,
#dashboard .mobile-header {
  margin-bottom: 18px;
}

#tasks .summary-row,
#records .record-stats,
#dashboard .summary-row {
  margin-top: 0;
  margin-bottom: 18px;
}

#tasks .filter-tabs {
  margin-bottom: 18px;
}

#tasks .task-list {
  margin-top: 18px;
}

#records .mobile-panel,
#dashboard .mobile-panel {
  padding: 18px;
}

#records .mobile-panel .item-actions,
#dashboard .mobile-panel .item-actions {
  margin-top: 14px;
}

#records .record-list,
#dashboard .mobile-panel + .mobile-panel {
  margin-top: 18px;
}

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

.bottom-tabs {
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 3px;
  min-height: 82px;
  padding: 0 4px 3px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
}

.bottom-tabs button {
  display: grid;
  place-items: center;
  gap: 5px;
  color: var(--muted);
  background: transparent;
  border: 0;
  min-width: 0;
  padding: 10px 2px 9px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.05;
}

.bottom-tabs span {
  display: block;
  font-size: 1.05rem;
  line-height: 1;
}

.bottom-tabs button.is-active {
  color: var(--green);
}

.toast {
  position: absolute;
  right: 18px;
  bottom: 88px;
  left: 18px;
  z-index: 4;
  padding: 12px 14px;
  color: #fff;
  background: rgba(20, 83, 58, 0.94);
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(20, 32, 29, 0.18);
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-notes {
  max-width: 520px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-notes h2 {
  margin: 0 0 14px;
  font-size: clamp(2rem, 4vw, 3.7rem);
  line-height: 1.05;
}

.plan-list {
  display: grid;
  gap: 12px;
}

.plan-list article {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.plan-list strong {
  display: block;
  margin-bottom: 8px;
}

.plan-list p {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

@keyframes scanPulse {
  0%,
  100% {
    opacity: 0.55;
    transform: translate(-50%, -50%) scale(0.96);
  }

  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.05);
  }
}

@media (max-width: 760px) {
  .app-page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    padding-bottom: 2px;
  }

  .topnav a {
    min-width: 0;
    text-align: center;
  }

  .header-actions {
    align-items: flex-start;
    flex-direction: column;
    width: 100%;
  }

  .backend-menu {
    width: 100%;
  }

  .backend-menu summary {
    justify-content: center;
    width: 100%;
  }

  .backend-menu-panel {
    right: auto;
    left: 0;
    width: min(100%, 360px);
    max-height: 58vh;
  }

  .app-stage {
    grid-template-columns: 1fr;
  }

  .app-notes {
    order: -1;
    max-width: 100%;
  }
}

@media (max-width: 520px) {
  .app-page-header {
    padding: 12px 16px;
  }

  .topnav {
    gap: 6px;
    font-size: 0.88rem;
  }

  .app-stage {
    width: 100%;
    min-height: auto;
    padding: 0;
  }

  .phone-shell {
    width: 100%;
    height: calc(100dvh - 186px);
    min-height: calc(100dvh - 186px);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .app-screen {
    min-height: 0;
    padding: 10px 14px 12px;
  }

  .app-notes {
    display: none;
  }

  .field-switcher,
  .filter-tabs {
    gap: 5px;
  }

  .field-switcher button,
  .filter-tabs button,
  .quick-actions button {
    font-size: 0.76rem;
  }

  .icon-button {
    min-width: 42px;
    height: 38px;
    padding: 0 10px;
    font-size: 0.7rem;
  }

  .voice-command {
    align-items: flex-start;
    flex-direction: column;
  }

  .voice-command b {
    text-align: left;
  }

  .bottom-tabs {
    gap: 3px;
    min-height: 76px;
    padding: 0 3px 3px;
  }

  .bottom-tabs button {
    gap: 4px;
    padding: 8px 1px 8px;
    font-size: 0.64rem;
  }

  .bottom-tabs span {
    font-size: 0.92rem;
  }

  .live-card,
  .mobile-panel,
  .task-list article,
  .record-list article,
  .alert-list article,
  .summary-row article,
  .record-stats article,
  .telemetry-grid article {
    border-radius: 10px;
  }
}
