:root {
  --bg: #f7fbfc;
  --surface: #ffffff;
  --ink: #11303a;
  --muted: #6c8089;
  --line: #d8e6eb;
  --accent: #0aa3c2;
  --accent-soft: #d9f1f6;
  --now: #fff7d6;
  --saved: #2f9e44;
  --error: #c92a2a;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

input {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: max(10px, env(safe-area-inset-top));
}

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

.nav-btn {
  background: var(--accent-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  font-size: 14px;
}

.nav-btn:hover {
  background: #c8e8ef;
}

.date-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  min-width: 200px;
  height: 40px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}

.date-btn:hover {
  background: var(--accent-soft);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.text-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 12px;
  height: 40px;
  font-size: 14px;
}

.text-btn:hover {
  background: var(--accent-soft);
}

.status {
  font-size: 13px;
  color: var(--muted);
  min-width: 60px;
}

.status.saved {
  color: var(--saved);
}

.status.error {
  color: var(--error);
}

.hidden-date {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  padding: 14px 12px 60px;
  max-width: 1400px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
}

.half {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.col-header {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  background: var(--accent-soft);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  position: sticky;
  top: var(--topbar-h, 60px);
  z-index: 5;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.col-header > div {
  padding: 8px 10px;
  text-align: center;
}

.col-header > div:first-child {
  text-align: left;
}

.row {
  display: grid;
  grid-template-columns: 90px 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.row.alt {
  background: #f3f9fb;
}

.row.now {
  background: var(--now);
}

.row.matched,
.row.matched.alt,
.row.matched.now {
  background: #e3f9e5;
}

.row.matched input {
  color: #2b6a30;
}

.row .time {
  padding: 8px 10px;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--muted);
  display: flex;
  align-items: center;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}

.row input {
  border: 0;
  background: transparent;
  padding: 8px 10px;
  width: 100%;
  font-size: 15px;
  color: var(--ink);
  border-right: 1px solid var(--line);
  outline: none;
  text-align: center;
}

.row input:last-child {
  border-right: 0;
}

.row input:focus {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  min-width: 280px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

dialog p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

dialog input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 16px;
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  margin: 16px 0 0;
}

dialog menu button {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

dialog menu button[value="ok"] {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.error {
  color: var(--error);
  font-size: 13px;
}

.drag-handle {
  position: absolute;
  width: 11px;
  height: 11px;
  background: var(--accent);
  border: 1.5px solid white;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: crosshair;
  z-index: 20;
  display: none;
  touch-action: none;
}

.drag-handle.visible {
  display: block;
}

input.selected {
  background: rgba(10, 163, 194, 0.12) !important;
}

input.fill-target {
  background: var(--accent-soft) !important;
  box-shadow: inset 0 0 0 1.5px var(--accent) !important;
}

body.dragging {
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 600px) {
  .topbar {
    flex-wrap: nowrap;
    gap: 6px;
    padding: 8px 8px;
  }
  .nav {
    gap: 4px;
    flex-shrink: 0;
  }
  .nav-btn {
    width: 36px;
    height: 36px;
  }
  .date-btn {
    min-width: 0;
    flex: 1 1 auto;
    padding: 6px 6px;
    height: 36px;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .actions {
    gap: 4px;
    flex-shrink: 0;
  }
  .text-btn {
    padding: 4px 10px;
    height: 36px;
    font-size: 12px;
  }
  .status {
    display: none;
  }
  .grid {
    padding: 10px 8px 60px;
    gap: 16px;
  }
  .row,
  .col-header {
    grid-template-columns: 78px 1fr 1fr;
  }
  .row .time {
    font-size: 13px;
    padding: 8px 8px;
  }
  .row input {
    font-size: 15px;
    padding: 10px 8px;
  }
  .col-header > div {
    padding: 6px 8px;
    font-size: 12px;
  }
}
