:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --ink: #1c2b26;
  --muted: #5a6e66;
  --line: #d5e0db;
  --brand: #1a5f4a;
  --brand-dark: #0d3d30;
  --brand-soft: #e8f5f0;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --danger: #8b1e1e;
  --danger-bg: #fdeceb;
  --ok: #1a5f4a;
  --ok-bg: #e8f5f0;
  --shadow: 0 1px 3px rgba(28, 43, 38, 0.08);
  --radius: 12px;
  --touch: 48px;
  --font: "Segoe UI", "Roboto", "Noto Sans", system-ui, sans-serif;
  --mono: "Roboto Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

button {
  min-height: var(--touch);
  border: 0;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
button:active { transform: scale(0.98); }
button.secondary {
  background: var(--surface);
  color: var(--brand-dark);
  border: 1px solid var(--line);
}
button.ghost {
  background: transparent;
  color: var(--brand-dark);
  border: 1px solid transparent;
}
button.warn { background: #b36b00; }
button.danger { background: var(--danger); }
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--brand-dark);
  color: #f5fffa;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  flex: 1;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255,255,255,0.12);
}
.badge.online { background: #1f8a66; }
.badge.offline { background: #8a5a18; }
.badge.pending { background: #355f8a; }

.install-btn {
  min-height: 40px;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: #f5fffa;
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}
.install-btn:active { transform: scale(0.97); }
.install-btn.installed {
  background: rgba(255,255,255,0.14);
  color: #d9fff0;
  box-shadow: none;
}

.context-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 160px;
  flex: 1;
}
.field label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea,
.cell-input {
  min-height: var(--touch);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  background: #fff;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.cell-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.main {
  padding: 1rem;
  overflow: auto;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.85rem;
}
.form-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 150px;
  text-align: left;
  color: inherit;
}
.form-card .code {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--brand);
}
.form-card h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}
.form-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  flex: 1;
}
.form-card .meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  background: var(--brand-soft);
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}
.panel-head .sub {
  color: var(--muted);
  font-size: 0.85rem;
}
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.panel-body { padding: 0.75rem; }

.hint {
  margin: 0 0 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: var(--warn-bg);
  color: #5c3a00;
  font-size: 0.88rem;
  line-height: 1.35;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100dvh - 280px);
  border: 1px solid var(--line);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}
table.sheet {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  background: #fff;
}
table.sheet th,
table.sheet td {
  border: 1px solid var(--line);
  padding: 0.35rem;
  vertical-align: middle;
  font-size: 0.82rem;
}
table.sheet th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef5f1;
  color: var(--brand-dark);
  font-weight: 700;
  text-align: center;
  white-space: normal;
  min-width: 110px;
  line-height: 1.2;
}
table.sheet td.sticky-col,
table.sheet th.sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #f8fbf9;
}
table.sheet th.sticky-col { z-index: 3; }
table.sheet .cell-input {
  width: 100%;
  min-width: 100px;
  min-height: 44px;
  border-radius: 8px;
  border-color: #c9d7d0;
  padding: 0.4rem 0.5rem;
}
table.sheet select.cell-input { min-width: 90px; }
table.sheet input[type="date"].cell-input,
table.sheet input[type="number"].cell-input { min-width: 120px; }

.checklist {
  display: grid;
  gap: 0.55rem;
}
.check-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) repeat(5, minmax(120px, 1fr));
  gap: 0.4rem;
  align-items: center;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.check-row .item-name {
  font-weight: 650;
  font-size: 0.9rem;
}
@media (max-width: 900px) {
  .check-row {
    grid-template-columns: 1fr 1fr;
  }
  .check-row .item-name { grid-column: 1 / -1; }
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  z-index: 20;
}
.bottom-nav button {
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 56px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 10px;
}
.bottom-nav button.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.bottom-nav .ico { font-size: 1.15rem; line-height: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 20, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(560px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 1.1rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.modal h3 { margin: 0 0 0.5rem; }
.modal p { margin: 0 0 1rem; color: var(--muted); line-height: 1.4; }
.modal .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.status-list {
  display: grid;
  gap: 0.65rem;
}
.status-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem;
  background: #fff;
}
.status-item strong { display: block; margin-bottom: 0.25rem; }
.status-item .row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

.hidden { display: none !important; }

@media (min-width: 900px) {
  .app-shell {
    grid-template-columns: 220px 1fr;
    grid-template-rows: auto 1fr;
  }
  .topbar { grid-column: 1 / -1; }
  .bottom-nav {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: 1fr;
    position: sticky;
    top: 56px;
    bottom: auto;
    height: calc(100dvh - 56px);
    border-top: 0;
    border-right: 1px solid var(--line);
    align-content: start;
    padding-top: 0.75rem;
  }
  .bottom-nav button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.65rem;
    font-size: 0.9rem;
    min-height: 52px;
    padding-left: 0.9rem;
  }
  .main-wrap {
    grid-column: 2;
    display: grid;
    grid-template-rows: auto 1fr;
    min-width: 0;
  }
  .table-wrap { max-height: calc(100dvh - 220px); }
}
