:root {
  color-scheme: light;
  --bg: #f2f5f9;
  --panel: #fff;
  --ink: #17283d;
  --muted: #596b80;
  --line: #dbe3ed;
  --blue: #173f6b;
  --red: #a81f32;
  --redbg: #fff0f2;
  --amber: #84500a;
  --amberbg: #fff5df;
  --green: #216747;
  --greenbg: #edf8f1;
  font:
    16px/1.5 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1 {
  font-size: 1.2rem;
  letter-spacing: -0.025em;
}
h2 {
  font-size: 1.35rem;
}
h3 {
  font-size: 1.05rem;
}
p + p {
  margin-top: 0.6rem;
}
button,
input,
select,
textarea {
  font: inherit;
}
button,
.file-button {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  min-height: 46px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  font-weight: 550;
}
button:disabled {
  opacity: 0.55;
  cursor: default;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #4285d4;
  outline-offset: 3px;
}
input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  border: 1px solid #b9c7d8;
  border-radius: 10px;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
}
textarea {
  min-height: 90px;
  resize: vertical;
}
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 550;
  min-width: 0;
}
.primary,
button[aria-pressed="true"] {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}
.danger {
  color: var(--red);
  background: var(--redbg);
  border-color: #edbac3;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.8rem;
}
.app-header {
  max-width: 1100px;
  margin: auto;
  padding: 20px 20px 14px;
  padding-top: max(20px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.brand #install {
  margin-left: auto;
}
.base-switch {
  display: flex;
  background: var(--bg);
  padding: 4px;
  border-radius: 13px;
  gap: 5px;
  margin-top: 16px;
}
.base-switch button {
  flex: 1;
  border: 0;
}
.base-switch button:not([aria-pressed="true"]) {
  background: transparent;
}
main {
  max-width: 1100px;
  margin: auto;
  padding: 20px 20px calc(110px + env(safe-area-inset-bottom));
  min-height: 70vh;
}
.bottom-nav {
  position: fixed;
  z-index: 20;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px 6px max(10px, env(safe-area-inset-bottom));
}
.bottom-nav button {
  border: 0;
  min-width: 0;
  padding: 7px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.75rem;
  min-height: 54px;
  background: transparent;
}
.bottom-nav button span {
  font-size: 1.3rem;
  line-height: 1.2;
}
.bottom-nav button.active {
  background: #e7eff9;
  color: var(--blue);
}
#lamp-nav { background: #fff1c7; color: #6a4300; font-weight: 700; }
#lamp-nav[aria-pressed="true"] { background: #ffca55; color: #1f2530; }
#lamp-screen {
  position: fixed;
  z-index: 10001;
  inset: 0;
  background: #fff;
  color: #1b2633;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
#lamp-screen[hidden] { display: none; }
#lamp-video { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.row > * {
  min-width: 0;
}
.row.space {
  justify-content: space-between;
}
.stack {
  display: grid;
  gap: 12px;
}
.top-gap {
  margin-top: 16px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  margin-top: 16px;
}
.fire-memo summary {
  cursor: pointer;
  font-weight: 700;
}
.fire-memo h3 {
  margin: 20px 0 8px;
}
.fire-memo ul {
  margin: 0;
  padding-left: 22px;
}
.fire-memo li {
  margin: 8px 0;
}
.search-row {
  display: flex;
  gap: 8px;
}
.search-row input {
  flex: 1;
  min-width: 0;
}
.search-row button {
  padding: 10px 12px;
}
.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.metric {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
}
.metric strong {
  font-size: 1.8rem;
  line-height: 1.1;
}
.metric.red {
  background: var(--redbg);
  color: var(--red);
  border-color: #f2ced4;
}
.metric.amber {
  background: var(--amberbg);
  color: var(--amber);
  border-color: #ebdcb7;
}
.metric.selected {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}
.record-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.record {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-weight: 400;
  overflow-wrap: anywhere;
}
.record strong {
  font-size: 1.05rem;
}
.record .location {
  color: var(--muted);
  font-size: 0.9rem;
}
.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.badge {
  font-size: 0.8rem;
  border-radius: 6px;
  padding: 3px 7px;
  background: #eef2f7;
  color: #40536b;
  font-weight: 500;
}
.badge.red {
  background: var(--redbg);
  color: var(--red);
}
.badge.amber {
  background: var(--amberbg);
  color: var(--amber);
}
.badge.green {
  background: var(--greenbg);
  color: var(--green);
}
.empty {
  padding: 32px 18px;
  text-align: center;
  color: var(--muted);
}
.details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
  margin-top: 15px;
  overflow-wrap: anywhere;
}
.details dt {
  font-size: 0.8rem;
  color: var(--muted);
}
.details dd {
  margin: 3px 0 0;
}
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.actions > * {
  flex: 1;
}
.timeline {
  border-left: 2px solid var(--line);
  padding: 0 0 18px 14px;
  margin-top: 14px;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.photo-grid figure {
  margin: 0;
  min-width: 0;
}
.photo-grid img {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
  border-radius: 9px;
}
.photo-grid a {
  display: block;
}
.photo-grid figcaption {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}
.photo-grid button {
  font-size: 0.75rem;
  padding: 5px;
  min-height: 36px;
  width: 100%;
  margin-top: 5px;
}
.timeline .photo-grid img {
  height: 100px;
}
.notice {
  font-size: 0.9rem;
  color: var(--muted);
  padding: 12px 0;
}
.warning {
  background: var(--amberbg);
  color: var(--amber);
  padding: 12px;
  border-radius: 10px;
}
.table-wrap {
  overflow-x: auto;
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
th,
td {
  text-align: left;
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
}
th {
  color: var(--muted);
  font-size: 0.8rem;
}
table input {
  min-width: 80px;
  padding: 8px;
}
.summary-line {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 14px 0;
}
.summary-line span {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 12px;
}
.preview-video {
  width: 100%;
  max-height: 460px;
  aspect-ratio: 3/4;
  object-fit: cover;
  background: #17283d;
  border-radius: 16px;
  display: block;
  margin-top: 14px;
}
#camera {
  height: clamp(210px, 33vh, 300px);
  max-height: none;
  aspect-ratio: auto;
  object-fit: cover;
  margin-top: 8px;
}
#scan-flash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  background: rgba(154, 255, 193, 0.42);
}
#scan-flash.active {
  animation: scan-confirmation 420ms ease-out;
}
#scan-results .notice { overflow-wrap: anywhere; }
@keyframes scan-confirmation {
  0%, 100% { opacity: 0; }
  22% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #scan-flash.active { animation-duration: 120ms; }
}
.scan-frame {
  position: relative;
}
.scan-frame::after {
  content: "";
  position: absolute;
  inset: 25% 12%;
  border: 2px solid #fff;
  border-radius: 12px;
  pointer-events: none;
}
.hidden,
[hidden] {
  display: none !important;
}
dialog {
  color: var(--ink);
  background: var(--panel);
  border: 0;
  border-radius: 18px;
  padding: 22px;
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  box-shadow: 0 20px 80px #0b1c3e55;
}
dialog::backdrop {
  background: #10213b77;
}
dialog .dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
dialog form {
  display: grid;
  gap: 13px;
}
dialog .form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
#toast {
  position: fixed;
  z-index: 100;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 28px);
  width: max-content;
  background: #173f6b;
  color: white;
  border-radius: 12px;
  padding: 14px 20px;
  box-shadow: 0 4px 24px #0003;
}
a {
  color: var(--blue);
}
details > summary {
  cursor: pointer;
  min-height: 44px;
  padding: 10px 0;
}
code {
  overflow-wrap: anywhere;
}
.pagination {
  margin-top: 18px;
  justify-content: center;
}
.inline-checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.inline-checkbox input {
  width: 22px;
  min-height: 22px;
}
.numeric {
  font-variant-numeric: tabular-nums;
}
.manager-cards {
  display: none;
}
@media (min-width: 800px) {
  .app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 0 0 18px 18px;
  }
  .base-switch {
    margin: 0;
    width: 280px;
  }
  .bottom-nav button {
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    font-size: 0.9rem;
  }
  .preview-video {
    max-width: 430px;
  }
  .scan-frame {
    max-width: 430px;
  }
}
@media (max-width: 620px) {
  .app-header {
    padding-left: 16px;
    padding-right: 16px;
  }
  main {
    padding: 16px 16px calc(106px + env(safe-area-inset-bottom));
  }
  .metrics {
    grid-template-columns: 1fr;
    gap: 9px;
  }
  .metric {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 13px 15px;
  }
  .metric strong {
    font-size: 1.5rem;
    flex-shrink: 0;
  }
  .record-list,
  .details,
  .filters {
    grid-template-columns: 1fr;
  }
  .panel {
    padding: 15px;
  }
  .filters {
    gap: 9px;
  }
  .actions > * {
    flex-basis: calc(50% - 8px);
  }
  dialog .form-grid {
    grid-template-columns: 1fr;
  }
  .photo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .manager-table {
    display: none;
  }
  .manager-cards {
    display: grid;
    gap: 12px;
  }
  .manager-cards .panel {
    margin-top: 0;
  }
  .plan-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .plan-fields label {
    font-size: 0.8rem;
  }
  .row > .wide {
    flex-basis: 100%;
  }
  .search-row {
    flex-wrap: wrap;
  }
  .search-row input {
    flex-basis: 100%;
  }
  .search-row button {
    flex: 1;
  }
}

.bottom-nav {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.bottom-nav.viewer {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.bottom-nav.provider { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.auth-panel {
  max-width: 480px;
  margin: 20px auto;
}
.app-header {
  flex-wrap: wrap;
}
#shared-status {
  flex-basis: 100%;
  margin-top: 8px;
  overflow-wrap: anywhere;
}
#account-button {
  margin-left: auto;
  font-size: 0.8rem;
  max-width: 170px;
}
.exact-search {
  background: #e7eff9;
  padding: 14px;
  border-radius: 12px;
}
.pie-wrap {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: center;
  margin: 20px 0;
}
.pie {
  height: 180px;
  width: 180px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend {
  display: grid;
  gap: 9px;
}
.legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border-radius: 3px;
}
.sync-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.conflict-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.conflict-columns pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
}
.control-cost {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 12px;
}
@media (max-width: 620px) {
  .bottom-nav button {
    font-size: 10px;
  }
  .conflict-columns {
    grid-template-columns: 1fr;
  }
  #account-button {
    max-width: 130px;
  }
  .pie {
    width: 150px;
    height: 150px;
  }
  .pie-wrap {
    justify-content: center;
  }
}

.qr-capture {
  margin: 18px 0;
  padding: 16px;
}
.qr-capture > label {
  font-weight: 700;
}
.qr-value {
  margin: 8px 0 14px;
  padding: 10px 12px;
  background: #f4f7fa;
  border-radius: 8px;
  overflow-wrap: anywhere;
  min-height: 42px;
}
.qr-capture[hidden],
[hidden] {
  display: none !important;
}
.atex-alert {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  padding: 24px;
}
.atex-alert h2 {
  margin: 0 0 12px;
  color: #8f1526;
}
.atex-alert p {
  margin: 12px 0;
}
.atex-alert button {
  width: 100%;
  margin-top: 10px;
}
.atex-symbol {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff0f2;
  color: #a81f32;
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
}
