:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e3e5ea;
  --accent: #2563eb;
  --ok: #16a34a;
  --ok-bg: #e9f8ee;
  --warn: #dc2626;
  --warn-bg: #fdecec;
  --pending-bg: #eef0f3;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --card: #1f222a;
    --text: #e8e9ec;
    --muted: #9aa0ab;
    --border: #30333c;
    --accent: #5b8df7;
    --ok: #3ecf76;
    --ok-bg: #163322;
    --warn: #f06464;
    --warn-bg: #3a1d1d;
    --pending-bg: #2a2d35;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  padding-bottom: 40px;
}

header.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
}

header.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  margin-left: 14px;
}
header.topbar nav a.active { color: var(--accent); font-weight: 600; }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

select, input[type="date"], input[type="text"], input[type="time"], textarea {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 15px;
}

.seg {
  display: flex;
  background: var(--pending-bg);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.seg button.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.summary {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 14px;
}

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}

.room-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--pending-bg);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  min-height: 72px;
}
.room-tile .room-no { font-size: 17px; font-weight: 700; }
.room-tile .room-sub { font-size: 11px; color: var(--muted); }
.room-tile.inspected { background: var(--ok-bg); border-color: var(--ok); }
.room-tile.inspected .room-sub { color: var(--ok); }

button.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 15px;
  cursor: pointer;
}
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 11px 16px;
  cursor: pointer;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}

.field-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}
.field-row > div { flex: 1; min-width: 140px; }
.field-row label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field-row input { width: 100%; }

.group-title {
  font-weight: 700;
  font-size: 15px;
  margin: 18px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.sub-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0 6px;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.item-row:last-child { border-bottom: none; }
.item-label { font-size: 14px; }

.toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.toggle button {
  border: none;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  background: var(--card);
  color: var(--muted);
}
.toggle button.ok.active { background: var(--ok-bg); color: var(--ok); font-weight: 700; }
.toggle button.warn.active { background: var(--warn-bg); color: var(--warn); font-weight: 700; }

.note-input {
  width: 100%;
  margin-top: 6px;
  display: none;
}
.item-row.flagged + .note-input { display: block; }

textarea { width: 100%; min-height: 70px; resize: vertical; font-family: inherit; }

.action-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 14px 0 6px;
  display: flex;
  gap: 10px;
}
.action-bar button { flex: 1; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--ok-bg);
  color: var(--ok);
  font-weight: 600;
}
.badge.pending { background: var(--pending-bg); color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th, table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table th { color: var(--muted); font-size: 12px; font-weight: 600; }

a.back-link { color: var(--muted); text-decoration: none; font-size: 14px; }

.flag-count {
  color: var(--warn);
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
