:root {
  --color-primary: #0f4c81;
  --color-primary-dark: #0a3660;
  --color-accent: #d9973f;
  --color-bg: #f4f6f8;
  --color-card: #ffffff;
  --color-text: #1f2937;
  --color-text-muted: #6b7280;
  --color-success: #16a34a;
  --color-warning: #f59e0b;
  --color-danger: #dc2626;
  --color-info: #2563eb;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #e5e5e5;
  color: var(--color-text);
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ---- role switch bar ---- */
.role-switch-bar {
  position: sticky; top: 0; z-index: 100;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--color-primary-dark); padding: 10px 20px;
}
.role-tabs { display: flex; gap: 8px; }
.role-tab {
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.8);
  padding: 8px 16px; border-radius: 8px; font-size: 13px; transition: all .15s;
}
.role-tab-active { background: var(--color-accent); color: #fff; font-weight: 600; }
.reset-btn { background: transparent; border: 1px solid rgba(255,255,255,0.4); color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 12px; }

/* ---- H5 phone shell ---- */
.phone-frame { display: flex; justify-content: center; align-items: center; padding: 16px; height: calc(100vh - 56px); box-sizing: border-box; }
.phone-shell { width: 390px; height: 100%; max-height: 820px; background: #111; padding: 10px; border-radius: 36px; box-shadow: 0 20px 40px rgba(0,0,0,.35); box-sizing: border-box; display: flex; }
.phone-screen { background: var(--color-bg); border-radius: 26px; overflow: hidden; display: flex; flex-direction: column; width: 100%; height: 100%; }
.phone-statusbar { height: 44px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; font-size: 13px; font-weight: 600; background: var(--color-primary); color: #fff; }
.phone-navbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--color-primary); color: #fff; flex-shrink: 0; }
.phone-navbar .nav-back { font-size: 18px; padding: 2px 6px; }
.phone-navbar .nav-title { font-size: 15px; font-weight: 600; flex: 1; text-align: center; margin-right: 22px; }
.phone-content { flex: 1; overflow-y: auto; padding: 14px; }
.phone-tabbar { height: 58px; flex-shrink: 0; display: flex; border-top: 1px solid #e5e7eb; background: #fff; }
.tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--color-text-muted); }
.tab-item-active { color: var(--color-primary); font-weight: 600; }

/* ---- admin shell ---- */
.admin-frame { min-height: calc(100vh - 56px); }
.admin-shell { display: flex; min-height: calc(100vh - 56px); }
.admin-sidebar { width: 220px; background: var(--color-primary-dark); color: #fff; flex-shrink: 0; overflow-y: auto; }
.admin-logo { padding: 20px 16px; font-weight: 700; font-size: 14px; border-bottom: 1px solid rgba(255,255,255,.1); }
.admin-group-title { padding: 12px 20px 4px; font-size: 11px; color: rgba(255,255,255,.4); letter-spacing: 1px; }
.admin-sidebar-item { padding: 12px 20px; font-size: 13.5px; color: rgba(255,255,255,.75); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.admin-sidebar-item:hover { background: rgba(255,255,255,.06); }
.admin-sidebar-item-active { background: rgba(255,255,255,.1); color: #fff; font-weight: 600; border-left: 3px solid var(--color-accent); padding-left: 17px; }
.admin-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.admin-topbar { height: 56px; flex-shrink: 0; background: #fff; border-bottom: 1px solid #e5e7eb; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; font-size: 14px; }
.admin-content { padding: 24px; flex: 1; background: var(--color-bg); overflow-y: auto; }

/* ---- shared components ---- */
.card { background: var(--color-card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.section-title { font-size: 15px; font-weight: 600; margin: 16px 0 8px; }
.section-title:first-child { margin-top: 0; }
.empty-state { text-align: center; color: var(--color-text-muted); padding: 40px 0; font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 16px; border-radius: 10px; font-size: 14px; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid #d1d5db; color: var(--color-text); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-link { color: var(--color-primary); font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-pending, .badge-pending_payment { background: #fef3c7; color: #92400e; }
.badge-approved, .badge-paid, .badge-active, .badge-enabled, .badge-settled, .badge-completed { background: #dcfce7; color: #166534; }
.badge-rejected, .badge-cancelled, .badge-disabled { background: #fee2e2; color: #b91c1c; }
.badge-expired { background: #e5e7eb; color: #4b5563; }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-refunded { background: #ede9fe; color: #6d28d9; }
.badge-internal { background: #e0e7ff; color: #3730a3; }
.badge-external { background: #ffedd5; color: #c2410c; }

.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 13px; color: var(--color-text-muted); margin-bottom: 4px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; background: #fff; }
.form-textarea { resize: vertical; }
.form-row { display: flex; gap: 10px; }
.form-row > .form-group { flex: 1; }
.form-check { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 0; }

.avatar { border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; flex-shrink: 0; }
.upload-box { border: 1.5px dashed #d1d5db; border-radius: 10px; height: 90px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 4px; color: var(--color-text-muted); font-size: 12px; background: #fafafa; cursor: pointer; }
.upload-box:hover { border-color: var(--color-primary); color: var(--color-primary); }

.page-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.page-tab { flex: 1; text-align: center; padding: 8px; border-radius: 8px; background: #fff; font-size: 13px; color: var(--color-text-muted); }
.page-tab-active { background: var(--color-primary); color: #fff; font-weight: 600; }

.grid-cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-tile { background: #fff; border-radius: 12px; padding: 14px 8px; text-align: center; box-shadow: var(--shadow); }
.cat-tile .cat-icon { font-size: 26px; }
.cat-tile .cat-name { font-size: 12px; margin-top: 6px; font-weight: 600; }

.search-box { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 10px; padding: 11px 14px; box-shadow: var(--shadow); color: var(--color-text-muted); font-size: 13px; margin: 12px 0; cursor: pointer; }
.carousel-viewport { overflow: hidden; margin: 0 -14px; padding: 0 14px; }
.carousel-viewport:hover .carousel-track { animation-play-state: paused; }
.carousel-track { display: flex; width: max-content; animation: carousel-scroll 20s linear infinite; }
@keyframes carousel-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.home-cat-layout { display: flex; gap: 10px; align-items: flex-start; }
.home-cat-side { width: 74px; flex-shrink: 0; display: flex; flex-direction: column; gap: 6px; }
.home-cat-item { background: #fff; border-radius: 10px; padding: 10px 4px; text-align: center; font-size: 11px; color: var(--color-text-muted); box-shadow: var(--shadow); cursor: pointer; line-height: 1.4; }
.home-cat-item .cat-icon { font-size: 20px; display: block; margin-bottom: 2px; }
.home-cat-item-active { background: var(--color-primary); color: #fff; font-weight: 600; }
.home-cat-content { flex: 1; min-width: 0; }

.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #f1f1f1; }
.list-row:last-child { border-bottom: none; }

.spec-chip { display: inline-flex; align-items: center; padding: 8px 12px; border-radius: 10px; border: 1px solid #d1d5db; font-size: 13px; cursor: pointer; margin: 0 8px 8px 0; }
.spec-chip-active { border-color: var(--color-primary); background: #eaf1fb; color: var(--color-primary); font-weight: 600; }
.spec-chip .spec-delta { color: var(--color-accent); margin-left: 4px; }

.person-pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; border: 1px solid #d1d5db; font-size: 13px; cursor: pointer; margin: 0 8px 8px 0; }
.person-pill-active { border-color: var(--color-primary); background: #eaf1fb; color: var(--color-primary); font-weight: 600; }

.timeline { position: relative; padding-left: 18px; }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before { content: ''; position: absolute; left: -18px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-primary); }
.timeline-item::after { content: ''; position: absolute; left: -15px; top: 12px; bottom: -4px; width: 1px; background: #e5e7eb; }
.timeline-item:last-child::after { display: none; }
.timeline-note { font-size: 13px; font-weight: 600; }
.timeline-time { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }

.qr-box { width: 140px; height: 140px; margin: 12px auto; background: repeating-linear-gradient(45deg, #1f2937, #1f2937 6px, #fff 6px, #fff 12px); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.qr-box-inner { width: 90px; height: 90px; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 10px; text-align: center; padding: 4px; border-radius: 4px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card { background: var(--color-card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat-label { font-size: 12px; color: var(--color-text-muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; color: var(--color-text-muted); font-weight: 500; padding: 8px; border-bottom: 1px solid #e5e7eb; white-space: nowrap; }
.admin-table td { padding: 8px; border-bottom: 1px solid #f1f1f1; vertical-align: middle; }
.admin-table tr[data-action]:hover { background: #f9fafb; cursor: pointer; }
.table-scroll { overflow-x: auto; }

.secret-text { font-family: "SFMono-Regular", Menlo, monospace; font-size: 12px; background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }
.perm-tag { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 6px; background: #eaf1fb; color: var(--color-primary); font-size: 11px; margin: 0 4px 4px 0; }
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar .form-select, .filter-bar .form-input { width: auto; min-width: 140px; }

#toast-container { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; opacity: 0; transform: translateY(-8px); transition: all .2s; }
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { background: #166534; }
.toast-error { background: #b91c1c; }
.toast-info { background: #1f2937; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 9998; }
.modal-box { background: #fff; border-radius: 12px; padding: 20px; width: 320px; max-height: 80vh; overflow-y: auto; }
.modal-box-wide { width: 420px; }
.modal-message { font-size: 14px; margin-bottom: 16px; }
.modal-body { font-size: 13px; line-height: 1.9; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
