:root {
  --ink: #1c1914;
  --muted: #5c564c;
  --paper: #efe8da;
  --card: #fffdf8;
  --line: #ddd3c2;
  --navy: #122743;
  --navy-2: #1b3d66;
  --blue: #1f4e89;
  --amber: #e39b12;
  --amber-ink: #2a1c04;
  --amber-bg: #fff6e4;
  --red: #9d1c1c;
  --red-bg: #fdeceb;
  --green: #1d6b45;
  --green-bg: #e7f5ee;
  --shadow: 0 10px 28px rgba(48, 36, 12, 0.08);
  --sans: "Segoe UI", "Helvetica Neue", sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  background:
    linear-gradient(180deg, #d9d0c0 0, var(--paper) 220px);
}

body.has-bar { padding-bottom: 96px; }

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

fieldset.plain {
  border: 0;
  margin: 0;
  padding: 0;
  min-inline-size: 0;
}

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

.loading { padding: 32px 16px; color: var(--muted); }

.top {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--navy);
  color: #f6f1e6;
}

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

.crew-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.brand-logo {
  height: 46px;
  width: auto;
  max-width: 108px;
  object-fit: contain;
  display: block;
  flex: 0 0 auto;
}

.stamp {
  display: inline-block;
  background: #f4efe4;
  color: #111;
  font-family: var(--serif);
  font-weight: 700;
  letter-spacing: 0.14em;
  font-size: 13px;
  padding: 7px 8px 6px;
  transform: rotate(-2deg);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25);
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #c9d4e4;
}

.title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  line-height: 1.1;
}

.top-right { display: flex; gap: 8px; align-items: center; }

.conn {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 4px 8px;
}

.conn.ok { background: #1d6b45; color: white; }
.conn.bad { background: var(--red); color: white; }

.nav { display: flex; background: rgba(255, 255, 255, 0.08); border-radius: 999px; padding: 3px; }

.navbtn {
  border: 0;
  background: transparent;
  color: #d5deea;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: 700;
}

.navbtn.on { background: #f4efe4; color: var(--navy); }

.wrap {
  width: min(1080px, calc(100% - 24px));
  margin: 18px auto 32px;
}

.wrap.narrow { width: min(740px, calc(100% - 24px)); }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; }

h1 { font-size: 34px; line-height: 1.1; }

.lede { color: var(--muted); margin: 6px 0 16px; }

.card, .section, .tcard, .part-card, .stat, .banner, .sheet {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.section { padding: 16px; margin: 0 0 12px; }

.crew-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.crew-toggle strong { flex: 1; }
.crew-body { margin-top: 8px; }

.section h2 {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 22px;
  margin-bottom: 4px;
}

.section h2 span {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--blue);
}

.hint { color: var(--muted); margin: 0 0 12px; }

.section.hot {
  background: var(--amber-bg);
  border-color: #e3c48a;
  box-shadow: inset 4px 0 0 var(--amber), var(--shadow);
}

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

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }

.field span, .lbl {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

input, textarea, select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: white;
  border: 1px solid #cfc6b6;
  border-radius: 10px;
  padding: 12px;
  min-height: 48px;
}

textarea { min-height: 140px; resize: vertical; line-height: 1.45; }
textarea.equip-notes { min-height: 88px; }

.work { min-height: 180px; }

.row-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 8px;
  background: white;
}

.chips, .seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

.chip, .seg button, .btn, .btn-ghost, .btn-send, .btn-danger {
  border-radius: 12px;
  border: 1px solid #cfc6b6;
  background: white;
  min-height: 44px;
  padding: 8px 12px;
  font-weight: 700;
}

.chip { color: var(--navy-2); }

.seg button { flex: 1 1 120px; }

.seg button.on { background: var(--navy); color: white; border-color: var(--navy); }

.seg button.on.danger { background: var(--red); border-color: var(--red); }

.btn, .btn-send {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.btn-send {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: #c8880d;
  min-height: 52px;
  font-size: 17px;
}

.btn-ghost { background: transparent; color: var(--navy); }
a.btn, a.btn-ghost, a.btn-send { text-decoration: none; }

.btn-danger { background: white; color: var(--red); border-color: #e4b4b0; }

.btn.big, .btn-send.big { width: 100%; min-height: 56px; font-size: 18px; }

button:disabled { opacity: 0.55; cursor: wait; }

.qty {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty input { width: 72px; text-align: center; padding-left: 6px; padding-right: 6px; }

.qty button, .stepper button {
  width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid #cfc6b6;
  background: white;
  font-size: 22px;
  line-height: 1;
}

.stepper { display: flex; gap: 8px; align-items: center; }

.stepper input { width: 88px; max-width: 88px; flex: 0 0 88px; text-align: center; }

.lede, .hint, .meta, .excerpt { overflow-wrap: anywhere; }

.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(239, 232, 218, 0.96);
  border-top: 1px solid var(--line);
}

.actionbar .btn-ghost { flex: 0 0 auto; }
.actionbar .btn-send { flex: 1; }

.form-error, .banner {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.form-error { background: var(--red-bg); color: var(--red); border: 1px solid #f0c2be; }

.banner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #fff8e8;
  border-color: #e3c48a;
}

.banner p { margin: 0; }

.shop-code, .office-code { letter-spacing: 0.14em; font-size: 1.2rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  text-align: left;
  padding: 12px;
  box-shadow: none;
  min-height: 76px;
}

.stat b { display: block; font-size: 28px; font-family: var(--serif); line-height: 1; }

.stat span { color: var(--muted); font-size: 13px; font-weight: 700; }

.stat.on { border-color: var(--navy); box-shadow: inset 0 0 0 2px var(--navy); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }

.filters button.on { background: var(--navy); color: white; border-color: var(--navy); }

.office-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.tcard, .part-card { display: block; padding: 14px; margin-bottom: 10px; color: inherit; text-decoration: none; }

.parts-heading {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
  margin-bottom: 8px;
}

.building { margin: 0 0 18px; }
.building-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 4px 0 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
}
.building-name { font-family: var(--serif); font-size: 22px; font-weight: 700; line-height: 1.2; flex: 1 1 160px; }
.building-toggle .meta { margin: 0; }
.building.down .building-name { box-shadow: inset 4px 0 0 var(--red); padding-left: 10px; }
.building-units { margin-top: 8px; }
.history-tickets { margin-top: 8px; }
.history-tickets .tcard { margin-left: 10px; }
.equip-toggle { margin-top: 2px; }
.equip-toggle .building-name { font-family: var(--sans); font-size: 16px; font-weight: 700; }
.equip-list { margin: 8px 0 4px 10px; }
.equip-card {
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.equip-card strong { display: block; }
.equip-card .meta { margin: 2px 0 0; overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.building .unit-group { margin-left: 10px; }

.unit-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.unit-group.down { box-shadow: inset 4px 0 0 var(--red), var(--shadow); }

.unit-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}

.unit-name { font-size: 17px; font-weight: 700; flex: 1 1 140px; }

.unit-caret { margin-left: auto; color: var(--blue); font-size: 13px; }

.unit-parts { padding: 0 10px 8px; }

.unit-parts .part-card { box-shadow: none; }

.part-card.locked input[readonly],
.part-card.locked select:disabled {
  background: #f6f3ec;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
  opacity: 1;
  cursor: default;
}

.part-actions { display: flex; justify-content: flex-end; }
.part-actions .linkish { min-height: 44px; padding: 10px 2px; }

.tcard-top, .part-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.tcard-top strong,
.part-top > div { flex: 1 1 180px; min-width: 0; }

.meta { color: var(--muted); font-size: 14px; margin-top: 4px; }

.meta.warn { color: var(--red); font-weight: 700; }

.excerpt { margin: 8px 0 0; color: var(--ink); }

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: #e7eef8;
  color: var(--navy-2);
}

.badge.wait { background: var(--amber-bg); color: #7a4d00; }
.badge.down { background: var(--red-bg); color: var(--red); }
.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.muted { background: #eeeae2; color: var(--muted); }

.linkish {
  border: 0;
  background: none;
  color: var(--blue);
  font-weight: 700;
  padding: 0;
  min-height: 0;
  text-decoration: underline;
}

.sign-wrap {
  background: white;
  border: 1px dashed #b7ad9c;
  border-radius: 12px;
  overflow: hidden;
}

canvas#sign {
  width: 100%;
  height: 140px;
  touch-action: none;
  display: block;
  background: white;
  cursor: crosshair;
}

.tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

.urlbox {
  font-family: Consolas, "Courier New", monospace;
  background: #122743;
  color: #f6f1e6;
  border-radius: 12px;
  padding: 12px;
  word-break: break-all;
}

.sheet { padding: 22px; }

.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 3px solid var(--blue);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.sheet-logo {
  height: 72px;
  width: auto;
  max-width: 168px;
  object-fit: contain;
  display: block;
}

.sheet h2 { font-size: 28px; color: var(--blue); font-style: italic; }

.sheet h3 {
  margin: 16px 0 6px;
  font-size: 16px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--blue);
}

.sheet p { margin: 0 0 8px; white-space: pre-wrap; }

.sheet table { width: 100%; border-collapse: collapse; }

.sheet th, .sheet td {
  border: 1px solid #d9d1c3;
  text-align: left;
  padding: 6px 8px;
  vertical-align: top;
  font-size: 14px;
}

.sheet th { background: #e7eef8; }

.fine {
  margin-top: 14px;
  font-size: 11px;
  color: var(--muted);
}

.sig-img { max-width: 280px; height: auto; background: white; }

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

.photo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.photo {
  margin: 0;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.photo img { display: block; width: 100%; height: 140px; object-fit: cover; background: var(--paper); }

.sheet .photo img { height: auto; max-height: 480px; object-fit: contain; }

.photo .linkish { margin: 6px 8px 8px; }

.sent {
  text-align: center;
  padding: 28px 16px;
}

.sent .mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-size: 36px;
  line-height: 72px;
  font-weight: 800;
}

.stack { display: flex; flex-direction: column; gap: 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%) translateY(8px);
  background: var(--navy);
  color: white;
  padding: 10px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 9;
  max-width: calc(100% - 24px);
}

#toast.show { opacity: 1; transform: translateX(-50%); }

.empty {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed #cfc6b6;
  border-radius: 12px;
}

@media (max-width: 720px) {
  .grid-2, .stats { grid-template-columns: 1fr 1fr; }
  .banner { flex-direction: column; align-items: stretch; }
  .conn { display: none; }
  h1 { font-size: 30px; }
  .top { flex-wrap: wrap; }
  .top-right, .nav { width: 100%; }
  .navbtn { flex: 1; padding: 0 8px; }
}

@media (min-width: 980px) {
  .office-grid { grid-template-columns: 1.35fr 0.8fr; align-items: start; }
  .part-list { display: grid; grid-template-columns: 1fr; gap: 0; }
}

@media print {
  body { background: white; padding: 0; }
  .top, .noprint, .actionbar, #toast { display: none !important; }
  .wrap { width: auto; margin: 0; max-width: none; }
  .sheet { box-shadow: none; border: 1px solid #222; }
}
