:root {
  --primary: #F1BC23;
  --primary-dark: #d9a512;
  --primary-soft: #fef6d8;
  --primary-border: #f3d062;
  --text: #18181b;
  --text-muted: #52525b;
  --text-subtle: #71717a;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e4e4e7;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --success-border: #86efac;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.06);
  --shadow-md: 0 4px 12px rgba(24, 24, 27, 0.08);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--primary);
  color: var(--text);
  border-bottom: 1px solid rgba(24, 24, 27, 0.1);
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  box-shadow: 0 2px 8px rgba(24, 24, 27, 0.08);
}

.header-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--text);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(24, 24, 27, 0.1);
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.back-btn:active {
  background: rgba(24, 24, 27, 0.2);
}

.header-titles {
  min-width: 0;
}

.header-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(24, 24, 27, 0.85);
  margin-top: 1px;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.sync-dot.live {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.25);
}

.sync-dot.demo {
  background: #2563eb;
}

.sync-dot.error {
  background: var(--danger);
}

/* Language Slider */
.lang-slider {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(24, 24, 27, 0.12);
  border-radius: 999px;
  padding: 3px;
  width: 146px;
  flex-shrink: 0;
  user-select: none;
}

.lang-slider-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--text);
  border-radius: 999px;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.lang-slider[data-active="sv"] .lang-slider-thumb {
  transform: translateX(100%);
}

.lang-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  border-radius: 999px;
  transition: color 0.2s ease;
  text-align: center;
}

.lang-btn.active {
  color: var(--primary);
}

/* Main Content */
.main-content {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px calc(14px + env(safe-area-inset-right)) calc(104px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  flex: 1;
}

/* Start Screen */
.start-intro {
  margin-bottom: 14px;
}

.start-intro h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 800;
}

.start-intro p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.role-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.role-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.role-card:active {
  transform: scale(0.985);
}

.role-card.done {
  border-color: var(--success-border);
  background: linear-gradient(180deg, #ffffff 0%, #f6fef9 100%);
}

.role-card.admin-card {
  border-color: var(--primary-border);
  background: linear-gradient(180deg, #ffffff 0%, var(--primary-soft) 100%);
}

.role-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.role-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.role-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.role-card.admin-card .role-icon {
  background: var(--primary);
  border-color: var(--primary-dark);
}

.role-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.role-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.unchecked {
  background: #f4f4f5;
  color: var(--text-muted);
}

.status-badge.done {
  background: var(--success-bg);
  color: var(--success);
}

.status-badge.lock {
  background: rgba(24, 24, 27, 0.08);
  color: var(--text);
}

.count-pill {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  padding: 4px 10px;
  border-radius: 999px;
}

.count-pill.zero {
  background: #f4f4f5;
  border-color: transparent;
  color: var(--text-subtle);
}

.location-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.loc-chip {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: #f4f4f5;
  padding: 3px 8px;
  border-radius: 6px;
}

/* Role View Controls */
.sticky-controls {
  position: sticky;
  top: calc(59px + env(safe-area-inset-top));
  z-index: 30;
  background: var(--bg);
  padding: 6px 0 10px;
  margin: -6px 0 8px;
  border-bottom: 1px solid var(--border);
}

.tabs-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.tabs-scroll::-webkit-scrollbar {
  display: none;
}

.loc-tab {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
}

.loc-tab.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--primary);
}

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

.search-box {
  flex: 1;
  position: relative;
}

.search-input {
  width: 100%;
  height: 42px;
  padding: 0 34px 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 15px;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary-dark);
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: #e4e4e7;
  color: var(--text);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.only-selected-btn {
  height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.only-selected-btn.active {
  background: var(--primary-soft);
  border-color: var(--primary-dark);
  color: var(--text);
}

/* Item Cards */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.item-card.selected {
  border-color: var(--primary);
  background: #fffdf5;
  box-shadow: 0 2px 8px rgba(241, 188, 35, 0.18);
}

.item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.item-names {
  min-width: 0;
  flex: 1;
}

.item-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  word-break: break-word;
}

.item-subtitle-zh {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 2px;
}

.item-loc-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  background: #f4f4f5;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.item-card.selected .item-loc-tag {
  background: var(--primary-soft);
  color: var(--text);
}

.item-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-btn {
  width: 48px;
  height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #f4f4f5;
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.step-btn.plus {
  background: var(--primary);
  border-color: var(--primary-dark);
}

.step-btn:active {
  transform: scale(0.94);
}

.step-btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.qty-input {
  width: 64px;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  outline: none;
}

.item-card.selected .qty-input {
  border-color: var(--primary-dark);
  background: #ffffff;
}

.unit-select {
  height: 44px;
  min-width: 84px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-subtle);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  font-size: 14px;
}

/* Sticky Bottom Bar */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 35;
  background: rgba(248, 250, 252, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}

.bottom-bar-inner {
  max-width: 760px;
  margin: 0 auto;
}

.primary-cta {
  width: 100%;
  height: 52px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(241, 188, 35, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-cta:active {
  transform: scale(0.985);
  background: var(--primary-dark);
}

.secondary-cta {
  width: 100%;
  height: 48px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

/* Admin View */
.admin-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #e4e4e7;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.admin-tab-btn {
  border: none;
  background: transparent;
  padding: 9px 6px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.admin-tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.panel-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.panel-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 800;
}

.role-progress-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.role-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8fafc;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.btn.disabled, .btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.sub-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f4f4f5;
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 12px;
}

.sub-tab-btn {
  border: none;
  background: transparent;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.sub-tab-btn.active {
  background: var(--text);
  color: var(--primary);
}

.export-preview {
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  margin: 8px 0 0;
  max-height: 220px;
  overflow-y: auto;
  color: var(--text);
}

.loc-role-select {
  height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: var(--text);
}

.btn-dark {
  background: var(--text);
  border-color: var(--text);
  color: var(--primary);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: #fca5a5;
  color: var(--danger);
}

.btn-sm {
  height: 34px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
}

.shopping-group-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-muted);
  margin: 14px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.shopping-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}

.shopping-row.bought {
  opacity: 0.58;
  background: #f4f4f5;
  text-decoration: line-through;
}

.shopping-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.check-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 800;
}

.shopping-row.bought .check-circle {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.shopping-qty {
  font-size: 15px;
  font-weight: 800;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  padding: 4px 10px;
  border-radius: 8px;
  white-space: nowrap;
}

/* Catalog Admin */
.catalog-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}

/* Forms */
.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.input, .textarea, .select-full {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
  outline: none;
}

.input:focus, .textarea:focus, .select-full:focus {
  border-color: var(--primary-dark);
}

.textarea {
  min-height: 110px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.code-block {
  background: #18181b;
  color: #f8fafc;
  padding: 10px 12px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0;
}

/* Modal & PIN Pad */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(24, 24, 27, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.modal-title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.modal-subtitle {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 12px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--text);
  background: transparent;
  transition: background-color 0.12s ease;
}

.pin-dot.filled {
  background: var(--primary);
}

.pin-error {
  text-align: center;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  min-height: 18px;
  margin-bottom: 10px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.key-btn {
  height: 54px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: #f8fafc;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
}

.key-btn:active {
  background: var(--primary-soft);
  border-color: var(--primary-dark);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--text);
  color: var(--primary);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}
