:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Top Bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 12px;
}

.back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.page-title {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
}

.cookie-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray-400);
}
.cookie-indicator.fresh { background: var(--success); }
.cookie-indicator.stale { background: var(--danger); }

/* Content */
.content {
  padding: 72px 16px 80px;
  min-height: 100vh;
}

/* Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: white;
  display: flex;
  border-top: 1px solid var(--gray-200);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--gray-400);
  font-size: 10px;
  gap: 4px;
  transition: color 0.2s;
}

.tab-item.active { color: var(--primary); }
.tab-icon { font-size: 20px; }
.tab-label { font-weight: 500; }

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}

.card-label {
  font-size: 13px;
  color: var(--gray-500);
}

.card-value {
  font-size: 14px;
  font-weight: 500;
}

/* Summary Cards */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.summary-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.summary-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* Compact Group Buy List */
.gb-compact-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}

.gb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: white;
  text-decoration: none;
  color: inherit;
  gap: 8px;
  transition: background 0.15s;
}

.gb-row:active {
  background: var(--gray-50);
}

.gb-row-selected {
  background: #eff6ff;
  border-left: 3px solid var(--primary);
}

.gb-row-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gb-row-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.gb-col-status {
  width: 44px;
  text-align: center;
  flex-shrink: 0;
}

.gb-col-count {
  width: 28px;
  text-align: right;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
}

.gb-col-pending {
  width: 28px;
  text-align: right;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--gray-300);
  font-weight: 500;
}

.gb-col-pending.gb-row-pending {
  color: white;
  background: var(--danger);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* Applicant Card */
.applicant-card {
  background: white;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
}

.applicant-check {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.applicant-info { flex: 1; min-width: 0; }

.applicant-nick {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.applicant-level {
  font-size: 11px;
  color: var(--gray-500);
  font-weight: 400;
}

.applicant-meta {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.applicant-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Multi-purchase badge */
.multi-purchase-badge {
  background: #f3e8ff;
  color: #7c3aed;
  cursor: pointer;
  font-size: 10px;
  padding: 1px 6px;
}

.multi-purchase-badge:hover {
  background: #ede9fe;
}

/* Applicant Table (hidden on mobile by default) */
.applicant-table {
  display: none;
}

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

.applicant-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.applicant-table thead {
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
}

.applicant-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--gray-600);
  white-space: nowrap;
  user-select: none;
}

.applicant-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
}

.applicant-table tbody tr:hover {
  background: var(--gray-50);
}

.at-sortable {
  cursor: pointer;
}

.at-sortable:hover {
  color: var(--primary);
}

.at-check {
  width: 36px;
}

.applicant-table .applicant-check-table {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fef2f2; color: #991b1b; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  gap: 6px;
}

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-block { width: 100%; }

/* Filter tabs */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--gray-300);
  background: white;
  color: var(--gray-600);
  cursor: pointer;
  white-space: nowrap;
}

.filter-chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Batch action bar */
.batch-bar {
  position: fixed;
  bottom: 64px;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--gray-200);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 90;
}

.batch-bar.hidden { display: none; }

.batch-count {
  font-size: 13px;
  color: var(--gray-600);
  flex: 1;
}

/* Sub-tabs */
.sub-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--gray-200);
}

.sub-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-400);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.sub-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Multi-purchase compact list */
.multi-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.multi-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: white;
  text-decoration: none;
  color: inherit;
  gap: 8px;
}

.multi-item:active { background: var(--gray-50); }
.multi-item:hover { background: var(--gray-50); }

/* Recent deposits */
.deposit-summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 13px;
  font-weight: 500;
}

.deposit-total {
  font-size: 15px;
  font-weight: 700;
}

.deposit-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--gray-200);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.deposit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
}

.deposit-row:active { background: var(--gray-50); }
.deposit-row:hover { background: var(--gray-50); }

.deposit-date {
  color: var(--gray-400);
  font-size: 12px;
  min-width: 42px;
  flex-shrink: 0;
}

.deposit-nick {
  font-weight: 600;
  min-width: 60px;
  flex-shrink: 0;
}

.deposit-title {
  flex: 1;
  min-width: 0;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Comment list */
.comment-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.comment-item {
  background: white;
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.comment-mine {
  background: #eff6ff;
  border-left: 3px solid var(--primary);
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.comment-nick {
  font-size: 13px;
  font-weight: 600;
}

.comment-date {
  font-size: 11px;
  color: var(--gray-400);
}

.comment-body {
  font-size: 13px;
  color: var(--gray-700);
  line-height: 1.5;
  margin-bottom: 6px;
  word-break: break-word;
}

.comment-reply-btn {
  font-size: 11px !important;
  padding: 3px 8px !important;
}

.deposit-price {
  font-weight: 600;
  color: var(--primary);
  flex-shrink: 0;
  text-align: right;
  min-width: 60px;
}

.multi-item-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multi-item-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.multi-item-date {
  font-size: 11px;
  color: var(--gray-400);
}

/* Split layout (desktop only, base hidden) */
.split-layout {
  display: flex;
  flex-direction: column;
}

.split-left {
  margin-bottom: 16px;
}

.split-right {
  flex: 1;
  min-width: 0;
}

/* Form elements */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

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

.form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 15px;
  background: white;
}

/* Toast */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  transition: opacity 0.3s;
}

.toast.hidden { opacity: 0; pointer-events: none; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: white;
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  padding: 24px 20px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* Credit list */
.credit-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: white;
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.credit-nick {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
}

.credit-balance {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}

/* Transaction list */
.tx-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}

.tx-info { flex: 1; }

.tx-type {
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 2px;
}

.tx-memo {
  font-size: 12px;
  color: var(--gray-500);
}

.tx-amount {
  font-size: 15px;
  font-weight: 600;
}

.tx-amount.positive { color: var(--success); }
.tx-amount.negative { color: var(--danger); }

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--gray-400);
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray-400);
}

.empty-icon { font-size: 40px; margin-bottom: 12px; }

/* Utility */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }

/* ==========================================
   Desktop styles (min-width: 768px)
   ========================================== */
@media (min-width: 768px) {
  /* Tab bar moves to top, inline horizontal */
  .tab-bar {
    position: fixed;
    top: 0;
    bottom: auto;
    left: auto;
    right: 0;
    width: auto;
    height: 56px;
    border-top: none;
    border-bottom: none;
    background: transparent;
    padding-bottom: 0;
    gap: 0;
  }

  .tab-item {
    flex: unset;
    flex-direction: row;
    gap: 4px;
    padding: 0 16px;
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    white-space: nowrap;
    height: 56px;
  }

  .tab-item.active {
    color: white;
  }

  .tab-icon {
    font-size: 14px;
  }

  .tab-label {
    font-size: 13px;
  }

  /* Content area */
  .content {
    padding: 72px 24px 24px;
    max-width: 1400px;
    margin: 0 auto;
    min-height: 100vh;
  }

  /* Split layout */
  .split-layout {
    flex-direction: row;
    gap: 20px;
  }

  .split-left {
    width: 320px;
    flex-shrink: 0;
    margin-bottom: 0;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    position: sticky;
    top: 72px;
  }

  .split-right {
    flex: 1;
    min-width: 0;
  }

  /* Show table, hide cards on desktop */
  .applicant-table {
    display: table;
  }

  .applicant-cards {
    display: none;
  }

  /* Summary grid: 4 columns */
  .summary-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Modal: centered dialog */
  .modal {
    align-items: center;
  }

  .modal-content {
    border-radius: 16px;
    max-width: 520px;
  }

  /* Tighter card padding */
  .card {
    padding: 14px 16px;
    margin-bottom: 10px;
  }

  /* Batch bar */
  .batch-bar {
    bottom: 0;
    max-width: 1400px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 12px 12px 0 0;
  }

  /* Compact list tighter */
  .gb-row {
    padding: 8px 12px;
    font-size: 13px;
  }

  .gb-row-title {
    font-size: 13px;
  }
}
