:root {
  --bg: #f3f6fb;
  --card: #fff;
  --text: #1a2332;
  --muted: #6b7785;
  --brand: #1565c0;
  --brand-light: #e3f2fd;
  --ok: #2e7d32;
  --warn: #ef6c00;
  --danger: #c62828;
  --line: #e2e8f0;
  --shadow: 0 2px 10px rgba(21, 101, 192, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input { font: inherit; }
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 10px;
  background: linear-gradient(135deg, #1565c0, #0d47a1);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }
.topbar .sub { margin: 4px 0 0; font-size: 12px; opacity: .88; }
.icon-btn {
  border: 0; background: rgba(255,255,255,.18); color: #fff;
  width: 36px; height: 36px; border-radius: 10px; font-size: 14px;
}

.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 10px 12px 0;
}
.tab {
  border: 0; background: var(--card); color: var(--muted);
  padding: 10px 6px; border-radius: 12px 12px 0 0;
  font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow);
}
.tab.active { background: var(--brand); color: #fff; }
.tab span {
  display: inline-block; margin-left: 4px; min-width: 18px;
  padding: 0 6px; border-radius: 999px; background: rgba(0,0,0,.12); font-size: 12px;
}
.tab.active span { background: rgba(255,255,255,.22); }

.filter-panel {
  margin: 10px 12px 0; padding: 0; background: var(--card);
  border-radius: 14px; box-shadow: var(--shadow);
  border: 2px solid rgba(21,101,192,.15); overflow: hidden;
}
.filter-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: linear-gradient(90deg, #e3f2fd, #fff);
  border-bottom: 1px solid var(--line);
}
.filter-head strong { display: block; font-size: 14px; color: var(--brand); }
.filter-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.icon-btn.light { background: #fff; color: var(--brand); border: 1px solid var(--line); }
.filter-body { padding: 12px; }
.filter-panel.collapsed .filter-body { display: none; }
.filter-panel.collapsed .filter-head .icon-btn.light::after { content: ''; }
.active-filters {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line);
  display: flex; flex-wrap: wrap; gap: 6px;
}
.active-filters .af {
  font-size: 11px; padding: 4px 8px; border-radius: 999px;
  background: var(--brand-light); color: var(--brand); font-weight: 600;
}
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filter-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field-name { color: var(--brand); font-weight: 700; font-size: 12px; }
.filter-grid input {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fafbfd;
}
.filter-actions {
  display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap;
}
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin-right: auto; }

.toolbar {
  display: flex; gap: 8px; padding: 10px 12px;
}
.search {
  flex: 1; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: var(--card);
}
.btn {
  border: 0; background: var(--brand); color: #fff;
  padding: 10px 14px; border-radius: 10px; font-weight: 600;
}
.btn.ghost { background: #eef2f7; color: var(--text); }
.btn.sm { padding: 10px 12px; font-size: 13px; white-space: nowrap; }
.btn.block { width: 100%; padding: 14px; font-size: 15px; }
.btn.danger-text { color: var(--danger); margin-bottom: 8px; }
.btn.danger-text.danger, .btn.ghost.danger { background: #ffebee; color: var(--danger); font-weight: 700; }

.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0 0 8px; }
.slot-day-group { margin-bottom: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(70px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0;
  background: rgba(21,101,192,.95); color: #fff; padding: 10px 16px;
  border-radius: 999px; font-size: 13px; z-index: 100; pointer-events: none;
  transition: .2s ease; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: rgba(198,40,40,.95); }

.order-list { padding: 0 12px 80px; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card); border-radius: 14px; padding: 12px 14px;
  box-shadow: var(--shadow); border: 1px solid rgba(21,101,192,.06);
}
.card:active { transform: scale(.995); }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.card-title { font-size: 15px; font-weight: 700; line-height: 1.35; margin: 0; }
.card-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center;
}
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--text); font-weight: 600; white-space: nowrap;
}
.chip.branch { background: var(--brand-light); color: var(--brand); }
.chip.ok { background: #e8f5e9; color: var(--ok); }
.chip.muted { background: #f5f5f5; color: var(--muted); }
.card-summary {
  margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.5;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.g-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; margin-left: 2px;
}
.g-badge.silver { background: #eceff1; color: #546e7a; }
.g-badge.gold { background: #fff8e1; color: #f57f17; }
.g-badge.platinum { background: #ede7f6; color: #5e35b1; }
.g-badge.diamond { background: #e0f7fa; color: #006064; }
.g-badge.vip { background: #fce4ec; color: #ad1457; }
.badge {
  flex-shrink: 0; font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--brand-light); color: var(--brand); font-weight: 600;
}
.badge.ok { background: #e8f5e9; color: var(--ok); }
.badge.warn { background: #fff3e0; color: var(--warn); }
.badge.bad { background: #ffebee; color: var(--danger); }
.card-meta { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.card-meta b { color: var(--text); font-weight: 600; }
.card-foot {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line);
  display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted);
}
.phone-link { color: var(--brand); text-decoration: none; font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30;
}
.drawer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 92vh; background: var(--card);
  border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column;
  padding-bottom: calc(12px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.15);
}
.drawer-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 16px; flex: 1; }
.drawer-body { overflow: auto; padding: 10px 12px 12px; flex: 1; background: var(--bg); }
.drawer-foot { padding: 10px 14px 0; border-top: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; }

.detail-block {
  background: var(--card); border-radius: 14px; padding: 10px 12px;
  margin-bottom: 10px; box-shadow: var(--shadow);
  border: 1px solid rgba(21,101,192,.06);
}
.detail-block.appt-block { padding-bottom: 12px; }
.detail-block-title {
  font-size: 13px; font-weight: 700; color: var(--brand);
  margin-bottom: 8px; padding-bottom: 6px; border-bottom: 2px solid var(--brand-light);
}
.detail-block-title.sub { margin-top: 10px; font-size: 12px; color: var(--text); border-bottom: 0; padding-bottom: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.detail-kv { min-width: 0; }
.detail-kv .dk { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.detail-kv .dv { display: block; font-size: 13px; line-height: 1.4; word-break: break-all; }
.detail-kv .dv a { color: var(--brand); text-decoration: none; font-weight: 700; }
.detail-grid .detail-kv:first-child,
.detail-grid .detail-kv:nth-child(2) { grid-column: span 1; }
@media (max-width: 360px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.kv { margin-bottom: 12px; }
.kv .k { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kv .v { font-size: 14px; line-height: 1.5; word-break: break-all; }
.kv .v a { color: var(--brand); text-decoration: none; font-weight: 700; }

.section-title {
  font-size: 13px; font-weight: 700; color: var(--brand);
  margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--brand-light);
}

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: #eef2f7; color: var(--text); font-weight: 600;
}
.tag.branch { background: var(--brand-light); color: var(--brand); }
.tag.appt-yes { background: #e8f5e9; color: var(--ok); }
.tag.appt-no { background: #fafafa; color: var(--muted); }

.slot-picker { margin-top: 8px; }
.slot-date-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.slot-date-row input[type=date] {
  flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fafbfd;
}
.selected-slots { margin-top: 12px; }
.selected-slot-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; margin-bottom: 6px; background: var(--brand-light);
  border-radius: 10px; font-size: 13px;
}
.selected-slot-item button {
  border: 0; background: #fff; color: var(--danger); border-radius: 8px; padding: 4px 8px; font-size: 12px;
}

.note-history { margin-top: 10px; }
.note-item {
  padding: 8px 10px; margin-bottom: 6px; background: #fafbfd;
  border-left: 3px solid var(--brand); border-radius: 0 8px 8px 0; font-size: 13px;
  display: flex; gap: 8px; align-items: flex-start; justify-content: space-between;
}
.note-item .note-body { flex: 1; min-width: 0; }
.note-item time { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.note-item button {
  border: 0; background: #ffebee; color: var(--danger); border-radius: 8px;
  padding: 4px 8px; font-size: 11px; flex-shrink: 0;
}

.slot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot-day { grid-column: 1 / -1; font-size: 13px; font-weight: 700; margin-top: 8px; color: var(--text); }
.slot-btn {
  border: 1px solid var(--line); background: #fafbfd; border-radius: 10px;
  padding: 10px 8px; font-size: 12px; text-align: center;
}
.slot-btn.selected { background: var(--brand-light); border-color: var(--brand); color: var(--brand); font-weight: 700; }

.note-box {
  width: 100%; min-height: 70px; margin-top: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical;
}

@media (min-width: 720px) {
  body { max-width: 520px; margin: 0 auto; }
}
