:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #64748b;
  --border: #d9e1e8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --soft-blue: #eaf2ff;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #f97316;
  --warning-bg: #ffedd5;
  --soon: #ca8a04;
  --soon-bg: #fef9c3;
  --ok-bg: #e8f5ef;
  --shadow: 0 12px 32px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 18px;
}

.header-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  touch-action: manipulation;
}

.range-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 9px 10px;
  text-align: left;
}

.range-input.has-value {
  color: var(--primary-dark);
  font-weight: 600;
}

.date-range-popover {
  position: absolute;
  z-index: 20;
  width: 330px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  padding: 12px;
}

.date-range-header,
.date-range-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.date-range-weekdays,
.date-range-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-top: 10px;
}

.date-range-weekdays span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.date-day {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.date-day:hover {
  border-color: var(--primary);
}

.date-day.is-today {
  border-color: var(--warning);
  font-weight: 600;
}

.date-day.outside {
  color: #94a3b8;
}

.date-day.selected,
.date-day.range-edge {
  background: var(--primary);
  color: #fff;
}

.date-day.is-today.range-edge {
  border-color: var(--primary);
}

.date-day.in-range {
  background: var(--soft-blue);
  color: var(--primary-dark);
}

.date-range-footer {
  margin-top: 12px;
}

.date-range-actions {
  display: flex;
  gap: 8px;
}

.primary-button {
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  background: var(--panel);
  border-color: var(--border);
  color: var(--text);
  padding: 0 14px;
}

.secondary-button:hover {
  background: #f8fafc;
}

.icon-button {
  width: 36px;
  background: transparent;
  border-color: var(--border);
}

.import-button {
  display: inline-flex;
  align-items: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app-shell {
  padding: 24px 32px 40px;
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 16px;
}

.status-panel strong {
  display: block;
  font-size: 15px;
}

.count-pill.offline {
  background: var(--ok-bg);
  color: #047857;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dashboard-grid .panel,
.customer-section {
  padding: 18px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
}

.count-pill {
  min-width: 30px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--primary-dark);
  text-align: center;
  font-weight: 600;
}

.reminder-list {
  display: grid;
  gap: 10px;
}

.reminder-card {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-left-width: 5px;
  border-radius: 7px;
  padding: 10px;
  background: #fff;
  color: inherit;
  text-align: left;
}

.reminder-card.reminded {
  opacity: 0.72;
}

.todo-card {
  cursor: pointer;
}

.todo-card:hover {
  border-color: var(--primary);
}

.reminder-card.overdue,
tr.overdue {
  border-left-color: var(--danger);
  background: var(--danger-bg);
}

.reminder-card.today,
tr.today {
  border-left-color: var(--danger);
  background: var(--danger-bg);
}

.reminder-card.week,
tr.week {
  border-left-color: var(--soon);
  background: var(--soon-bg);
}

.reminder-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
}

.reminder-meta,
.muted,
.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.reminder-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.stage-stats {
  display: grid;
  gap: 10px;
}

.stage-row {
  display: grid;
  grid-template-columns: 80px 1fr 36px;
  gap: 10px;
  align-items: center;
}

.stage-bar {
  height: 10px;
  border-radius: 999px;
  background: #edf2f7;
  overflow: hidden;
}

.stage-bar span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.appointment-list {
  display: grid;
  gap: 14px;
}

.appointment-group {
  display: grid;
  gap: 8px;
}

.appointment-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

.appointment-items {
  display: grid;
  gap: 8px;
}

.appointment-card {
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: 7px;
  padding: 10px;
  background: #fff;
}

.appointment-card.today {
  border-left-color: var(--warning);
  background: var(--warning-bg);
}

.appointment-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
}

.appointment-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.appointment-actions button {
  min-height: 30px;
  padding: 0 10px;
}

.filters {
  display: grid;
  grid-template-columns: 1.3fr repeat(3, minmax(150px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.wide {
  grid-column: span 2;
}

label {
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  min-height: 38px;
  font-size: 16px;
}

textarea {
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: #475569;
  font-size: 13px;
  font-weight: 600;
  background: #f8fafc;
}

tbody tr {
  border-left: 5px solid transparent;
}

.customer-name {
  font-weight: 600;
}

.small-line {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.priority {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 30px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--ok-bg);
}

.priority.high {
  background: var(--danger-bg);
  color: var(--danger);
}

.priority.medium {
  background: var(--warning-bg);
  color: var(--warning);
}

.priority.soon {
  background: var(--soon-bg);
  color: var(--soon);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-actions button {
  min-height: 32px;
  padding: 0 10px;
}

.inline-button {
  margin-top: 8px;
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--primary-dark);
  cursor: pointer;
  padding: 0 10px;
}

.inline-button:hover {
  background: var(--soft-blue);
}

.empty-state {
  display: none;
  padding: 28px;
  text-align: center;
}

dialog {
  width: min(860px, calc(100vw - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

#historyDialog {
  width: min(1040px, calc(100vw - 24px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.38);
}

form {
  padding: 20px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

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

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.is-hidden {
  display: none;
}

.history-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.history-toolbar .field {
  min-width: 180px;
}

.history-editor {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.history-editor-actions {
  margin-top: 14px;
}

.history-list-wrap {
  padding: 0 20px 20px;
  overflow-x: auto;
}

.history-table {
  min-width: 840px;
}

@media (max-width: 1120px) {
  .dashboard-grid,
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stage-panel,
  .appointment-panel,
  .clear-filters {
    grid-column: span 2;
  }
}

@media (max-width: 720px) {
  body {
    background: #eef3f7;
  }

  .app-header,
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding-top: 16px;
    padding-bottom: 14px;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .dashboard-grid,
  .filters,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .stage-panel,
  .appointment-panel,
  .clear-filters,
  .field.wide {
    grid-column: auto;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .header-actions .primary-button,
  .header-actions .secondary-button {
    min-height: 44px;
    justify-content: center;
    text-align: center;
  }

  .header-actions .primary-button {
    grid-column: 1 / -1;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 16px;
  }

  .app-shell {
    padding-top: 12px;
    padding-bottom: 88px;
  }

  .dashboard-grid {
    gap: 12px;
    margin-bottom: 12px;
  }

  .status-panel {
    align-items: flex-start;
    margin-bottom: 12px;
    padding: 12px;
  }

  .dashboard-grid .panel,
  .customer-section,
  .filters {
    padding: 14px;
  }

  .panel-title-row {
    align-items: flex-start;
    margin-bottom: 12px;
  }

  .panel-actions {
    justify-content: flex-end;
  }

  .reminder-main,
  .appointment-main {
    display: grid;
    gap: 2px;
  }

  .reminder-main span:last-child,
  .appointment-main span:last-child {
    color: var(--muted);
    font-size: 13px;
  }

  .appointment-actions,
  .row-actions,
  .dialog-actions,
  .date-range-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .appointment-actions .primary-button,
  .appointment-actions .secondary-button,
  .row-actions .secondary-button,
  .dialog-actions .primary-button,
  .dialog-actions .secondary-button,
  .date-range-actions .primary-button,
  .date-range-actions .secondary-button {
    min-height: 44px;
    width: 100%;
  }

  .filters {
    gap: 10px;
  }

  label {
    font-size: 12px;
  }

  input,
  select,
  textarea,
  .range-input {
    min-height: 44px;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tbody tr {
    border: 1px solid var(--border);
    border-left-width: 5px;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid #edf2f7;
  }

  td::before {
    color: var(--muted);
    content: "";
    font-size: 12px;
    font-weight: 600;
  }

  td:nth-child(1)::before {
    content: "优先级";
  }

  td:nth-child(2)::before {
    content: "客户";
  }

  td:nth-child(3)::before {
    content: "等级";
  }

  td:nth-child(4)::before {
    content: "洗澡";
  }

  td:nth-child(5)::before {
    content: "驱虫";
  }

  td:nth-child(6)::before {
    content: "最近联系";
  }

  td:nth-child(7)::before {
    content: "操作";
  }

  td:last-child {
    border-bottom: 0;
  }

  .customer-name {
    font-size: 17px;
  }

  .small-line {
    line-height: 1.45;
    word-break: break-word;
  }

  .inline-button {
    width: 100%;
    min-height: 40px;
  }

  dialog {
    width: 100vw;
    max-width: 100vw;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  form {
    padding: 16px 14px;
  }

  .dialog-header {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: -16px -14px 14px;
    padding: 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }

  .dialog-actions {
    position: static;
    margin: 0;
    padding-top: 12px;
    background: var(--panel);
    border-top: 1px solid var(--border);
  }

  #historyDialog form {
    padding-bottom: 16px;
  }

  .history-toolbar {
    display: grid;
    gap: 10px;
  }

  .history-toolbar .field {
    min-width: 0;
  }

  .history-editor {
    padding: 12px;
  }

  .history-list-wrap {
    padding: 0 14px 16px;
    overflow: visible;
  }

  .history-table {
    min-width: 0;
  }

  .history-table tbody tr {
    border-left-width: 1px;
  }

  .history-table td:nth-child(1)::before {
    content: "项目";
  }

  .history-table td:nth-child(2)::before {
    content: "日期";
  }

  .history-table td:nth-child(3)::before {
    content: "下次提醒";
  }

  .history-table td:nth-child(4)::before {
    content: "产品/金额";
  }

  .history-table td:nth-child(5)::before {
    content: "备注";
  }

  .history-table td:nth-child(6)::before {
    content: "操作";
  }

  .date-range-popover {
    position: fixed;
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: 12px;
    width: auto;
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }

  .date-day {
    min-height: 42px;
  }
}
