:root {
  --bg: #ffffff;
  --surface: #f5f7f6;
  --border: #dfe4e2;
  --text: #1b2421;
  --muted: #5d6b66;
  --green: #1e8e4e;
  --green-dark: #17723e;
  --red: #c0392b;
  --red-bg: #fdecea;
  --amber: #8a5a00;
  --amber-bg: #fff4d6;
  --blue: #1f5f99;
  --blue-bg: #e8f1fa;
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 19px; }
p { margin: 8px 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

.net-status {
  font-size: 14px;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.net-status.is-online { background: #e3f4ea; color: var(--green-dark); }
.net-status.is-offline { background: var(--amber-bg); color: var(--amber); }

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

.view { display: block; }

.banner {
  margin: 10px 16px 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 16px;
  max-width: 608px;
}
main .banner { margin: 0 0 12px; }
@media (min-width: 672px) {
  body > .banner { margin-left: auto; margin-right: auto; }
}
.banner-warn { background: var(--amber-bg); color: var(--amber); }
.banner-info { background: var(--blue-bg); color: var(--blue); }
.banner-error { background: var(--red-bg); color: var(--red); }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h2 { margin-bottom: 4px; }
.empty { text-align: center; padding: 28px 16px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 15px; }
.warn-text { color: var(--amber); font-weight: 600; }

.group-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--muted);
  margin: 18px 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
}
.group-title:first-child { margin-top: 4px; }

/* Task card */
.task {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--bg);
}
.task-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.task-time { font-size: 24px; font-weight: 700; }
.task-time-label { font-size: 14px; color: var(--muted); display: block; }

.badge {
  display: inline-block;
  font-size: 15px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-none { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.badge-ok { background: #e3f4ea; color: var(--green-dark); }
.badge-bad { background: var(--red-bg); color: var(--red); }
.badge-sync { background: var(--blue-bg); color: var(--blue); }
.badge-warn { background: var(--amber-bg); color: var(--amber); }

.meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 10px 0 0;
  font-size: 16px;
}
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 600; word-break: break-all; }

.route {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  border-top: 1px solid var(--border);
}
.route li {
  position: relative;
  padding: 8px 0 8px 64px;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}
.route li:last-child { border-bottom: 0; }
.route-tag {
  position: absolute;
  left: 0;
  top: 9px;
  font-size: 14px;
  font-weight: 700;
  width: 52px;
  text-align: center;
  border-radius: 6px;
  padding: 1px 0;
}
.route-from .route-tag { background: #e3f4ea; color: var(--green-dark); }
.route-stop .route-tag { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.route-to .route-tag { background: var(--blue-bg); color: var(--blue); }

.receipt-info { margin: 10px 0 0; font-size: 15px; color: var(--muted); }
.receipt-reason {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--surface);
  border-radius: 8px;
  font-size: 15px;
  word-break: break-word;
}

.task-actions { display: grid; gap: 10px; margin-top: 14px; }
.task-error { margin: 10px 0 0; }

/* Forms */
.field-label { display: block; font-weight: 600; margin: 14px 0 6px; }
.input, .textarea {
  width: 100%;
  font: inherit;
  font-size: 20px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
.textarea { font-size: 17px; min-height: 96px; resize: vertical; }
.input:focus, .textarea:focus { outline: none; border-color: var(--green); }
.input-large { letter-spacing: 0.05em; }
.field-error { color: var(--red); font-size: 15px; margin: 8px 0 0; }
.char-count { font-size: 14px; color: var(--muted); text-align: right; margin: 4px 0 0; }

.reason-form {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface);
}
.reason-form .field-label { margin-top: 0; }

/* Buttons */
.btn {
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  min-height: 56px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 2px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible { outline: 3px solid #8cc9a6; outline-offset: 2px; }
.btn-block { display: block; width: 100%; margin-top: 12px; }
.task-actions .btn-block, .dialog-actions .btn-block { margin-top: 0; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--green-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-danger-outline { background: var(--bg); color: var(--red); border-color: #e6b3ad; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-small { font-size: 16px; min-height: 44px; padding: 6px 14px; }
.btn-link {
  background: none;
  border: 0;
  color: var(--blue);
  font-size: 16px;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 0;
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: 12px;
  background: #1b2421;
  color: #fff;
  font-size: 17px;
  text-align: center;
}

/* Dialog */
.dialog {
  width: calc(100% - 32px);
  max-width: 440px;
  border: 0;
  border-radius: 16px;
  padding: 20px;
  color: var(--text);
  background: var(--bg);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog h2 { margin-bottom: 8px; }
.dialog-actions { display: grid; gap: 10px; margin-top: 16px; }
