:root {
  color-scheme: light;
  --ink: #191919;
  --muted: #888888;
  --line: #e5e5e5;
  --paper: #ededed;
  --card: #ffffff;
  --header: #ededed;
  --header-line: #d9d9d9;
  --tab: #f7f7f7;
  --field: #ffffff;
  --green: #07c160;
  --link: #576b95;
  --overdue: #fa5151;
}

html[data-theme="night"] {
  color-scheme: dark;
  --ink: #f5f5f5;
  --muted: #d0d0d0;
  --line: #7a7a7a;
  --paper: #4f4f4f;
  --card: #5c5c5c;
  --header: #4f4f4f;
  --header-line: #6a6a6a;
  --tab: #585858;
  --field: #6a6a6a;
  --link: #9db4d8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  font-size: 16px;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: transparent; cursor: pointer; }

#app {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 64px;
  background: var(--paper);
}

#app.wide { width: min(980px, 100%); }

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  height: 44px;
  background: var(--header);
  border-bottom: 1px solid var(--header-line);
}

h1 {
  margin: 0;
  grid-column: 1 / -1;
  grid-row: 1;
  padding: 0 112px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0;
  pointer-events: none;
}

.nav-left {
  grid-column: 1;
  grid-row: 1;
  z-index: 1;
  display: flex;
  align-items: center;
}

.nav-left button,
.nav-left button.secondary { color: var(--ink); padding-left: 8px; }
.nav-left button[data-action="list"]::before,
.nav-left button[data-action="capture"]::before,
.nav-left button[data-action="patients"]::before {
  content: "‹";
  margin-right: 2px;
  font-size: 22px;
  line-height: 0;
}

.nav {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.nav button,
button.secondary,
button.quiet,
button.star {
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 0;
  padding: 8px 12px;
}

.nav button { color: var(--green); }
button.theme { color: var(--ink); }
button.secondary { color: var(--link); }
button.quiet { color: var(--green); margin-top: 14px; padding: 0 0 0 8px; }
button.star {
  width: 28px;
  height: 24px;
  margin-top: 14px;
  padding: 0;
  font-size: 16px;
  color: #c8c8c8;
}
button.star.on { color: #fa9d3b; }

button.primary {
  display: block;
  width: calc(100% - 32px);
  height: 44px;
  margin: 16px auto 0;
  border: 0;
  border-radius: 4px;
  background: var(--green);
  color: #fff;
  font-size: 17px;
}

button:disabled { opacity: 0.45; }

.notice, .sub, .error, .done {
  margin: 0;
  padding: 8px 16px;
  color: var(--muted);
  font-size: 13px;
}

.notice { color: var(--green); }
.gate-switch {
  display: block;
  width: 100%;
  margin: 8px 0 24px;
  text-align: center;
  color: var(--link);
}

.error:empty { display: none; }
.error { color: var(--overdue); }

.card {
  background: var(--card);
  margin-top: 8px;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.card > h2 {
  margin: 0;
  padding: 8px 16px 4px;
  background: var(--paper);
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 140px;
  margin: 0;
  padding: 16px;
  border: 0;
  border-radius: 0;
  background: var(--field);
  resize: vertical;
  text-align: left;
}

.cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.cell label {
  flex: none;
  width: 76px;
  margin: 0;
  color: var(--ink);
  font-size: 16px;
}

.cell input,
.cell select {
  flex: 1;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 12px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  text-align: right;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
}

.choice input { margin: 0; }

.card > label {
  display: block;
  margin: 0;
  padding: 10px 16px 0;
  color: var(--muted);
  font-size: 13px;
}

.quote {
  margin: 0;
  padding: 12px 16px;
  border: 0;
  background: var(--paper);
  color: var(--muted);
  font-size: 14px;
}

.swipe {
  position: relative;
  overflow: hidden;
  background: var(--card);
}

.swipe-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

.swipe-actions button {
  width: 72px;
  border-radius: 0;
  color: #fff;
}

.swipe-done { background: var(--green); }
.swipe-delay { background: #d4880f; }
.swipe-close { background: var(--overdue); }

.swipe-front {
  position: relative;
  z-index: 1;
  background: var(--card);
  transition: transform 0.18s ease;
  touch-action: pan-y;
}

.swipe.open .swipe-actions { z-index: 2; }
.swipe.open .swipe-front { transform: translateX(-216px); }
.swipe.open .row {
  width: calc(100% - 216px);
  transform: translateX(216px);
}

.swipe-panel {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.swipe-panel p {
  margin: 0;
  padding: 12px 16px 0;
}

button.primary.danger { background: var(--overdue); }

.row-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.row {
  display: block;
  position: relative;
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 12px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.swipe .row { padding-right: 118px; }

.edited {
  position: absolute;
  right: 0;
  bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
}

.row strong { display: block; font-size: 17px; font-weight: 500; }
.row span { display: block; margin-top: 2px; color: var(--muted); font-size: 14px; }
.row em { font-style: normal; }
.row .warn, .warn { color: var(--overdue); font-weight: 400; }
.overdue { color: var(--overdue); }
.done-flag { color: var(--green); font-style: normal; }
.done-row > span:nth-of-type(1) { color: var(--muted); text-decoration: line-through; }

.card > .row { padding: 12px 16px; border-bottom: 1px solid var(--line); }

.empty {
  margin: 0;
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  background: transparent;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 16px 16px;
}

.actions .primary { margin: 12px 0 4px; }
.actions button:not(.primary) { color: var(--link); }

.finder {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 8px 0;
}

#patient-query {
  display: block;
  flex: 1;
  width: auto;
  min-width: 0;
  height: 36px;
  margin: 0;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  background: var(--field);
  text-align: left;
}

.finder-mode {
  display: flex;
  flex: none;
  overflow: hidden;
  border-radius: 4px;
  background: var(--field);
}

.finder-mode button {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 14px;
}

.finder-mode button.on { color: var(--green); }

.list-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 10px 12px 0;
  background: var(--card);
  border-radius: 8px;
  overflow: hidden;
}

.list-tabs button {
  height: 40px;
  border-radius: 0;
  color: var(--muted);
  font-size: 15px;
}

.list-tabs button em {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e23b32;
  color: #fff;
  font-style: normal;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
}

.list-tabs button.on {
  color: var(--green);
  box-shadow: inset 0 -2px 0 var(--green);
}


.cal-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
}

.cal-toolbar strong {
  font-size: 22px;
  font-weight: 650;
}

.cal-toolbar button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 22px;
}

.cal-today {
  width: auto !important;
  margin-left: auto;
  padding: 0 12px;
  border: 1px solid var(--line) !important;
  border-radius: 999px !important;
  font-size: 14px !important;
}

.cal-week,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-week {
  padding: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.cal-grid {
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: var(--card);
}

.cal-day {
  min-height: 96px;
  padding: 4px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
}

.cal-day.out { background: var(--paper); }
.cal-day.selected { box-shadow: inset 0 0 0 2px var(--green); background: color-mix(in srgb, var(--green) 14%, var(--card)); }
.cal-day.selected.out { background: color-mix(in srgb, var(--green) 10%, var(--paper)); }

#cal-selected { scroll-margin-bottom: 70px; }

.cal-num {
  width: 24px;
  height: 24px;
  margin: 0 0 2px;
  padding: 0;
  border-radius: 50%;
  color: var(--ink);
  font-size: 13px;
  line-height: 24px;
  text-align: center;
}

.cal-day.out .cal-num { color: var(--muted); }
.cal-day.today .cal-num { background: #e23b32; color: #fff; }

.cal-chip,
.cal-more {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 1px 4px;
  border-radius: 4px;
  overflow: hidden;
  color: #fff;
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.cal-chip .mark {
  display: inline-block;
  margin-right: 3px;
  padding: 0 3px;
  border-radius: 2px;
  background: #fff;
  color: #333;
  font-style: normal;
  font-weight: 700;
  line-height: 1.2;
}

.cal-chip .mark.late { background: #e23b32; color: #fff; }
.cal-chip.done span { text-decoration: line-through; }
.cal-more { background: transparent; color: var(--muted); padding-left: 2px; }

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 3;
  display: flex;
  width: min(480px, 100%);
  height: 50px;
  transform: translateX(-50%);
  background: var(--tab);
  border-top: 1px solid var(--header-line);
}

.tabbar button {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
}

.tabbar button.on { color: var(--green); }

#app.wide .tabbar { width: min(980px, 100%); }
