:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #111827;
  --transfer: #f97316;
  --install: #16a34a;
  --wait: #ef4444;
  --break: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(82px + env(safe-area-inset-bottom));
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #e2e8f0;
  padding: 9px 12px;
}

.clock {
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
}

.tabs {
  position: sticky;
  top: 41px;
  z-index: 25;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid #e2e8f0;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

.tab {
  min-width: 150px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 16px;
  padding: 9px 11px;
  text-align: left;
  box-shadow: 0 1px 3px rgba(15,23,42,.08);
}

.tab.active {
  background: #111827;
  color: #fff;
  border-color: #111827;
}

.tab.today:not(.active) {
  border-color: #4f46e5;
  background: #eef2ff;
}

.tab-date {
  font-size: 12px;
  opacity: .75;
}

.tab-title {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-plus {
  min-width: 58px;
  justify-content: center;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  border-style: dashed;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px;
}

.day-card {
  background: var(--card);
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 1px 5px rgba(15,23,42,.1);
  margin-bottom: 12px;
}

.day-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.day-title {
  margin: 0;
  font-size: 22px;
}

.day-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.icon-actions {
  display: flex;
  gap: 7px;
}

.icon-btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
  border-radius: 12px;
  min-width: 40px;
  min-height: 38px;
  padding: 7px 10px;
  font-weight: 800;
}

.timeline {
  position: relative;
  display: grid;
  gap: 12px;
}

.now-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 3px solid var(--line);
  z-index: 10;
  pointer-events: none;
}

.now-line span {
  position: absolute;
  right: 0;
  top: -14px;
  background: var(--line);
  color: #fff;
  border-radius: 999px;
  font-size: 12px;
  padding: 2px 8px;
  font-weight: 800;
}

.empty {
  background: #fff;
  border: 2px dashed #cbd5e1;
  border-radius: 20px;
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.block {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-left-width: 8px;
  border-radius: 18px;
  box-shadow: 0 1px 4px rgba(15,23,42,.08);
  overflow: hidden;
}

.block.active {
  outline: 4px solid rgba(17,24,39,.22);
}

.block.transfer { border-left-color: var(--transfer); background: #fff7ed; }
.block.install { border-left-color: var(--install); background: #f0fdf4; }
.block.wait { border-left-color: var(--wait); background: #fef2f2; }
.block.break { border-left-color: var(--break); background: #eff6ff; }

.block-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(15,23,42,.10);
  padding: 8px 10px;
}

.block-time {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 900;
}

.block-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.drag-handle {
  cursor: grab;
  user-select: none;
  font-size: 25px;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 12px;
  border: 0;
  background: transparent;
}

.block-body {
  padding: 12px;
}

.block-kind {
  font-size: 12px;
  color: var(--muted);
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.block-title {
  font-size: 18px;
  font-weight: 900;
  margin-top: 2px;
}

.info-box {
  background: rgba(255,255,255,.7);
  border-radius: 14px;
  padding: 9px;
  margin-top: 10px;
  font-size: 14px;
}

.note {
  white-space: pre-wrap;
}

.link-pill, .share-pos {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  color: #1d4ed8;
  background: rgba(255,255,255,.85);
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 6px 10px;
  margin-top: 8px;
  font-weight: 800;
}

.share-pos {
  color: #111827;
}

.bottom-actions {
  position: fixed;
  z-index: 40;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.96);
  border-top: 1px solid #e2e8f0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  box-shadow: 0 -6px 20px rgba(15,23,42,.12);
}

.add-btn {
  border: 0;
  border-radius: 17px;
  color: #fff;
  min-height: 58px;
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(15,23,42,.18);
}

.add-btn span {
  display: block;
  font-size: 13px;
}

.add-btn.transfer { background: var(--transfer); }
.add-btn.install { background: var(--install); }
.add-btn.wait { background: var(--wait); }
.add-btn.break { background: var(--break); }

.modal-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  background: rgba(0,0,0,.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 16px;
  box-shadow: 0 -10px 35px rgba(0,0,0,.25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-title {
  font-size: 19px;
  font-weight: 900;
}

.form {
  display: grid;
  gap: 12px;
}

.field span {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 800;
  color: #334155;
}

.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 10px 12px;
  outline: none;
  background: #fff;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.primary {
  border: 0;
  background: #111827;
  color: #fff;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 900;
}

.danger {
  border: 0;
  background: #dc2626;
  color: #fff;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 900;
}

.secondary {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #111827;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 900;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 24px; }
}


.map-picker {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.map-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.map-results {
  display: grid;
  gap: 6px;
  max-height: 150px;
  overflow: auto;
}

.map-result {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  text-align: left;
  font-size: 14px;
}

.map-canvas {
  width: 100%;
  height: 320px;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  overflow: hidden;
  background: #e2e8f0;
}

.map-hint {
  color: #64748b;
  font-size: 13px;
}

.map-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}


.block-time-center {
  flex: 1;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 900;
  font-size: 14px;
  min-width: 0;
}
.block-time-center .time { font-weight: 900; }
.block-time-center .type { font-weight: 900; }
.block-time-center .dur { font-weight: 800; color: #475569; }
.block-time-center .sep { margin: 0 4px; color: #94a3b8; }
.block.transfer .block-time-center .type { color: var(--transfer); }
.block.install .block-time-center .type { color: var(--install); }
.block.wait .block-time-center .type { color: var(--wait); }
.block.break .block-time-center .type { color: var(--break); }

.route-map {
  width: 100%;
  height: 430px;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  overflow: hidden;
  background: #e2e8f0;
}
.route-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}
.route-item {
  display: grid;
  gap: 3px;
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 14px;
  padding: 9px 10px;
}
.route-item-title { font-weight: 900; }
.route-item-meta { font-size: 13px; color: #64748b; }


/* v2 header layout: time left, type centered, actions right */
.block-top {
  position: relative;
  min-height: 50px;
}

.block-time {
  font-size: 16px;
  font-weight: 950;
  z-index: 1;
}

.block-type-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 190px);
  text-align: center;
  font-weight: 950;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-type-center .sep {
  margin: 0 5px;
  color: #94a3b8;
}

.block-type-center .dur {
  color: #334155;
}

.block.transfer .block-type-center .type { color: var(--transfer); }
.block.install .block-type-center .type { color: var(--install); }
.block.wait .block-type-center .type { color: var(--wait); }
.block.break .block-type-center .type { color: var(--break); }

@media (max-width: 430px) {
  .block-top {
    min-height: 58px;
  }

  .block-time {
    font-size: 14px;
  }

  .block-type-center {
    top: 28px;
    max-width: calc(100% - 24px);
    font-size: 16px;
  }
}


/* v3: single locked installation bar with centered current time */
.topbar {
  display: none;
}

.tabs {
  top: 0;
}

.app {
  padding-top: 0;
}

.locked-day-card {
  position: sticky;
  top: 74px;
  z-index: 22;
  margin-left: -12px;
  margin-right: -12px;
  border-radius: 0 0 20px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
}

.locked-day-top {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
}

.day-main {
  min-width: 0;
  padding-right: 132px;
}

.locked-clock {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 17px;
  font-weight: 950;
  color: #111827;
}

.locked-day-card .icon-actions {
  justify-self: end;
  z-index: 1;
}

.locked-day-card .day-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-size: 19px;
}

.locked-day-card .day-meta {
  font-size: 13px;
}

@media (max-width: 560px) {
  .locked-day-card {
    top: 72px;
  }

  .locked-day-top {
    grid-template-columns: 1fr;
    min-height: 92px;
    align-items: start;
  }

  .day-main {
    padding-right: 0;
    padding-top: 34px;
  }

  .locked-clock {
    top: 4px;
    font-size: 16px;
  }

  .locked-day-card .icon-actions {
    position: absolute;
    right: 0;
    top: 38px;
  }

  .locked-day-card .day-title {
    max-width: calc(100% - 174px);
    font-size: 17px;
  }

  .locked-day-card .day-meta {
    max-width: calc(100% - 174px);
  }
}


/* v4 clock layout */
.locked-clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.locked-clock .date {
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
}

.locked-clock .time {
  font-size: 20px;
  font-weight: 950;
  color: #111827;
}


/* v5 completion, status and cleaner block controls */
.locked-day-card {
  padding-top: 12px;
  padding-bottom: 12px;
}

.locked-day-top {
  min-height: 92px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.day-status {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 58px;
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
  font-weight: 900;
}

.day-progress {
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 4px 9px;
}

.day-delta {
  background: #f1f5f9;
  color: #475569;
  border-radius: 999px;
  padding: 4px 9px;
}

.day-delta.good {
  background: #dcfce7;
  color: #15803d;
}

.day-delta.bad {
  background: #fee2e2;
  color: #b91c1c;
}

.block-actions {
  align-items: center;
}

.edit-icon,
.drag-handle {
  border: 0;
  background: transparent;
  min-width: 36px;
  min-height: 36px;
  border-radius: 12px;
  font-size: 150%;
  line-height: 1;
  padding: 3px 8px;
}

.edit-icon:active,
.drag-handle:active {
  background: rgba(15,23,42,.08);
}

.done-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 800;
  color: #334155;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255,255,255,.65);
}

.done-check input {
  width: 18px;
  height: 18px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-field input {
  width: 20px;
  height: 20px;
}

.check-field span {
  margin: 0;
}

@media (max-width: 560px) {
  .locked-day-card {
    top: 72px;
  }

  .locked-day-top {
    min-height: 128px;
  }

  .day-status {
    top: 72px;
    font-size: 13px;
  }

  .locked-day-card .icon-actions {
    top: 38px;
  }

  .block-top {
    min-height: 82px;
  }

  .block-type-center {
    top: 44px;
  }

  .block-actions {
    position: absolute;
    right: 4px;
    top: 4px;
  }

  .done-check span {
    display: none;
  }
}


/* v6: cleaner sticky header and completion moved to block footer */
.locked-day-card {
  padding: 14px 16px;
}

.locked-day-top {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(190px, auto) auto;
  align-items: center;
  gap: 16px;
  min-height: 74px;
}

.day-main {
  padding-right: 0;
}

.day-center {
  justify-self: center;
  display: grid;
  gap: 6px;
  text-align: center;
  min-width: 190px;
}

.locked-clock {
  position: static;
  transform: none;
}

.day-status {
  position: static;
  transform: none;
  justify-content: center;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-weight: 900;
}

.locked-day-card .icon-actions {
  justify-self: end;
  position: static;
}

.block-actions {
  min-width: 86px;
  justify-content: flex-end;
}

.block-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed rgba(15,23,42,.14);
}

.block-footer .done-check {
  background: rgba(255,255,255,.85);
}

@media (max-width: 720px) {
  .locked-day-top {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "center actions"
      "main main";
    gap: 8px 12px;
    min-height: 112px;
  }

  .day-center {
    grid-area: center;
    justify-self: start;
    text-align: left;
    min-width: 0;
  }

  .day-center .locked-clock {
    align-items: flex-start;
  }

  .day-status {
    justify-content: flex-start;
  }

  .day-main {
    grid-area: main;
    padding-top: 0;
  }

  .locked-day-card .icon-actions {
    grid-area: actions;
    justify-self: end;
    position: static;
  }

  .locked-day-card .day-title,
  .locked-day-card .day-meta {
    max-width: 100%;
  }
}

@media (max-width: 430px) {
  .locked-day-top {
    grid-template-columns: 1fr;
    grid-template-areas:
      "center"
      "actions"
      "main";
    min-height: 168px;
  }

  .locked-day-card .icon-actions {
    justify-self: stretch;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .locked-day-card .icon-btn {
    width: 100%;
  }

  .block-top {
    min-height: 58px;
  }

  .block-type-center {
    top: 28px;
  }

  .block-actions {
    position: absolute;
    right: 4px;
    top: 4px;
  }

  .done-check span {
    display: inline;
  }
}


/* v7: keep block header as a single row and center day clock/status precisely */
.locked-day-top {
  grid-template-columns: minmax(0, 1fr) minmax(190px, 240px) minmax(0, 1fr);
}

.day-main {
  justify-self: start;
  min-width: 0;
}

.day-center {
  justify-self: center;
  align-self: center;
  width: 100%;
  min-width: 0;
  text-align: center;
}

.day-center .locked-clock {
  align-items: center;
}

.day-status {
  justify-content: center;
}

.locked-day-card .icon-actions {
  justify-self: end;
}

.block-top {
  display: grid;
  grid-template-columns: minmax(115px, auto) minmax(125px, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 58px;
}

.block-time {
  white-space: nowrap;
  justify-self: start;
}

.block-type-center {
  position: static;
  transform: none;
  justify-self: center;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-actions {
  position: static;
  justify-self: end;
  min-width: 82px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .locked-day-top {
    grid-template-columns: minmax(0, 1fr) minmax(150px, 210px) minmax(0, 1fr);
    grid-template-areas: "main center actions";
    min-height: 82px;
  }

  .day-main {
    grid-area: main;
  }

  .day-center {
    grid-area: center;
    justify-self: center;
    text-align: center;
  }

  .day-center .locked-clock {
    align-items: center;
  }

  .day-status {
    justify-content: center;
  }

  .locked-day-card .icon-actions {
    grid-area: actions;
    justify-self: end;
  }

  .locked-day-card .day-title,
  .locked-day-card .day-meta {
    max-width: 100%;
  }

  .block-top {
    grid-template-columns: minmax(108px, auto) minmax(105px, 1fr) auto;
    min-height: 56px;
  }

  .block-type-center {
    top: auto;
    font-size: 16px;
  }

  .block-actions {
    position: static;
    right: auto;
    top: auto;
  }
}

@media (max-width: 430px) {
  .locked-day-top {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "center actions"
      "main main";
    min-height: 118px;
  }

  .day-center {
    justify-self: start;
    text-align: left;
  }

  .day-center .locked-clock {
    align-items: flex-start;
  }

  .day-status {
    justify-content: flex-start;
  }

  .locked-day-card .icon-actions {
    justify-self: end;
    display: flex;
  }

  .block-top {
    grid-template-columns: minmax(102px, auto) minmax(90px, 1fr) auto;
    gap: 5px;
    min-height: 54px;
  }

  .block-time {
    font-size: 14px;
  }

  .block-type-center {
    font-size: 15px;
  }

  .edit-icon,
  .drag-handle {
    min-width: 30px;
    padding-left: 4px;
    padding-right: 4px;
  }
}
