:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.975 0.006 260);
  --surface-strong: oklch(0.94 0.012 260);
  --ink: oklch(0.24 0.025 260);
  --muted: oklch(0.46 0.025 260);
  --primary: oklch(0.42 0.14 260);
  --primary-hover: oklch(0.36 0.14 260);
  --danger: oklch(0.52 0.18 25);
  --warning: oklch(0.72 0.14 75);
  --success: oklch(0.5 0.13 150);
  --border: oklch(0.87 0.012 260);
  --focus: oklch(0.7 0.14 260);
  --font: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { width: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-width: 0; margin: 0; color: var(--ink); background: var(--bg); font-family: var(--font); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.category-option, .callback-choice, .privacy-row, button { touch-action: manipulation; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: white; background: var(--primary); font-weight: 700; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }

.patient-body { min-height: 100vh; overflow-x: hidden; background: oklch(0.965 0.008 260); font-size: 16px; line-height: 1.55; }
.patient-header { padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left)); background: var(--bg); border-bottom: 1px solid var(--border); }
.patient-header-inner { display: flex; width: min(100%, 640px); margin: 0 auto; align-items: center; justify-content: space-between; gap: 12px; }
.patient-header .brand { min-width: 0; min-height: 44px; }
.patient-header .brand-mark { width: 34px; height: 34px; border-radius: 9px; }
.patient-header .brand strong { font-size: 15px; line-height: 1.2; }
.patient-header .brand small { font-size: 11px; }
.demo-mode-tag { flex: 0 0 auto; padding: 5px 9px; border-radius: 999px; color: var(--primary); background: oklch(0.95 0.028 260); font-size: 12px; font-weight: 600; }
.patient-shell { width: min(100%, 640px); margin: 0 auto; padding: 20px max(14px, env(safe-area-inset-right)) 32px max(14px, env(safe-area-inset-left)); }
.patient-intro { margin: 2px 2px 18px; }
.patient-intro h1 { margin: 0; font-size: 26px; line-height: 1.3; letter-spacing: -0.02em; text-wrap: balance; }
.patient-intro p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.patient-intro.is-error { padding: 14px; border-radius: 12px; background: oklch(0.96 0.025 25); }
.patient-intro.is-error h1 { color: var(--danger); }
.urgent-note { display: flex; gap: 9px; align-items: flex-start; margin: 10px 2px 16px; color: oklch(0.36 0.055 65); }
.urgent-note > span { display: grid; flex: 0 0 auto; width: 20px; height: 20px; margin-top: 1px; place-items: center; border-radius: 50%; color: white; background: oklch(0.58 0.15 60); font-size: 12px; font-weight: 700; }
.urgent-note p { margin: 0; font-size: 14px; line-height: 1.5; }
.feedback-form, .success-panel { padding: 20px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.feedback-form fieldset { min-width: 0; margin: 0; padding: 0 0 22px; border: 0; }
.feedback-form .field-block { margin: 0; padding: 22px 0; border-top: 1px solid var(--border); }
.feedback-form fieldset + fieldset { padding-top: 22px; border-top: 1px solid var(--border); }
.feedback-form legend, .field-block > label { display: flex; width: 100%; margin-bottom: 12px; align-items: center; gap: 9px; color: var(--ink); font-size: 17px; font-weight: 650; }
.step-index { display: grid; flex: 0 0 auto; width: 26px; height: 26px; place-items: center; border-radius: 50%; color: white; background: var(--primary); font-size: 13px; font-style: normal; font-weight: 700; }
.field-block > label em { margin-left: 4px; color: var(--danger); font-size: 12px; font-style: normal; font-weight: 600; }
.feedback-form legend .optional { color: var(--muted); font-size: 13px; font-style: normal; font-weight: 500; }
.callback-heading { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 12px; }
.callback-heading .step-index { margin-top: 1px; }
.callback-title { margin: 0; color: var(--ink); font-size: 17px; font-weight: 650; line-height: 1.45; }
.callback-title em { margin-left: 4px; color: var(--muted); font-size: 12px; font-style: normal; font-weight: 500; }
.callback-help { margin: 3px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.callback-choice { display: flex; min-height: 48px; gap: 11px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); background: var(--surface); cursor: pointer; transition: border-color 180ms ease-out, background 180ms ease-out; }
.callback-choice:hover { border-color: oklch(0.62 0.08 260); background: oklch(0.97 0.014 260); }
.callback-choice input { flex: 0 0 auto; width: 22px; height: 22px; margin: 0; accent-color: var(--primary); }
.callback-choice span { font-size: 15px; font-weight: 600; }
.phone-wrap { margin-top: 12px; padding: 14px; border: 1px solid oklch(0.82 0.04 260); border-radius: 10px; background: oklch(0.975 0.012 260); }
.phone-wrap:not([hidden]) { animation: phone-wrap-in 180ms ease-out; }
.phone-wrap > label { display: block; margin-bottom: 6px; color: var(--ink); font-size: 15px; font-weight: 600; }
.phone-help { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
@keyframes phone-wrap-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.category-option { position: relative; }
.category-option input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.category-option-surface { display: grid; min-height: 78px; grid-template-columns: 36px minmax(0, 1fr) 20px; gap: 9px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); background: var(--bg); cursor: pointer; transition: border-color 180ms ease-out, background 180ms ease-out; }
.category-symbol { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 9px; color: var(--primary); background: oklch(0.95 0.028 260); font-size: 15px; font-weight: 700; transition: color 180ms ease-out, background 180ms ease-out; }
.category-copy { min-width: 0; text-align: left; }
.category-copy strong, .category-copy small { display: block; }
.category-copy strong { font-size: 15px; line-height: 1.35; }
.category-copy small { margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.35; text-wrap: pretty; }
.category-check { display: grid; width: 20px; height: 20px; place-items: center; border: 1px solid var(--border); border-radius: 50%; color: transparent; background: var(--bg); font-size: 12px; font-weight: 700; transition: border-color 180ms ease-out, background 180ms ease-out, color 180ms ease-out; }
.category-option:hover .category-option-surface { border-color: oklch(0.62 0.08 260); }
.category-option input:checked + .category-option-surface { border-color: var(--primary); background: oklch(0.965 0.022 260); }
.category-option input:checked + .category-option-surface .category-symbol { color: white; background: var(--primary); }
.category-option input:checked + .category-option-surface .category-copy strong { color: var(--primary); }
.category-option input:checked + .category-option-surface .category-check { border-color: var(--primary); color: white; background: var(--primary); }
.category-option input:focus-visible + .category-option-surface { outline: 3px solid var(--focus); outline-offset: 2px; }
.category-option input:disabled + .category-option-surface { cursor: not-allowed; opacity: .55; }
.category-grid[aria-invalid="true"] .category-option-surface { border-color: var(--danger); }
textarea, input[type="tel"] { width: 100%; border: 1px solid var(--border); border-radius: 10px; color: var(--ink); background: var(--bg); font-size: 16px; }
textarea { min-height: 116px; padding: 12px 13px; line-height: 1.6; resize: vertical; }
input[type="tel"] { min-height: 48px; padding: 10px 13px; }
textarea::placeholder, input::placeholder { color: oklch(0.45 0.02 260); }
textarea:hover, input[type="tel"]:hover { border-color: oklch(0.65 0.04 260); }
textarea[aria-invalid="true"], input[type="tel"][aria-invalid="true"] { border-color: var(--danger); }
.field-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; color: var(--muted); font-size: 13px; }
.field-meta p { margin: 0; }
.privacy-block { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.privacy-row { display: flex; gap: 11px; align-items: flex-start; cursor: pointer; }
.privacy-row input { flex: 0 0 auto; width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--primary); }
.privacy-row { min-height: 48px; margin-top: 2px; padding: 8px 0; color: oklch(0.38 0.025 260); font-size: 14px; line-height: 1.5; }
.field-error { min-height: 0; margin: 6px 0 0; color: var(--danger); font-size: 14px; line-height: 1.45; }
.submit-error:not(:empty) { margin-bottom: 10px; text-align: center; }
.primary-button, .secondary-button, .primary-link { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px; border-radius: 9px; font-weight: 600; text-decoration: none; cursor: pointer; }
.primary-button, .primary-link { border: 1px solid var(--primary); color: white; background: var(--primary); }
.primary-button:hover, .primary-link:hover { background: var(--primary-hover); }
.primary-button:disabled { cursor: wait; opacity: .65; }
.submit-area { margin-top: 10px; }
.submit-area .primary-button { width: 100%; min-height: 52px; font-size: 17px; }
.secondary-button { border: 1px solid var(--border); color: var(--ink); background: var(--bg); }
.secondary-button:hover { background: var(--surface); }
.submit-hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.success-panel { padding-block: 30px; text-align: center; }
.success-icon { display: grid; width: 56px; height: 56px; margin: 0 auto 14px; place-items: center; border-radius: 50%; color: white; background: var(--success); font-size: 28px; }
.success-panel h2 { margin: 0; font-size: 24px; }
.success-panel > p { color: var(--muted); }
.success-panel dl { margin: 22px 0; text-align: left; }
.success-panel dl div { display: flex; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.success-panel dt { color: var(--muted); }
.success-panel dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-weight: 600; text-align: right; }
.patient-footer { padding: 0 max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); color: var(--muted); font-size: 12px; text-align: center; }

.admin-body { min-height: 100vh; background: var(--surface); font-size: 14px; line-height: 1.5; }
.admin-shell { display: flex; min-height: 100vh; }
.sidebar { position: sticky; top: 0; display: flex; flex: 0 0 224px; flex-direction: column; height: 100vh; padding: 22px 16px; border-right: 1px solid var(--border); background: var(--bg); }
.admin-brand { margin: 0 8px 28px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-link { display: flex; gap: 10px; align-items: center; min-height: 42px; padding: 9px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; }
.nav-link:hover, .nav-link.active { color: var(--primary); background: oklch(0.96 0.025 260); }
.demo-badge { margin-top: auto; padding: 12px; border-radius: 10px; background: var(--surface); }
.demo-badge strong, .demo-badge span { display: block; }
.demo-badge strong { font-size: 13px; }
.demo-badge span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.admin-main { min-width: 0; flex: 1; padding: 28px clamp(18px, 3vw, 42px) 48px; }
.admin-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; }
.admin-header p { margin: 0 0 3px; color: var(--muted); }
.admin-header h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.header-actions { display: flex; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 24px 0; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.stats div { padding: 16px 18px; }
.stats div + div { border-left: 1px solid var(--border); }
.stats span, .stats strong { display: block; }
.stats span { color: var(--muted); font-size: 12px; }
.stats strong { margin-top: 4px; font-size: 25px; }
.workbench { border: 1px solid var(--border); border-radius: 12px; background: var(--bg); overflow: hidden; }
.workbench-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.workbench-header h2 { margin: 0; font-size: 17px; }
.workbench-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 5px; }
.filter { min-height: 34px; padding: 6px 10px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; }
.filter:hover, .filter.active { color: var(--primary); background: oklch(0.96 0.025 260); }
.workbench-grid { display: grid; grid-template-columns: minmax(520px, 1.45fr) minmax(320px, 1fr); min-height: 480px; }
.ticket-list-wrap { min-width: 0; overflow-x: auto; }
.ticket-table { width: 100%; border-collapse: collapse; }
.ticket-table th { padding: 11px 13px; color: var(--muted); background: var(--surface); font-size: 12px; font-weight: 600; text-align: left; }
.ticket-table td { padding: 13px; border-top: 1px solid var(--border); font-size: 13px; }
.ticket-table tbody tr { cursor: pointer; }
.ticket-table tbody tr:hover, .ticket-table tbody tr.selected { background: oklch(0.975 0.015 260); }
.ticket-no { font-weight: 600; white-space: nowrap; }
.priority { display: inline-grid; min-width: 26px; height: 24px; place-items: center; border-radius: 6px; color: oklch(0.3 0.07 65); background: oklch(0.93 0.08 75); font-weight: 700; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status-badge[data-status="new"]::before { background: var(--danger); }
.status-badge[data-status="accepted"]::before { background: var(--warning); }
.status-badge[data-status="handling"]::before { background: var(--primary); }
.status-badge[data-status="resolved"]::before { background: var(--success); }
.ticket-detail { min-width: 0; padding: 20px; border-left: 1px solid var(--border); background: var(--surface); }
.detail-placeholder { display: grid; min-height: 360px; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.detail-placeholder span { font-size: 32px; }
.detail-placeholder strong { margin-top: 8px; color: var(--ink); }
.detail-placeholder p { max-width: 260px; }
.detail-top { display: flex; justify-content: space-between; gap: 15px; }
.detail-top h3 { margin: 2px 0 0; font-size: 19px; }
.detail-section { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--border); }
.detail-section h4 { margin: 0 0 8px; font-size: 13px; }
.detail-section p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detail-meta div { padding: 10px; border-radius: 8px; background: var(--bg); }
.detail-meta span, .detail-meta strong { display: block; }
.detail-meta span { color: var(--muted); font-size: 11px; }
.detail-meta strong { margin-top: 3px; font-size: 13px; }
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 16px 20px; }
.timeline li::before { content: ""; position: absolute; top: 6px; left: 2px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; top: 17px; bottom: 2px; left: 5px; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline strong, .timeline span { display: block; }
.timeline span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.timeline p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.action-panel textarea { min-height: 82px; background: var(--bg); }
.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.action-buttons button { min-height: 40px; }
.empty-state { padding: 80px 20px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); }
.pilot-note { margin-top: 22px; padding: 18px 20px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.pilot-note h2 { margin: 0 0 4px; font-size: 16px; }
.pilot-note p { margin: 0; color: var(--muted); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 360px; padding: 12px 15px; border-radius: 9px; color: white; background: var(--ink); }

.login-body { display: grid; min-height: 100vh; place-items: center; padding: 24px 16px; background: var(--surface); }
.login-shell { width: min(100%, 420px); }
.login-card { padding: 30px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg); box-shadow: 0 16px 42px oklch(0.25 0.03 260 / 8%); }
.login-brand { margin-bottom: 30px; }
.login-heading h1 { margin: 0; font-size: 25px; letter-spacing: -0.02em; }
.login-heading p:last-child { margin: 7px 0 0; color: var(--muted); }
.eyebrow { margin: 0 0 5px; color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.login-form { display: grid; gap: 8px; margin-top: 25px; }
.login-form label { color: var(--ink); font-size: 13px; font-weight: 650; }
.login-form input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; color: var(--ink); background: var(--bg); }
.login-form input:focus { border-color: var(--focus); outline: 3px solid oklch(0.7 0.14 260 / 22%); outline-offset: 0; }
.login-form .field-error { min-height: 21px; margin: 2px 0 0; }
.login-form .primary-button { width: 100%; margin-top: 4px; }
.login-note { margin: 22px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 1040px) {
  .workbench-grid { grid-template-columns: 1fr; }
  .ticket-detail { border-top: 1px solid var(--border); border-left: 0; }
}
@media (max-width: 760px) {
  .admin-shell { display: block; }
  .sidebar { position: static; width: auto; height: auto; padding: 14px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .admin-brand { margin: 0 0 12px; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .demo-badge { display: none; }
  .admin-main { padding: 20px 14px 36px; }
  .admin-header { align-items: flex-start; flex-direction: column; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats div + div { border-left: 0; }
  .stats div:nth-child(even) { border-left: 1px solid var(--border); }
  .stats div:nth-child(n+3) { border-top: 1px solid var(--border); }
  .workbench-header { align-items: flex-start; flex-direction: column; }
  .workbench-grid { display: block; }
  .ticket-table { min-width: 620px; }
}
@media (max-width: 440px) {
  .header-actions { width: 100%; }
  .header-actions > * { flex: 1; }
}
@media (max-width: 440px) {
  .login-card { padding: 24px 20px; }
}
@media (max-width: 599px) {
  .patient-header { padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
  .patient-header-inner { gap: 8px; }
  .patient-header .brand-mark { width: 32px; height: 32px; }
  .demo-mode-tag { padding: 4px 8px; }
  .patient-shell { padding: 16px max(12px, env(safe-area-inset-right)) 28px max(12px, env(safe-area-inset-left)); }
  .patient-intro { margin: 0 2px 14px; }
  .patient-intro h1 { font-size: 24px; }
  .urgent-note { margin: 8px 2px 14px; }
  .feedback-form, .success-panel { padding: 18px 14px; }
  .feedback-form fieldset { padding-bottom: 18px; }
  .feedback-form .field-block { padding: 18px 0; }
  .feedback-form legend, .field-block > label { margin-bottom: 10px; font-size: 16px; }
  .callback-title { font-size: 16px; }
  .callback-help { font-size: 13px; }
  .category-grid { gap: 8px; }
  .category-option-surface { min-height: 64px; grid-template-columns: 34px minmax(0, 1fr); gap: 8px; padding: 9px; }
  .category-symbol { width: 34px; height: 34px; }
  .category-copy strong { white-space: nowrap; }
  .category-copy small, .category-check { display: none; }
  .phone-wrap { padding: 12px; }
  .privacy-block { margin-top: 16px; padding-top: 16px; }
}
@media (max-width: 359px) {
  .patient-shell { padding-right: max(8px, env(safe-area-inset-right)); padding-left: max(8px, env(safe-area-inset-left)); }
  .feedback-form, .success-panel { padding-inline: 12px; }
  .category-grid { gap: 8px; }
  .category-option-surface { min-height: 64px; grid-template-columns: 32px minmax(0, 1fr); gap: 7px; padding: 8px; }
  .category-symbol { width: 32px; height: 32px; }
  .category-copy strong { font-size: 14px; }
}
@media (min-width: 600px) {
  .patient-shell { padding-top: 24px; padding-bottom: 48px; }
  .patient-intro { margin-bottom: 20px; }
  .feedback-form, .success-panel { padding: 28px; }
  .category-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (pointer: coarse) {
  .primary-button, .secondary-button, .category-option-surface { min-height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
  .phone-wrap:not([hidden]) { animation: none; }
}
