:root {
  color-scheme: dark;
  --bg: #101418;
  --surface: #171d23;
  --surface-2: #1f2830;
  --line: #33414d;
  --text: #f2f6f8;
  --muted: #9facb8;
  --accent: #2fb7c8;
  --accent-2: #8cc63f;
  --danger: #e5484d;
  --warn: #f59e0b;
  --info: #3b82f6;
  --rescue: #a855f7;
  --shadow: 0 16px 40px rgba(0, 0, 0, .25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button:disabled {
  cursor: progress;
  opacity: .62;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 12px;
  background: rgba(16, 20, 24, .96);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 22px;
}

.sync-pill,
.level-badge,
.time-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 700;
}

.content {
  padding: 18px;
  padding-bottom: 92px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head p,
.status-card p,
.task-card p,
.fault-card p,
.meta-row {
  color: var(--muted);
  line-height: 1.55;
}

.controls {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.segmented {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.segmented button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

.segmented button.active {
  border-color: var(--accent);
  background: rgba(47, 183, 200, .16);
  color: #d9fbff;
}

.action-btn {
  min-height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0 14px;
  color: #d9fbff;
  background: rgba(47, 183, 200, .16);
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.action-btn:active {
  transform: translateY(1px);
}

.segmented button[data-set-id="weekdayPunch"] {
  border-color: rgba(47, 183, 200, .45);
}

.segmented button[data-set-id="weekdayPunch"].active {
  border-color: #2fb7c8;
  background: rgba(47, 183, 200, .2);
  color: #d9fbff;
}

.segmented button[data-set-id="vacation"] {
  border-color: rgba(140, 198, 63, .45);
}

.segmented button[data-set-id="vacation"].active {
  border-color: #8cc63f;
  background: rgba(140, 198, 63, .2);
  color: #ecffd9;
}

.segmented button[data-set-id="holiday"] {
  border-color: rgba(245, 158, 11, .45);
}

.segmented button[data-set-id="holiday"].active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, .2);
  color: #ffe8ba;
}

.segmented.compact button {
  min-height: 40px;
  padding: 0 12px;
}

.search-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.search-field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  outline: none;
  color: var(--text);
  background: var(--surface);
}

.search-field input:focus {
  border-color: var(--accent);
}

.task-layout {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.task-list {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.task-list-item {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.task-card,
.fault-card,
.status-card,
.task-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.task-card {
  padding: 12px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
}

.task-card.active {
  border-color: var(--accent);
  background: rgba(47, 183, 200, .12);
}

.task-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 16px;
  line-height: 1.35;
}

.task-card p {
  font-size: 13px;
  line-height: 1.45;
}

.task-detail {
  min-width: 0;
  padding: 16px;
  overflow: hidden;
}

.inline-task-detail {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.detail-header {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.detail-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.meta-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.meta-box span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.duty-table {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.duty-row {
  display: grid;
  grid-template-columns: 58px 58px minmax(76px, .8fr) 52px minmax(150px, 1.4fr) minmax(150px, 1.4fr);
  min-width: 720px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

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

.duty-row > div {
  min-width: 0;
  padding: 9px 8px;
  line-height: 1.35;
  word-break: break-word;
}

.duty-head {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 800;
}

.duty-time,
.duty-kind {
  color: #d9fbff;
  font-weight: 800;
  white-space: nowrap;
}

.duty-train {
  color: #facc15;
  font-weight: 900;
  white-space: nowrap;
}

.duty-route,
.duty-note {
  color: var(--muted);
}

.detail-section {
  margin-top: 18px;
}

.detail-section h3 {
  margin-bottom: 10px;
  font-size: 18px;
}

.depart-list {
  display: grid;
  gap: 8px;
}

.depart-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.reminders {
  white-space: pre-line;
  color: var(--muted);
  line-height: 1.7;
}

.fault-grid,
.status-grid {
  display: grid;
  gap: 12px;
}

.fault-card,
.status-card {
  padding: 14px;
}

.fault-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.fault-code {
  color: #d9fbff;
  font-size: 20px;
  font-weight: 900;
}

.fault-fields {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.field-row {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.field-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-row strong {
  display: block;
  margin-top: 3px;
  line-height: 1.55;
}

.level-ERT {
  border-color: rgba(229, 72, 77, .55);
  background: rgba(229, 72, 77, .18);
  color: #ffd6d8;
}

.level-EOD {
  border-color: rgba(245, 158, 11, .55);
  background: rgba(245, 158, 11, .18);
  color: #ffe8ba;
}

.level-RTD {
  border-color: rgba(59, 130, 246, .55);
  background: rgba(59, 130, 246, .18);
  color: #d8e8ff;
}

.level-RES {
  border-color: rgba(168, 85, 247, .55);
  background: rgba(168, 85, 247, .18);
  color: #efd9ff;
}

.status-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 22px;
}

.empty-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(16, 20, 24, .96);
}

.nav-btn {
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.nav-btn.active {
  border-color: var(--accent);
  color: #d9fbff;
  background: rgba(47, 183, 200, .16);
}

@media (min-width: 860px) {
  .content {
    padding: 22px;
    padding-bottom: 92px;
  }

  .controls {
    grid-template-columns: minmax(240px, auto) 1fr;
    align-items: end;
  }

  #viewFaults .controls {
    grid-template-columns: 1fr auto;
  }

  .task-layout {
    grid-template-columns: minmax(230px, 26%) minmax(0, 1fr);
    align-items: start;
  }

  .task-list,
  .task-detail {
    max-height: calc(100vh - 230px);
    overflow: auto;
  }

  .inline-task-detail {
    display: none;
  }

  .fault-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: flex-start;
  }

  .section-head {
    display: grid;
  }

  .action-btn {
    width: 100%;
  }

  .task-layout > .task-detail {
    display: none;
  }

  .inline-task-detail {
    padding: 12px;
    box-shadow: none;
  }

  h1 {
    font-size: 21px;
  }

  .sync-pill {
    display: none;
  }

  .meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .meta-box {
    padding: 8px;
  }

  .meta-box span {
    margin-bottom: 2px;
    font-size: 11px;
  }

  .meta-box strong {
    display: block;
    overflow-wrap: anywhere;
    font-size: 14px;
    line-height: 1.25;
  }

  .duty-row {
    grid-template-columns: 56px 56px 76px 48px 140px 140px;
    min-width: 620px;
  }

  .duty-row > div {
    padding: 8px 7px;
    font-size: 14px;
  }

  .depart-row {
    grid-template-columns: 48px minmax(0, 1fr) 52px;
    gap: 8px;
    padding: 8px;
    align-items: center;
  }

  .depart-row strong,
  .depart-row span {
    min-width: 0;
    font-size: 14px;
    line-height: 1.3;
  }

  .depart-row span {
    overflow-wrap: anywhere;
  }

  .detail-section {
    margin-top: 14px;
  }

  .detail-section h3 {
    margin-bottom: 8px;
    font-size: 16px;
  }
}
