:root {
  color-scheme: light;
  --ink: #0f172a;
  --muted: #526176;
  --green-950: #0f172a;
  --green-800: #166534;
  --green-650: #15803d;
  --green-100: #dcfce7;
  --green-50: #ecfdf3;
  --red: #c8102e;
  --red-soft: #fff1f3;
  --amber: #8a4b08;
  --amber-soft: #fff2cc;
  --line: #dce3ec;
  --surface: #ffffff;
  --canvas: #f3f6fa;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.09);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei",
    "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 100% 0, rgba(200, 16, 46, 0.08), transparent 28rem), var(--canvas);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, input, select, textarea, label { touch-action: manipulation; }
button { cursor: pointer; transition: border-color 180ms ease, background-color 180ms ease, color 180ms ease, opacity 180ms ease, box-shadow 180ms ease; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .weekday-chip input:focus-visible + span {
  outline: 3px solid rgba(200, 16, 46, .28);
  outline-offset: 2px;
}
button:active:not(:disabled) { opacity: .78; }

.app-shell { min-height: 100vh; }

.brand-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 12px max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  border-bottom: 1px solid rgba(220, 227, 236, .92);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.brand-bar img { border-radius: 12px; background: white; box-shadow: 0 3px 12px rgba(15,23,42,.1); }
.brand-bar h1 { margin: 1px 0 0; font-size: 1.15rem; }
.brand-bar .eyebrow { color: var(--red); }

.eyebrow {
  margin: 0;
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.connection-badge {
  padding: 5px 9px;
  border: 1px solid #b8c4d3;
  border-radius: 999px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 0.73rem;
  font-weight: 750;
}

.connection-badge.error { color: var(--red); border-color: #efb4bf; background: var(--red-soft); }
.connection-badge.ok { color: var(--green-800); border-color: #a8dfbd; background: var(--green-50); }
.back-site, .guide-site {
  margin-left: auto;
  min-height: 44px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  color: #334155;
  font-size: .78rem;
  font-weight: 750;
  text-decoration: none;
}
.guide-site { margin-left: auto; color: var(--red); background: var(--red-soft); }
.back-site { margin-left: 0; }
.back-site:hover, .guide-site:hover { color: var(--red); background: var(--red-soft); }

.center-panel {
  display: grid;
  min-height: calc(100vh - 76px);
  place-items: center;
  padding: 24px 18px calc(28px + env(safe-area-inset-bottom));
}

.dashboard {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 28px 18px calc(48px + env(safe-area-inset-bottom));
}

.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card { width: min(100%, 430px); padding: 30px; }
.login-card h2, .notice-card h2 { margin: 8px 0 10px; font-size: 1.55rem; }
.notice-card { max-width: 480px; padding: 30px; }
.muted { color: var(--muted); }

.form-stack { display: grid; gap: 10px; margin-top: 24px; }
.form-stack label { font-size: 0.88rem; font-weight: 750; }

input, select, textarea {
  width: 100%;
  min-height: 50px;
  border: 1px solid #b8c4d3;
  border-radius: 11px;
  padding: 11px 14px;
  color: var(--ink);
  background: white;
  outline: none;
}

textarea { min-height: 92px; resize: vertical; }

input:focus, textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(200, 16, 46, 0.11);
}

select:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 4px rgba(200, 16, 46, 0.11);
}

.primary-button, .secondary-button, .icon-button, .text-button {
  min-height: 46px;
  border-radius: 12px;
  font-weight: 760;
}

.primary-button {
  border: 1px solid #0f172a;
  color: white;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  box-shadow: 0 5px 14px rgba(15, 23, 42, .14);
}

.secondary-button {
  border: 1px solid #b8c4d3;
  padding: 0 16px;
  color: var(--ink);
  background: white;
}

.text-button { border: 0; color: var(--red); background: transparent; }
.icon-button {
  width: 46px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
  font-size: 1.3rem;
}

.form-message { min-height: 1.4em; margin: 12px 0 0; color: var(--muted); font-size: 0.88rem; }
.form-message.error { color: var(--red); }
.form-message.success { color: var(--green-650); }

.welcome-row, .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.welcome-row h2, .section-heading h2 { margin: 5px 0 0; }
.welcome-row .muted { margin: 5px 0 0; }

.pairing-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px 24px;
  margin-top: 28px;
  padding: 22px;
  border-top: 3px solid var(--red);
}

.pairing-card h3 { margin: 6px 0; }
.pairing-card p { margin-bottom: 0; }
.pairing-form { display: flex; align-items: center; gap: 10px; }
.pairing-form input { width: 160px; text-align: center; font-weight: 800; letter-spacing: 0.1em; }
.pairing-form button { padding: 0 18px; white-space: nowrap; }
.pairing-card .form-message { grid-column: 1 / -1; margin: -6px 0 0; }

.section-block { margin-top: 34px; }
.section-heading { margin-bottom: 14px; }
.device-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

.workspace-heading { align-items: flex-end; }
.workspace-heading .muted { margin: 6px 0 0; }
.device-picker { display: grid; min-width: 220px; gap: 6px; color: var(--muted); font-size: .78rem; font-weight: 750; }
.device-picker select { min-height: 44px; }
.queue-notice {
  display: flex;
  align-items: center;
  gap: 10px 18px;
  margin: 14px 0;
  border: 1px solid #a8dfbd;
  border-radius: 15px;
  padding: 13px 16px;
  color: var(--green-800);
  background: var(--green-50);
}
.queue-notice span { color: var(--muted); font-size: .82rem; }
.queue-notice.busy { border-color: #e6c878; color: var(--amber); background: #fff8dc; }
.queue-notice.offline { border-color: #efb4bf; color: var(--red); background: var(--red-soft); }
.busy-copy { color: var(--amber); font-weight: 750; }

.workspace-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(90px, 1fr));
  gap: 7px;
  margin: 12px 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.workspace-tab {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: rgba(255,255,255,.82);
  font-weight: 760;
  white-space: nowrap;
}
.workspace-tab.active { border-color: var(--ink); color: white; background: var(--ink); }
.workspace-panel { padding: 22px; box-shadow: 0 8px 22px rgba(15,23,42,.06); }
.workspace-panel h3 { margin: 6px 0; }
.workspace-panel > .muted { margin-top: 6px; }
.workspace-panel > button { margin-top: 12px; padding-inline: 18px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.check-stack { display: grid; align-content: center; gap: 8px; }
.check-stack .check-row { grid-column: auto; }
.danger-confirm { min-height: 50px; border-color: var(--red); background: linear-gradient(135deg, #d11c38, #a90e27); }
.mobile-item-list { display: grid; gap: 10px; margin: 14px 0; }
.mobile-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  background: #f8fafc;
}
.thank-you-item { display: grid; grid-template-columns: auto 1fr minmax(110px, 160px); align-items: center; gap: 11px; }
.thank-you-item > input[type="checkbox"] { width: 24px; min-height: 44px; }
.thank-you-item .thank-you-amount { min-height: 44px; }
.mobile-item-main { display: grid; gap: 3px; }
.mobile-item-main span { color: var(--muted); font-size: .78rem; }
.traffic-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.traffic-metric { display: grid; gap: 5px; border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: #f8fafc; }
.traffic-metric span { color: var(--muted); font-size: .78rem; }
.traffic-metric strong { font-size: 1.08rem; }
.schedule-header, .panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.schedule-item .form-grid { margin-top: 10px; }
.schedule-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.schedule-remove { min-height: 44px; }
.weekday-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 10px; }
.weekday-chip { position: relative; }
.weekday-chip input { position: absolute; opacity: 0; pointer-events: none; }
.weekday-chip span { display: grid; min-height: 44px; place-items: center; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: white; font-size: .78rem; font-weight: 800; }
.weekday-chip input:checked + span { border-color: #86c89f; color: var(--green-800); background: var(--green-100); }
.panel-actions { justify-content: flex-end; margin-top: 12px; }
.panel-actions button { padding-inline: 16px; }

.device-card { padding: 20px; }
.device-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.device-card h3 { margin: 0; font-size: 1.05rem; }
.device-meta { margin: 7px 0 0; color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }
.device-actions { display: flex; gap: 10px; margin-top: 20px; }
.device-actions { flex-wrap: wrap; }
.device-actions button { flex: 1; }
.recovery-code {
  margin-top: 14px;
  border: 1px solid #e6c878;
  border-radius: 13px;
  padding: 13px;
  color: #5f3c00;
  background: #fff8dc;
  overflow-wrap: anywhere;
}
.recovery-code strong { display: block; font-size: 1.2rem; letter-spacing: 0.12em; }
.recovery-code p { margin: 7px 0 0; font-size: 0.77rem; }

.danger-button {
  min-height: 46px;
  border: 1px solid #edaaa5;
  border-radius: 12px;
  padding: 0 14px;
  color: var(--red);
  background: #fff8f7;
  font-weight: 760;
}

.sharing-card { padding: 22px; }
.share-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}
.field-group { display: grid; gap: 7px; }
.field-group label { font-size: 0.82rem; font-weight: 750; }
.field-group select { min-height: 50px; }
.check-row {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.84rem;
}
.check-row { min-height: 44px; }
.check-row input { width: 22px; min-height: 22px; accent-color: var(--green-650); }
.share-form > .primary-button { grid-column: 1 / -1; }
.grants-list { display: grid; gap: 10px; margin-top: 18px; }
.grant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--green-50);
}
.grant-row h3 { margin: 0; font-size: 0.9rem; overflow-wrap: anywhere; }
.grant-row p { margin: 4px 0 0; color: var(--muted); font-size: 0.76rem; }
.grant-row .danger-button { min-height: 44px; white-space: nowrap; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.74rem;
  font-weight: 800;
}

.status-pill.online { color: var(--green-800); background: var(--green-100); }
.status-pill.offline { color: var(--red); background: var(--red-soft); }
.status-pill.busy { color: var(--amber); background: var(--amber-soft); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.jobs-list { display: grid; gap: 10px; }
.job-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.82);
}

.job-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  color: var(--ink);
  background: #e8edf4;
  font-weight: 900;
}

.job-row h3 { margin: 0; font-size: 0.94rem; }
.job-row p { margin: 4px 0 0; color: var(--muted); font-size: 0.78rem; }
.job-state { font-size: 0.78rem; font-weight: 800; }
.job-state.failed { color: var(--red); }
.job-state.succeeded { color: var(--green-650); }
.job-actions { display: grid; justify-items: end; gap: 3px; }
.job-actions .text-button { min-height: 44px; padding: 0 4px; font-size: .74rem; }

.privacy-pill {
  border: 1px solid #a9cbbb;
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--green-800);
  background: var(--green-50);
  font-size: 0.72rem;
  font-weight: 800;
}
.pending-results { display: grid; gap: 9px; }
.pending-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #b8d9c8;
  border-radius: 15px;
  padding: 14px 16px;
  color: var(--green-800);
  background: var(--green-50);
}
.pending-summary span { color: var(--muted); font-size: 0.76rem; }
.pending-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  background: rgba(255, 255, 255, 0.86);
}
.pending-row h3 { margin: 0; font-size: 0.92rem; }
.pending-row p { margin: 4px 0 0; color: var(--muted); font-size: 0.78rem; }
.pending-kind {
  flex: 0 0 auto;
  color: var(--amber);
  font-size: 0.75rem;
  font-weight: 800;
}

.empty-state {
  padding: 26px;
  border: 1px dashed #aec3b8;
  border-radius: 18px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
}
.empty-state h3 { margin: 0 0 6px; color: var(--ink); }
.empty-state p { margin: 0; }
.empty-state.compact { padding: 16px; margin-top: 16px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 18px;
  z-index: 20;
  max-width: 520px;
  margin: auto;
  border-radius: 14px;
  padding: 13px 16px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  text-align: center;
}

[hidden] { display: none !important; }

@media (max-width: 680px) {
  .brand-bar { min-height: 70px; }
  .brand-bar img { width: 40px; height: 40px; }
  .connection-badge { max-width: 92px; overflow: hidden; white-space: nowrap; }
  .back-site { padding-inline: 8px; }
  .dashboard { padding-top: 22px; }
  .pairing-card { grid-template-columns: 1fr; }
  .pairing-form { align-items: stretch; }
  .pairing-form input { width: 100%; }
  .pairing-card .form-message { grid-column: auto; }
  .device-grid { grid-template-columns: 1fr; }
  .share-form { grid-template-columns: 1fr; }
  .check-row, .share-form > .primary-button { grid-column: auto; }
  .job-row { grid-template-columns: auto 1fr; }
  .job-state { grid-column: 2; }
  .job-actions { grid-column: 2; justify-items: start; }
  .pending-summary { align-items: flex-start; flex-direction: column; }
  .workspace-heading { align-items: stretch; flex-direction: column; }
  .device-picker { width: 100%; }
  .queue-notice { align-items: flex-start; flex-direction: column; gap: 4px; }
  .workspace-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); overflow-x: visible; }
  .form-grid.two { grid-template-columns: 1fr; }
  .schedule-extra { grid-template-columns: 1fr; }
  .traffic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .brand-bar { gap: 9px; }
  .brand-bar h1 { font-size: 1rem; }
  .brand-bar .eyebrow { font-size: .62rem; }
  .back-site { display: none; }
  .guide-site { min-height: 44px; padding-inline: 8px; font-size: .72rem; }
  .login-card { padding: 24px 20px; }
  .pairing-form { flex-direction: column; }
  .device-actions { flex-direction: column; }
  .grant-row { align-items: flex-start; flex-direction: column; }
  .welcome-row { align-items: flex-start; }
  .section-heading { align-items: flex-start; }
  .workspace-panel { padding: 18px 15px; }
  .thank-you-item { grid-template-columns: auto 1fr; }
  .thank-you-item .thank-you-amount { grid-column: 2; }
  .panel-actions { align-items: stretch; flex-direction: column; }
}

/* ── 超級加強版：協作者用自己的 BNI 帳號 ── */
.operator-account {
  margin: 14px 0 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--green-50);
}

.operator-account h4 {
  margin: 0 0 6px;
  font-size: .9rem;
  color: var(--green-800);
}

.operator-account-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.operator-account-form input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.operator-chapter-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.operator-chapter-row .device-meta {
  grid-column: 1 / -1;
  margin: 0;
}

@media (max-width: 520px) {
  .operator-chapter-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .job-row { animation: rise 240ms ease-out both; }
  @keyframes rise { from { opacity: 0; transform: translateY(5px); } }
}
