/* ==========================================================================
   迎宾轮牌系统 - 专为 iPad mini 横屏 (1133×744 / 1024×768) 深度优化
   ========================================================================== */

:root,
[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-elevated: #1e293b;
  --border: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(148, 163, 184, 0.32);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-fg: #ffffff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-elevated: #f8fafc;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.2);
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-fg: #ffffff;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 10px 28px -8px rgba(15, 23, 42, 0.08);
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

input {
  user-select: text;
}

.hidden {
  display: none !important;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Header */
.app-header {
  height: 68px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.brand-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}

.conn-badge.online {
  color: var(--success);
}

.conn-badge.offline {
  color: var(--warning);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.clock-pill {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 14px;
  text-align: right;
  min-width: 112px;
}

.clock-time {
  font-size: 17px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.1;
}

.clock-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.icon-btn,
.nav-btn {
  height: 44px;
  padding: 0 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, opacity 0.15s ease;
}

.icon-btn:active,
.nav-btn:active,
.action-btn:active,
.small-btn:active {
  transform: scale(0.97);
}

.icon-btn svg,
.nav-btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.icon-btn.muted {
  opacity: 0.55;
}

.nav-btn {
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-fg);
  padding: 0 16px;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

/* Main Reception Grid */
.main-grid {
  flex: 1;
  min-height: 0;
  padding: 18px 22px;
  display: grid;
  grid-template-columns: 7fr 5fr;
  gap: 18px;
}

/* Left Hero Panel */
.hero-panel {
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 0;
}

.hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.status-pill.live {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.status-pill.paused {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.round-counter {
  font-size: 13px;
  color: var(--text-muted);
}

.round-counter strong {
  color: var(--text);
  font-size: 15px;
}

.hero-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 12px 0;
}

.staff-hero {
  display: flex;
  align-items: center;
  gap: 20px;
}

.hero-avatar {
  width: 86px;
  height: 86px;
  border-radius: 22px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 800;
  box-shadow: 0 10px 24px -6px rgba(37, 99, 235, 0.45);
  flex-shrink: 0;
}

.hero-tags {
  display: flex;
  align-items: center;
  gap: 10px;
}

.code-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.role-text {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.hero-name {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-top: 6px;
}

/* Timer Card */
.timer-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px 28px;
  text-align: center;
  transition: border-color 0.25s ease;
}

.timer-card.warning {
  border-color: var(--warning);
}

.timer-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.timer-digits {
  font-size: 86px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.timer-card.warning .timer-digits {
  color: var(--warning);
}

.progress-track {
  width: 100%;
  height: 11px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 18px;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.4s linear, background-color 0.25s ease;
}

.timer-card.warning .progress-bar {
  background: var(--warning);
}

.timer-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 12px;
}

.timer-card.warning .timer-hint {
  color: var(--warning);
  font-weight: 600;
}

/* Hero Action Buttons */
.hero-actions {
  display: grid;
  grid-template-columns: 4fr 3fr 5fr;
  gap: 12px;
}

.action-btn {
  height: 58px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.action-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.action-btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
}

.action-btn.secondary {
  background: var(--surface-elevated);
  border-color: var(--border);
  color: var(--text);
}

.action-btn.full {
  width: 100%;
  height: 48px;
  font-size: 15px;
}

/* Right Queue Column */
.queue-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.next-panel {
  padding: 16px 18px;
  border: 2px solid rgba(59, 130, 246, 0.45);
  flex-shrink: 0;
}

.panel-header-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.next-tag {
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 0.03em;
}

.muted-xs {
  font-size: 12px;
  color: var(--text-muted);
}

.next-card-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar-md {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  flex-shrink: 0;
}

.avatar-sm {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}

.person-name-lg {
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.person-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Queue List Panel */
.list-panel {
  flex: 1;
  min-height: 0;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-desc {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.scroll-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 4px;
}

.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.queue-item:last-child {
  border-bottom: none;
}

.queue-item.resting {
  opacity: 0.6;
}

.rank-num {
  width: 26px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-muted);
  flex-shrink: 0;
}

.section-divider {
  padding: 12px 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.empty-state {
  padding: 36px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.small-btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.small-btn.primary {
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-fg);
}

.small-btn.danger {
  border-color: rgba(239, 68, 68, 0.45);
  color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
}

.small-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ==================== ADMIN VIEW ==================== */
.admin-grid {
  flex: 1;
  min-height: 0;
  padding: 18px 22px;
  display: grid;
  grid-template-columns: 4fr 8fr;
  gap: 18px;
}

.admin-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
}

.form-panel,
.settings-panel,
.admin-right {
  padding: 18px 20px;
}

.admin-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.admin-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count-pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}

.staff-form {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.field input,
.custom-interval-row input,
.pin-form input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.field input:focus,
.custom-interval-row input:focus,
.pin-form input:focus {
  border-color: var(--primary);
}

.interval-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.preset-btn {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.preset-btn.active {
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-fg);
}

.custom-interval-row {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.custom-interval-row input {
  width: 90px;
  text-align: center;
}

.admin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.admin-item:last-child {
  border-bottom: none;
}

.admin-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tag-live {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

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

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

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

.pin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pin-form input {
  text-align: center;
  letter-spacing: 0.25em;
  font-size: 20px;
  font-weight: 700;
}

.pin-error {
  font-size: 12px;
  color: var(--danger);
  text-align: center;
  font-weight: 600;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions .action-btn {
  height: 46px;
  font-size: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 60;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* iPad mini 5 (1024×768) & compact landscape adjustments */
@media (max-width: 1080px) {
  .app-header {
    padding: 0 16px;
    height: 62px;
  }
  .main-grid,
  .admin-grid {
    padding: 14px 16px;
    gap: 14px;
  }
  .hero-panel {
    padding: 18px 20px;
  }
  .hero-name {
    font-size: 36px;
  }
  .timer-digits {
    font-size: 74px;
  }
  .icon-btn span {
    display: none;
  }
}

/* Portrait fallback if rotated accidentally */
@media (max-width: 820px) {
  html, body {
    overflow: auto;
  }
  .app-shell {
    height: auto;
    min-height: 100dvh;
  }
  .main-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}
