:root {
  --bg: #e9e9e9;
  --bg-accent: #e9e9e9;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --line: #c8c8c8;
  --panel: #fff;
  --brand: #2b5f8a;
  --brand-ink: #1a3d5c;
  --accent: #8a4b12;
  --danger: #a1281a;
  --ok: #2d6a3e;
  --shadow: none;
  --radius: 3px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --display: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: none;
}

.login-panel-wide {
  width: min(520px, 100%);
}

.auth-switch {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.9rem;
}

.auth-switch a.btn-link {
  display: inline;
}

.inline-field {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.inline-field input {
  flex: 1;
  min-width: 0;
}

.inline-field .btn {
  white-space: nowrap;
}

.field-hint {
  margin: 4px 0 0;
  font-size: 0.82rem;
}

.brand {
  font-family: var(--font);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--ink);
  margin: 0 0 4px;
}

.subtitle {
  margin: 0 0 28px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}

.label-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.label-row label {
  margin: 0;
}

.info-tip-btn {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f5f8fb;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.info-tip-btn:hover,
.info-tip-btn[aria-expanded="true"] {
  background: var(--brand);
  border-color: #234f73;
  color: #fff;
}

.field-info-box {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #dbe7f2;
  border-radius: var(--radius);
  background: #f7fbff;
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.5;
}

.field input,
.field select,
.field textarea,
.toolbar input,
.toolbar select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  padding: 7px 9px;
  color: var(--ink);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.remember-row input {
  width: auto;
  margin: 0;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 7px 12px;
  font-weight: 600;
  font-size: 0.92rem;
}

.btn:hover {
  opacity: 0.92;
}

.btn:active {
  opacity: 0.85;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: #234f73;
}

.btn-secondary {
  background: #f5f5f5;
  color: var(--ink);
  border-color: var(--line);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.25);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 10px;
}

.btn-block {
  width: 100%;
}

.alert {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid #e0b4b0;
  background: #fdf3f2;
  color: var(--danger);
  font-size: 0.9rem;
}

.alert-ok {
  border-color: #b8d4be;
  background: #f2f8f3;
  color: var(--ok);
}

.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-family: var(--font);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar-left {
  display: grid;
  gap: 2px;
}

.user-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--line);
  background: #f3f3f3;
}

.nav-btn {
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: -1px;
}

.nav-btn.active {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  box-shadow: none;
  overflow: hidden;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #f7f7f7;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 140px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  color: var(--ink);
  font-weight: 600;
  background: #efefef;
}

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

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.badge {
  display: inline-block;
  border-radius: var(--radius);
  padding: 2px 6px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #eef2f6;
  color: var(--brand-ink);
  border: 1px solid #d5dde5;
}

.badge-warn {
  background: #fff6eb;
  color: #7a4510;
  border-color: #ecd4b8;
}

.badge-muted {
  background: #f2f2f2;
  color: var(--muted);
  border-color: #ddd;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 40;
}

.modal {
  width: min(520px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 16px;
}

.modal h3 {
  margin: 0 0 12px;
  font-family: var(--font);
  font-size: 1rem;
}

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

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 720px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .shell {
    padding: 12px 10px 24px;
  }

  th,
  td {
    padding: 8px;
  }
}

.service-id {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  font-size: 0.78rem;
  background: #f4f7f5;
  padding: 2px 6px;
  border-radius: 6px;
}

.btn-link {
  border: 0;
  background: none;
  color: var(--brand);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0 4px;
}

.bookings-toolbar {
  align-items: center;
}

.bookings-toolbar input[type="date"] {
  min-width: 150px;
}

.bookings-day-head {
  padding: 12px 16px 0;
}

.bookings-day-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.bookings-day-branch {
  margin: 4px 0 0;
  font-size: 0.88rem;
}

.table-wrap td.empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 16px;
}

.modal-wide {
  max-width: 640px;
  max-height: 90vh;
  overflow: auto;
}

.service-form.modal-wide {
  width: min(680px, 100%);
  max-height: min(90vh, 860px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.service-form .modal-head {
  padding: 16px 18px 0;
  flex-shrink: 0;
}

.service-form .modal-head h3 {
  margin: 0;
}

.service-form .form-sections {
  flex: 1;
  overflow: auto;
  padding: 12px 18px 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fafafa;
  padding: 12px 14px;
}

.form-section-title {
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.service-form .form-section .field {
  margin-bottom: 10px;
}

.service-form .form-section .field:last-child {
  margin-bottom: 0;
}

.service-form .field-nested {
  margin-bottom: 0;
}

.service-form .field-hint-block {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.days-grid .perm-item {
  font-size: 0.82rem;
  justify-content: center;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.staff-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.payment-methods-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.service-form .modal-actions {
  flex-shrink: 0;
  margin-top: 0;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

@media (max-width: 720px) {
  .days-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .staff-grid,
  .payment-methods-grid {
    grid-template-columns: 1fr;
  }
}

.qr-service-name {
  margin: 0 0 4px;
  font-weight: 700;
  color: var(--brand-ink);
}

.qr-service-id {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.qrcode-box {
  display: flex;
  justify-content: center;
  margin: 0 auto 12px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  width: fit-content;
}

.qr-hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 12px;
}

.tenant-switcher {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  background: #fff;
  min-width: 160px;
  font-size: 0.9rem;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.perm-item {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.9rem;
  color: var(--brand-ink);
}

.banner-settings {
  margin: 0 14px 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.payments-intro {
  padding: 0 20px 16px;
  color: var(--muted);
  line-height: 1.5;
}

.payments-intro .muted {
  font-size: 0.9rem;
}

.webhook-url {
  display: block;
  margin: 6px 0 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: #f5f5f5;
  border: 1px solid var(--line);
  font-size: 0.8rem;
  word-break: break-all;
}

.payments-form {
  display: grid;
  gap: 16px;
  padding: 0 20px 28px;
}

.payment-provider-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #fff;
}

.payment-provider-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.payment-provider-head h3 {
  margin: 0 0 4px;
  font-family: var(--display);
  color: var(--brand-ink);
}

.payment-ready {
  margin: 0;
  font-size: 0.85rem;
  color: #9a5b2e;
}

.payment-ready.is-ready {
  color: #0f6b4c;
}

.muted {
  color: var(--muted);
  font-weight: 400;
}

.banner-settings-head h3 {
  margin: 0 0 6px;
  font-family: var(--display);
  color: var(--brand-ink);
}

.banner-settings-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.banner-settings-body {
  margin-top: 14px;
  display: grid;
  gap: 14px;
}

.banner-preview-wrap,
.banner-preview-empty {
  border-radius: 12px;
  overflow: hidden;
  border: 1px dashed var(--line);
  background: #f8faf9;
}

.banner-preview-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.banner-preview-img {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
}

.banner-settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.banner-upload-btn {
  cursor: pointer;
}

.banner-upload-btn.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 0 20px 24px;
}

.theme-card {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}

.theme-card:hover {
  border-color: #999;
}

.theme-card-selected {
  border-color: var(--brand);
  background: #f8fafc;
}

.theme-preview {
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(165deg, var(--pv-bg), var(--pv-accent));
  border: 1px solid var(--pv-line);
  padding: 10px;
  min-height: 120px;
}

.theme-preview-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.theme-preview-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--pv-brand);
}

.theme-preview-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--pv-ink);
}

.theme-preview-card {
  height: 42px;
  border-radius: 8px;
  background: var(--pv-panel);
  border: 1px solid var(--pv-line);
  margin-bottom: 8px;
}

.theme-preview-btn {
  width: 58%;
  height: 10px;
  border-radius: 999px;
  background: var(--pv-brand);
}

.theme-card-meta {
  display: grid;
  gap: 4px;
  margin-top: 10px;
}

.theme-card-meta strong {
  color: var(--brand-ink);
}

.theme-card-meta span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.theme-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.theme-card-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--brand);
}

.theme-preview-link {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brand);
  text-decoration: none;
}

.theme-preview-link:hover {
  text-decoration: underline;
}

.analytics-panel {
  padding: 12px 14px 16px;
  display: grid;
  gap: 12px;
}

.analytics-meta-line {
  margin: 0;
  font-size: 0.88rem;
}

.analytics-narrative {
  margin: 0;
  color: var(--ink);
  line-height: 1.5;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.summary-table th,
.summary-table td {
  text-align: center;
  padding: 6px 8px;
}

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

.chart-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px 8px;
}

.chart-card h4 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--ink);
  font-weight: 600;
}

.analytics-list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-top: 4px;
}

.analytics-list-head h4 {
  margin: 0;
  font-size: 0.95rem;
}

.table-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 0 4px;
  flex-wrap: wrap;
}

.table-pager .pager-info {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 8rem;
  text-align: center;
}

.remark-cell {
  max-width: 160px;
  font-size: 0.85rem;
  line-height: 1.35;
  word-break: break-word;
}

.analytics-hint {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.85rem;
  background: #fafafa;
}

.analytics-hint code {
  font-size: 0.82rem;
  color: var(--ink);
}

.analytics-customer-table td.cell-list {
  font-size: 0.85rem;
  max-width: 180px;
  word-break: break-word;
}

.analytics-customer-table .cell-metrics {
  white-space: nowrap;
  font-size: 0.85rem;
}

.tier-tag {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.78rem;
  background: #f5f5f5;
}

.tier-tag.tier-high {
  background: #e8f0e8;
  border-color: #b8cdb8;
}

.tier-tag.tier-mid {
  background: #f8f0e6;
  border-color: #dcc9b0;
}

.tier-tag.tier-low {
  background: #f0f0f0;
  border-color: #ccc;
}

/* legacy analytics card classes kept for compatibility */
.analytics-hero,
.analytics-eyebrow,
.analytics-stats,
.stat-card,
.analytics-list,
.insight-card,
.insight-top,
.insight-sub,
.insight-score,
.score-num,
.score-tier,
.insight-summary,
.insight-metrics,
.insight-cols,
.insight-remarks {
  display: none;
}

@media (max-width: 720px) {
  .themes-grid {
    grid-template-columns: 1fr;
    padding: 0 12px 20px;
  }

  .themes-intro {
    padding: 0 12px 14px;
  }

  .banner-settings {
    margin: 0 12px 20px;
  }

  .analytics-panel {
    padding: 10px;
  }

  .analytics-charts {
    grid-template-columns: 1fr;
  }
}

.lang-switch {
  display: inline-flex;
  gap: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.lang-btn {
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 5px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.lang-btn + .lang-btn {
  border-left: 1px solid var(--line);
}

.lang-btn.active {
  background: #e8eef3;
  color: var(--ink);
}
