:root {
  --bg: #f6f7fb; --panel: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb; --soft: #f3f4f6;
  --brand: #4f46e5; --brand-soft: #eef2ff; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --st-confirmed: #2563eb; --st-in_progress: #9333ea; --st-completed: #16a34a; --st-cancelled: #9ca3af; --st-no_show: #dc2626;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stack > * + * { margin-top: 12px; }

/* layout */
.app { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }
.app.chat-open { grid-template-columns: 210px 1fr 400px; }
.side { background: #111827; color: #d1d5db; display: flex; flex-direction: column; padding: 16px 10px; }
.logo { color: #fff; font-weight: 700; font-size: 18px; padding: 4px 10px 16px; }
.logo small { display: block; font-weight: 400; font-size: 11px; color: #9ca3af; }
.nav a { display: flex; gap: 10px; align-items: center; color: #d1d5db; padding: 8px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: #1f2937; }
.nav a.active { background: var(--brand); color: #fff; }
.side .foot { margin-top: auto; font-size: 12px; color: #9ca3af; padding: 8px 10px; }
.main { overflow: auto; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.content { padding: 20px; }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 6px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--soft); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: #fecaca; }
button.ok { color: var(--ok); border-color: #bbf7d0; }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: #fff; color: var(--text); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { font-size: 14px; color: var(--text); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.red { background: #fee2e2; color: var(--danger); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.st { color: #fff; }
.st-confirmed { background: var(--st-confirmed); } .st-in_progress { background: var(--st-in_progress); }
.st-completed { background: var(--st-completed); } .st-cancelled { background: var(--st-cancelled); } .st-no_show { background: var(--st-no_show); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 500; background: #fafafa; position: sticky; top: 0; }
tr.click:hover td { background: #fafaff; cursor: pointer; }
.error { color: var(--danger); background: #fef2f2; border: 1px solid #fecaca; padding: 8px 12px; border-radius: 8px; }
.notice { color: #92400e; background: #fffbeb; border: 1px solid #fde68a; padding: 8px 12px; border-radius: 8px; }
.success { color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0; padding: 8px 12px; border-radius: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip:hover, .chip.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--soft); object-fit: cover; flex: none; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 22px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); }

/* modal / drawer */
.overlay { position: fixed; inset: 0; background: rgba(17,24,39,.4); z-index: 40; display: flex; align-items: flex-start; justify-content: center; padding-top: 6vh; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 94vw); max-height: 88vh; overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(900px, 96vw); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 96vw); background: #fff; z-index: 45; box-shadow: -10px 0 30px rgba(0,0,0,.15); padding: 20px; overflow: auto; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.timeline { border-left: 2px solid var(--line); padding-left: 12px; margin-left: 4px; }
.timeline div { margin-bottom: 8px; font-size: 12px; }

/* calendar: day gantt */
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; gap: 4px; align-items: center; }
.gantt { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.gantt-inner { min-width: 900px; }
.g-head, .g-row { display: grid; grid-template-columns: 140px 1fr; }
.g-head { border-bottom: 1px solid var(--line); background: #fafafa; position: sticky; top: 0; }
.g-hours { position: relative; height: 28px; }
.g-hours span { position: absolute; top: 6px; font-size: 11px; color: var(--muted); transform: translateX(-50%); }
.g-name { padding: 10px 12px; display: flex; gap: 8px; align-items: center; border-right: 1px solid var(--line); font-weight: 500; }
.g-row { border-bottom: 1px solid var(--line); min-height: 64px; }
.g-track { position: relative; cursor: copy; background-image: linear-gradient(to right, var(--line) 1px, transparent 1px); }
.g-off { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 6px, #e9eaee 6px, #e9eaee 12px); pointer-events: none; }
.g-appt { position: absolute; top: 6px; bottom: 6px; border-radius: 6px; padding: 3px 6px; font-size: 11px; color: #fff; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.15); line-height: 1.3; }
.g-appt.st-cancelled { text-decoration: line-through; opacity: .55; top: 40px; bottom: 4px; }
.g-appt:hover { filter: brightness(1.1); z-index: 2; }
.g-now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); z-index: 3; pointer-events: none; }
/* week & month */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.wcol { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); min-height: 400px; display: flex; flex-direction: column; }
.wcol.today .whead { background: var(--brand-soft); color: var(--brand); }
.whead { padding: 8px; font-weight: 600; border-bottom: 1px solid var(--line); text-align: center; cursor: pointer; }
.wbody { padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.mini { border-radius: 6px; padding: 3px 6px; font-size: 11px; color: #fff; cursor: pointer; line-height: 1.35; }
.mini.st-cancelled { text-decoration: line-through; opacity: .6; }
.month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.mcell { background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 104px; padding: 6px; cursor: pointer; }
.mcell.other { opacity: .45; } .mcell.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.mcell .n { font-weight: 600; font-size: 12px; }
.mhead { text-align: center; font-size: 12px; color: var(--muted); }

/* schedule editor */
.sched td, .sched th { padding: 6px; }
.slot-pill { display: inline-flex; gap: 4px; align-items: center; background: var(--brand-soft); color: var(--brand); border-radius: 6px; padding: 2px 4px 2px 8px; margin: 2px; font-size: 12px; }
.slot-pill button { padding: 0 6px; border: 0; background: transparent; color: var(--brand); }

/* chat */
.chat { border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.chat-log { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #fafafa; }
.msg { max-width: 88%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ccard { align-self: stretch; border: 1px solid #c7d2fe; background: #f5f7ff; border-radius: 12px; padding: 10px 12px; }
.ccard.confirmed { border-color: #bbf7d0; background: #f0fdf4; }
.ccard.rejected, .ccard.failed { opacity: .65; }
.ccard .t { font-weight: 600; font-size: 12px; color: var(--brand); margin-bottom: 4px; }
.chat-input { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; }
.chat-input textarea { flex: 1; resize: none; height: 42px; }
.examples { padding: 0 10px 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.typing { color: var(--muted); font-size: 12px; align-self: flex-start; }

@media (max-width: 1100px) { .app.chat-open { grid-template-columns: 0 1fr 380px; } .app.chat-open .side { display: none; } }
@media (max-width: 760px) {
  .app, .app.chat-open { grid-template-columns: 1fr; }
  .side { display: none; } .chat { position: fixed; inset: 0; z-index: 50; }
  .grid2, .grid3 { grid-template-columns: 1fr; } .week { grid-template-columns: 1fr; }
}
