:root {
  --ink: #1c1915;
  --muted: #6e675c;
  --paper: #f3efe6;
  --card: #fbf8f2;
  --line: #ddd4c6;
  --navy: #1b2a4a;
  --navy-2: #2c4168;
  --crimson: #9e2b3a;
  --lunch: #c47a32;
  --dinner: #6a3546;
  --road: #1b2a4a;
  --ok: #2f5d50;
  --danger: #9e2b3a;
  --shadow: 0 18px 50px rgba(28, 25, 21, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Source Han Sans SC", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff8ea 0%, transparent 50%),
    var(--paper);
}

.hidden { display: none !important; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.ghost, .primary, .danger, .login-card button {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
}
.ghost { background: #efe8da; color: var(--ink); }
.ghost:hover { background: #e5dccb; }
.primary { background: var(--navy); color: #fff; }
.danger { background: var(--danger); color: #fff; }
.error { color: var(--danger); min-height: 1.2em; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  display: grid;
  gap: 12px;
}
.login-kicker {
  margin: 0;
  letter-spacing: 0.28em;
  font-size: 12px;
  color: var(--crimson);
  text-transform: none;
}
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: 0.08em; }
.login-sub { margin: 0 0 8px; color: var(--muted); }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 1.2em;
}
.password-toggle {
  position: static;
  flex: 0 0 auto;
  background: transparent !important;
  color: var(--muted) !important;
  border: 1px solid var(--line) !important;
  box-shadow: none !important;
  border-radius: 4px !important;
  padding: 2px 10px !important;
  font-size: 12px !important;
  line-height: 1.4;
  cursor: pointer;
  width: auto !important;
  z-index: 2;
}
.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--navy) !important;
  background: #f3eee4 !important;
  outline: none;
}
.password-toggle[aria-pressed="true"] {
  color: var(--navy) !important;
  border-color: #b48642 !important;
}
.form .field-head {
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-help { margin: 0; font-size: 13px; }
.login-help a { color: var(--navy); }
.check { display: flex; align-items: center; gap: 8px; }
.top-actions a.ghost {
  display: inline-block;
  text-decoration: none;
  line-height: 1.2;
}
.login-card button { background: var(--navy); color: #fff; padding: 11px; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--navy);
  color: #f6f1e6;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-home {
  color: #e2c48a;
  text-decoration: none;
  font-size: 12px;
  letter-spacing: 0.08em;
}
.brand-home:hover { text-decoration: underline; }
.brand-mark { font-size: 12px; letter-spacing: 0.22em; color: #e2c48a; }
.tabs { display: flex; background: #132038; padding: 4px; border-radius: 8px; }
.tab {
  background: transparent;
  color: #c9d3e5;
  border: 0;
  padding: 8px 18px;
  border-radius: 6px;
}
.tab.is-on { background: #f3efe6; color: var(--navy); }
.top-actions { justify-self: end; display: flex; gap: 8px; }
.top-actions .ghost { background: #2c4168; color: #f6f1e6; }

main { padding: 16px 20px 32px; }
.week-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.week-bar h2 { margin: 0 0 0 8px; font-size: 18px; font-weight: 600; }
.week-bar .primary { margin-left: auto; }

.grid-wrap {
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: calc(100vh - 140px);
}
.road-table {
  --slot-h: 36px;
  border-collapse: collapse;
  width: 100%;
  min-width: 980px;
  table-layout: fixed;
  font-size: 12px;
}
.road-table th, .road-table td {
  border: 1px solid var(--line);
  vertical-align: top;
}
.road-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #ebe4d6;
  padding: 8px 6px;
  font-weight: 600;
}
.hd-week, .hd-date { display: inline; }
.hd-week::after { content: " "; }
.day-region {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--navy);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 4px;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.cal-nav-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  color: var(--navy);
  font-size: 20px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.cal-nav-btn:hover:not(:disabled) { border-color: var(--navy); }
.cal-nav-btn:disabled { opacity: 0.35; cursor: default; }
.cal-caption {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}
.cal-nav .cal-caption {
  margin: 0;
  flex: 1;
  text-align: center;
}
.cal-picked {
  font-size: 12px;
  color: var(--navy);
  margin-bottom: 8px;
}
.cal-mon {
  display: block;
  font-size: 10px;
  line-height: 1.1;
  opacity: 0.75;
}
.cal-day { display: block; font-size: 13px; line-height: 1.2; }
.cal button {
  display: grid;
  justify-items: center;
  padding: 4px 0;
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 10px;
  }
  .brand { flex-wrap: wrap; gap: 6px; }
  .brand-home { font-size: 11px; }
  .top-actions { justify-self: stretch; }
  .top-actions .ghost, .tab { padding: 6px 10px; font-size: 13px; }
  main { padding: 8px 8px 16px; }
  .week-bar { flex-wrap: wrap; gap: 6px; }
  .week-bar h2 { margin: 0; font-size: 13px; width: 100%; }
  .ghost, .primary { padding: 6px 10px; font-size: 13px; }

  .grid-wrap {
    overflow-x: hidden;
    overflow-y: auto;
    max-height: calc(100dvh - 168px);
    border-radius: 8px;
  }
  .road-table {
    min-width: 0;
    width: 100%;
    font-size: 10px;
  }
  .road-table thead th {
    padding: 4px 1px;
    line-height: 1.15;
  }
  .hd-week, .hd-date { display: block; }
  .hd-week::after { content: none; }
  .hd-week { font-size: 10px; }
  .hd-date { font-size: 9px; font-weight: 500; color: var(--muted); }
  .day-region {
    margin-top: 2px;
    font-size: 9px;
    padding: 0 1px;
  }
  .road-table .time {
    width: 32px;
    font-size: 9px;
    padding: 0 1px;
  }
  .road-table { --slot-h: 28px; }
  .road-table td.slot { height: var(--slot-h); max-height: var(--slot-h); }
  .block {
    padding: 1px 2px;
    min-height: 0;
    height: calc(var(--slot-h) - 2px);
    font-size: 9px;
    overflow: hidden;
    line-height: 1.1;
  }
  .block.span-2 { height: calc(var(--slot-h) * 2 - 2px); }
  .block.span-3 { height: calc(var(--slot-h) * 3 - 2px); }
  .block.span-4 { height: calc(var(--slot-h) * 4 - 2px); }
  .block small { display: none; }

  .modal { padding: 8px; }
  .modal-card { padding: 14px; }
  .form-row { grid-template-columns: 1fr; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; }
}
.road-table .time {
  width: 44px;
  padding-left: 2px;
  padding-right: 2px;
  text-align: center;
  color: var(--muted);
  background: #f7f3ea;
  font-variant-numeric: tabular-nums;
}
.road-table tbody tr {
  height: var(--slot-h);
}
.road-table tbody th.time {
  height: var(--slot-h);
  max-height: var(--slot-h);
  box-sizing: border-box;
  padding-top: 0;
  padding-bottom: 0;
  vertical-align: middle;
}
.road-table td.slot {
  height: var(--slot-h);
  max-height: var(--slot-h);
  padding: 1px;
  box-sizing: border-box;
  cursor: pointer;
  background: #fff;
  overflow: visible;
  position: relative;
  vertical-align: top;
}
.road-table td.slot[data-span="2"],
.road-table td.slot[rowspan="2"] {
  height: calc(var(--slot-h) * 2);
  max-height: calc(var(--slot-h) * 2);
}
.road-table td.slot[data-span="3"],
.road-table td.slot[rowspan="3"] {
  height: calc(var(--slot-h) * 3);
  max-height: calc(var(--slot-h) * 3);
}
.road-table td.slot[data-span="4"],
.road-table td.slot[rowspan="4"] {
  height: calc(var(--slot-h) * 4);
  max-height: calc(var(--slot-h) * 4);
}
.road-table td.slot:hover { background: #fff7e8; }
.block {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: calc(var(--slot-h) - 2px);
  min-height: 0;
  padding: 2px 5px;
  color: #fff;
  border: 0;
  text-align: left;
  border-radius: 3px;
  line-height: 1.15;
  overflow: hidden;
  position: relative;
  z-index: 1;
}
.block.span-2 { height: calc(var(--slot-h) * 2 - 2px); z-index: 2; }
.block.span-3 { height: calc(var(--slot-h) * 3 - 2px); z-index: 2; }
.block.span-4 { height: calc(var(--slot-h) * 4 - 2px); z-index: 2; }
.block.span-5 { height: calc(var(--slot-h) * 5 - 2px); z-index: 2; }
.block.span-6 { height: calc(var(--slot-h) * 6 - 2px); z-index: 2; }
.block.span-7 { height: calc(var(--slot-h) * 7 - 2px); z-index: 2; }
.block.span-8 { height: calc(var(--slot-h) * 8 - 2px); z-index: 2; }
.block.t-路演 { background: var(--road); }
.block.t-午餐 { background: var(--lunch); }
.block.t-晚餐 { background: var(--dinner); }
.block small { display: block; opacity: 0.85; font-weight: 400; }
.blk-org, .blk-client {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.blk-client { opacity: 0.9; font-weight: 400; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #fff7e8; }
.week-head td {
  background: #ebe4d6;
  font-weight: 600;
  color: var(--navy);
  user-select: none;
}
.week-head:hover td { background: #e3d9c8; }
.week-caret { display: inline-block; width: 1.2em; }
.week-count { color: var(--muted); font-weight: 500; margin-left: 8px; }
.data-table tbody tr.is-collapsed { display: none; }
.empty { text-align: center; color: var(--muted); cursor: default !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(27, 42, 74, 0.38);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 16px;
  z-index: 20;
}
.modal-card {
  width: min(520px, 100%);
  margin: auto;
  background: var(--card);
  border-radius: 12px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 14px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form input, .form select, .form textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.suggest { position: relative; }
.suggest-list {
  position: absolute;
  left: 0; right: 0; top: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-height: 220px;
  overflow: auto;
  z-index: 5;
  margin: 0;
  padding: 4px 0;
  list-style: none;
}
.suggest-list li { padding: 7px 10px; cursor: pointer; }
.suggest-list li:hover, .suggest-list li.is-on { background: #fff1d6; }
.suggest-list .sub { color: var(--muted); font-size: 12px; margin-left: 8px; }

.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 6px;
}
.cal b, .cal button {
  text-align: center;
  font-size: 12px;
  padding: 6px 0;
}
.cal b { color: var(--muted); font-weight: 500; }
.cal button {
  border: 1px solid transparent;
  background: #fff;
  border-radius: 4px;
}
.cal button:hover { border-color: var(--navy); }
.cal button.is-in { background: #eadcc8; color: var(--navy); border-radius: 0; }
.cal button.is-start {
  background: var(--navy);
  color: #fff;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}
.cal button.is-end {
  background: #c2410c;
  color: #fff;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}
.cal button.is-start.is-end {
  background: linear-gradient(90deg, var(--navy) 50%, #c2410c 50%);
  border-radius: 4px;
}
.cal button.is-other { color: var(--muted); }
.cal button.is-other.is-start,
.cal button.is-other.is-end { color: #fff; }
.cal button:disabled { opacity: 0.3; }
.field-block {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
.field-block .field-label { font-size: 12px; color: var(--muted); }
.cal-nav-btn { position: relative; z-index: 2; touch-action: manipulation; }
@media (max-width: 820px) {
  .cal-nav-btn {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    font-size: 22px;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}

.checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.checks label { display: flex; align-items: center; gap: 6px; color: var(--ink); }

.auth-form { display: grid; gap: 12px; }
.auth-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.login-card .auth-tab { flex: 1; background: #efe8da; color: var(--ink); padding: 9px 6px; font-size: 13px; }
.login-card .auth-tab.is-on { background: var(--navy); color: #fff; }
.auth-register { margin: 0; font-size: 13px; color: var(--muted); }
.login-card .auth-register button { background: transparent; color: var(--navy); padding: 4px; text-decoration: underline; }
.login-card input:not([type="checkbox"]) {
  border: 1px solid var(--line); background: #fff; padding: 10px 12px; border-radius: 6px; width: 100%; min-width: 0;
}
.login-card input[readonly] { background: #eee9df; color: var(--muted); }
.login-card label.check { display: flex; align-items: center; gap: 8px; }
.field-help { color: var(--muted); font-size: 12px; line-height: 1.65; margin: 0; }
.success { color: var(--ok); font-size: 13px; line-height: 1.6; margin: 0; }
.auth-form .error { margin: 0; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.current-user { align-self: center; font-size: 12px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { flex-wrap: wrap; }
.admin-topbar { grid-template-columns: 1fr auto; }
.admin-main { max-width: 1280px; margin: auto; }
.admin-main > .field-help { margin-bottom: 12px; }
.admin-table { min-width: 660px; }
.admin-table tbody tr { cursor: default; }
.admin-table .user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.user-actions button { font-size: 12px; padding: 5px 9px; }
.status-badge { display: inline-block; border-radius: 4px; padding: 3px 7px; font-size: 12px; background: #eee9df; color: var(--muted); }
.status-pending { background: #f8ead4; color: #8c551e; }
.status-active { background: #e0eee7; color: var(--ok); }
.app-notice { position: fixed; z-index: 50; bottom: 20px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); margin: 0; padding: 12px 18px; border-radius: 6px; box-shadow: var(--shadow); background: #1b2a4a; color: #fff; font-size: 13px; line-height: 1.6; }
button:disabled { opacity: 0.6; cursor: wait; }
input:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible { outline: 2px solid #b48642; outline-offset: 2px; }
.login-card .form-actions .ghost { background: #efe8da; color: var(--ink); }
@media (max-width: 820px) {
  .admin-topbar { grid-template-columns: 1fr; }
  .login-card { padding: 28px 22px 24px; }
  .login-wrap { padding: 16px; }
  .current-user { max-width: 160px; }
}

.profile-password-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.profile-section-title {
  margin: 0 0 12px;
  font-size: 16px;
  letter-spacing: 0.04em;
}
.admin-password-box {
  margin: 12px 0 20px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf8f4;
}
.admin-password-box summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--navy);
}
.admin-password-box .auth-form {
  margin-top: 12px;
  max-width: 420px;
}

.slot-stack {
  display: grid;
  gap: 2px;
  height: 100%;
  min-height: 100%;
  align-content: start;
  box-sizing: border-box;
}
.slot-stack .block { width: 100%; }
.blk-time { display: block; font-size: 11px; letter-spacing: 0.02em; margin-bottom: 2px; }
.conflict-list { display: grid; gap: 10px; margin: 12px 0; max-height: 50vh; overflow: auto; }
.conflict-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.conflict-option span { display: grid; gap: 2px; font-size: 13px; }
.conflict-option strong { color: var(--navy); }

.block.t-early {
  background: #b42318 !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.block.t-late {
  background: #c2410c !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.block.t-early .blk-org,
.block.t-early .blk-client,
.block.t-late .blk-org,
.block.t-late .blk-client { color: #fff; }

/* Conflict dual-delete confirmation — must stay visible on mobile */
.conflict-confirm {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 12px 0 8px;
  padding: 12px;
  border: 2px solid #b42318;
  border-radius: 8px;
  background: #fff5f4;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(180, 35, 24, 0.15);
  user-select: none;
}
.conflict-confirm input[type="checkbox"] {
  appearance: auto;
  -webkit-appearance: checkbox;
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  margin: 1px 0 0;
  flex: 0 0 auto;
  accent-color: #b42318;
  cursor: pointer;
}
.conflict-confirm-text {
  display: grid;
  gap: 4px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
}
.conflict-confirm-text strong {
  color: #b42318;
  font-weight: 700;
}
.conflict-confirm.is-on {
  background: #fde8e6;
  box-shadow: inset 0 0 0 1px #b42318;
}
@media (max-width: 820px) {
  .conflict-confirm {
    gap: 14px;
    padding: 14px 12px;
  }
  .conflict-confirm input[type="checkbox"] {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
  }
  .conflict-confirm-text { font-size: 14px; }
  .modal-card {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .conflict-list { max-height: 36vh; }
}
