/* === CSS Custom Properties === */
:root {
  --bg-body: #12121f;
  --bg-card: rgba(22, 33, 62, 0.6);
  --bg-header: rgba(18, 25, 50, 0.85);
  --bg-nav: rgba(18, 25, 50, 0.8);
  --bg-input: rgba(15, 52, 96, 0.4);
  --bg-input-heavy: rgba(15, 52, 96, 0.5);
  --bg-input-light: rgba(15, 52, 96, 0.35);
  --bg-placeholder: rgba(18, 18, 31, 0.6);
  --bg-rank: rgba(44, 62, 109, 0.6);
  --bg-leaderboard-title: rgba(15, 52, 96, 0.6);
  --bg-checkin-indicator: #333350;
  --text-primary: #d8d8e8;
  --text-secondary: #6a6a88;
  --text-muted: #555570;
  --text-heading: #fff;
  --text-placeholder: #444460;
  --text-rank: #6a7aa0;
  --text-packer: #b0b0c8;
  --text-summary: #8a8ab0;
  --text-admin-heading: #8a8ab0;
  --text-file: #555570;
  --text-history-none: #444460;
  --text-photo-placeholder: #3a3a55;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-subtle-light: rgba(255, 255, 255, 0.04);
  --border-input: rgba(26, 79, 138, 0.4);
  --border-input-heavy: rgba(26, 79, 138, 0.6);
  --border-photo: rgba(255, 255, 255, 0.1);
  --border-detail: rgba(255, 255, 255, 0.08);
  --shadow-color: rgba(0, 0, 0, 0.25);
  --shadow-light: rgba(0, 0, 0, 0.2);
  --shadow-dialog: rgba(0, 0, 0, 0.4);
  --shadow-dialog-inset: rgba(255, 255, 255, 0.04);
  --overlay-bg: rgba(0, 0, 0, 0.65);
  --dialog-bg: rgba(22, 33, 62, 0.95);
  --dialog-border: rgba(255, 255, 255, 0.08);
  --scrollbar-thumb: rgba(255, 255, 255, 0.08);
  --active-bg: rgba(255, 255, 255, 0.05);
  --nav-active-bg: rgba(233, 69, 96, 0.08);
  --accent: #e94560;
}

body.light-mode {
  --bg-body: #f0f0f5;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-header: rgba(240, 240, 245, 0.9);
  --bg-nav: rgba(240, 240, 245, 0.85);
  --bg-input: rgba(0, 0, 0, 0.05);
  --bg-input-heavy: rgba(0, 0, 0, 0.07);
  --bg-input-light: rgba(0, 0, 0, 0.04);
  --bg-placeholder: rgba(0, 0, 0, 0.06);
  --bg-rank: rgba(200, 210, 230, 0.6);
  --bg-leaderboard-title: rgba(0, 0, 0, 0.06);
  --bg-checkin-indicator: #ccccdd;
  --text-primary: #1a1a2e;
  --text-secondary: #666680;
  --text-muted: #888898;
  --text-heading: #1a1a2e;
  --text-placeholder: #aaaabc;
  --text-rank: #7788aa;
  --text-packer: #444460;
  --text-summary: #555570;
  --text-admin-heading: #555570;
  --text-file: #888898;
  --text-history-none: #aaaabc;
  --text-photo-placeholder: #bbbbcc;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-subtle-light: rgba(0, 0, 0, 0.05);
  --border-input: rgba(0, 0, 0, 0.15);
  --border-input-heavy: rgba(0, 0, 0, 0.2);
  --border-photo: rgba(0, 0, 0, 0.12);
  --border-detail: rgba(0, 0, 0, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.08);
  --shadow-light: rgba(0, 0, 0, 0.06);
  --shadow-dialog: rgba(0, 0, 0, 0.15);
  --shadow-dialog-inset: rgba(255, 255, 255, 0.5);
  --overlay-bg: rgba(0, 0, 0, 0.35);
  --dialog-bg: rgba(255, 255, 255, 0.95);
  --dialog-border: rgba(0, 0, 0, 0.1);
  --scrollbar-thumb: rgba(0, 0, 0, 0.12);
  --active-bg: rgba(0, 0, 0, 0.05);
  --nav-active-bg: rgba(233, 69, 96, 0.08);
  --accent: #e94560;
}

/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: 2rem;
  letter-spacing: 0.01em;
  transition: background 0.3s ease, color 0.3s ease;
}

/* === Header === */
#app-header {
  background: var(--bg-header);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

#app-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
}

#app-header h1 span {
  font-weight: 400;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-left: 0.5rem;
  letter-spacing: 0;
}

.header-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* === Offline Indicator === */
.offline-indicator {
  text-align: center;
  padding: 0.35rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  display: none;
}

.offline-indicator:not([hidden]) {
  display: block;
}

.offline-indicator.offline {
  background: #e74c3c;
  color: #fff;
}

.offline-indicator.syncing {
  background: #f39c12;
  color: #1a1a2e;
}

.undo-btn {
  background: linear-gradient(135deg, #533483, #6b44a0);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  box-shadow: 0 2px 8px rgba(83, 52, 131, 0.3);
}

.undo-btn:disabled {
  opacity: 0.3;
  cursor: default;
  box-shadow: none;
}

.undo-btn:not(:disabled):active {
  background: linear-gradient(135deg, #6b44a0, #8855cc);
  transform: scale(0.95);
}

.theme-toggle-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  white-space: nowrap;
}

.theme-toggle-btn:active {
  transform: scale(0.95);
}

/* === Navigation === */
#main-nav {
  display: flex;
  background: var(--bg-nav);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 52px;
  z-index: 99;
}

.nav-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.85rem 0.5rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.25s ease, border-color 0.25s ease;
  min-height: 50px;
  letter-spacing: 0.02em;
}

.nav-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.nav-btn:active {
  background: var(--nav-active-bg);
}

/* === Views === */
.view {
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
  animation: viewFadeIn 0.3s ease-out;
}

@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.view[hidden] {
  display: none;
}

.view h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.empty-msg {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

/* === Leaderboard === */
.leaderboard {
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  margin-bottom: 1rem;
  overflow: hidden;
  box-shadow: 0 4px 20px var(--shadow-color);
}

.leaderboard-title {
  background: var(--bg-leaderboard-title);
  padding: 0.5rem 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle-light);
  transition: background 0.15s ease;
}

.lb-row:last-child {
  border-bottom: none;
}

.lb-rank {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
  background: var(--bg-rank);
  color: var(--text-rank);
}

.lb-rank.rank-1 {
  background: linear-gradient(135deg, #f1c40f, #f39c12);
  color: #1a1a2e;
  box-shadow: 0 2px 10px rgba(241, 196, 15, 0.3);
}

.lb-rank.rank-2 {
  background: linear-gradient(135deg, #bdc3c7, #95a5a6);
  color: #1a1a2e;
  box-shadow: 0 2px 8px rgba(189, 195, 199, 0.2);
}

.lb-rank.rank-3 {
  background: linear-gradient(135deg, #e67e22, #d35400);
  color: #fff;
  box-shadow: 0 2px 8px rgba(230, 126, 34, 0.25);
}

.lb-name {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-stats {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.lb-earn {
  font-size: 1rem;
  font-weight: 700;
  color: #5dade2;
  min-width: 50px;
  text-align: right;
}

/* === Milestone Badges === */
.milestone-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.badge-newbie     { background: rgba(85, 85, 85, 0.5); color: #999; }
.badge-rookie     { background: rgba(44, 110, 73, 0.5); color: #6fcf97; }
.badge-pro        { background: rgba(26, 82, 118, 0.5); color: #5dade2; }
.badge-veteran    { background: rgba(108, 52, 131, 0.5); color: #bb8fce; }
.badge-packrat    { background: rgba(183, 149, 11, 0.4); color: #f4d35e; }
.badge-legend     { background: linear-gradient(135deg, #f39c12, #e74c3c); color: #fff; box-shadow: 0 1px 6px rgba(243, 156, 18, 0.3); }

/* === Personal Best Toast === */
.pb-toast {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #f39c12, #e74c3c);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  z-index: 200;
  transition: top 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 32px rgba(233, 69, 96, 0.35);
  white-space: nowrap;
}

.pb-toast[hidden] {
  display: block;
  pointer-events: none;
}

.pb-toast.show {
  top: 12px;
}

/* === Pay Button === */
.pay-btn {
  border: 2px solid rgba(192, 57, 43, 0.6);
  border-radius: 10px;
  background: rgba(192, 57, 43, 0.12);
  color: #e74c3c;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.35rem 0.7rem;
  min-height: 40px;
  min-width: 72px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.pay-btn:active {
  transform: scale(0.95);
}

.pay-btn.paid {
  border-color: rgba(39, 174, 96, 0.6);
  background: rgba(39, 174, 96, 0.12);
  color: #2ecc71;
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.1);
}

/* === Rig Outstanding Balance === */
.rig-balance {
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #e74c3c;
  background: rgba(192, 57, 43, 0.1);
  border: 1px solid rgba(192, 57, 43, 0.3);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  margin-top: 0.15rem;
  cursor: pointer;
}

/* === Balance Detail Popup === */
.bal-detail-dialog {
  max-width: 380px;
  text-align: left;
}
.bal-detail-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}
.bal-detail-list {
  max-height: 280px;
  overflow-y: auto;
}
.bal-detail-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}
.bal-detail-date {
  font-weight: 600;
  color: var(--text-heading);
  white-space: nowrap;
  min-width: 90px;
}
.bal-detail-info {
  flex: 1;
  color: var(--text-secondary);
  font-size: 0.8rem;
}
.bal-detail-due {
  font-weight: 700;
  color: #e74c3c;
  white-space: nowrap;
}
.bal-detail-total {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-heading);
}

/* === Payment Overlay === */
.pay-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  animation: overlayFadeIn 0.2s ease-out;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.pay-dialog {
  background: var(--dialog-bg);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 1px solid var(--dialog-border);
  border-radius: 18px;
  padding: 1.5rem;
  width: 90%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 16px 48px var(--shadow-dialog), 0 0 0 1px var(--shadow-dialog-inset) inset;
  animation: dialogSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dialogSlideIn {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.pay-dialog h3 {
  font-size: 1.2rem;
  color: var(--text-heading);
  margin-bottom: 0.25rem;
}

.pay-owed {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.pay-input {
  width: 100%;
  background: var(--bg-input-heavy);
  border: 2px solid var(--border-input-heavy);
  border-radius: 12px;
  color: var(--text-heading);
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
  padding: 0.75rem;
  min-height: 60px;
  margin-bottom: 1rem;
  -moz-appearance: textfield;
  transition: border-color 0.2s ease;
}

.pay-input::-webkit-outer-spin-button,
.pay-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pay-input:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 16px rgba(93, 173, 226, 0.15);
}

.pay-dialog-btns {
  display: flex;
  gap: 0.75rem;
}

.pay-dialog-btns .btn {
  flex: 1;
  font-size: 1.05rem;
  min-height: 52px;
}

/* === Payment QR Codes === */
.pay-qr-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.pay-qr-tab {
  flex: 1;
  padding: 0.5rem 0.25rem;
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.pay-qr-tab.active {
  border-color: var(--accent);
  color: var(--text-heading);
  background: var(--bg-input-heavy);
}
.pay-qr-display {
  text-align: center;
  margin-bottom: 0.75rem;
}
.pay-qr-img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 12px;
  border: 2px solid var(--border-subtle);
}
.pay-qr-missing {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2rem 0;
}
.pay-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.pay-divider::before,
.pay-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border-subtle);
}
.pay-method-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.pay-method-tab {
  flex: 1;
  padding: 0.4rem 0.15rem;
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.pay-method-tab.active {
  border-color: var(--accent);
  color: var(--text-heading);
  background: var(--bg-input-heavy);
}

/* === Rig Detail Dialog === */
.rig-detail-dialog {
  max-width: 400px;
  text-align: left;
}

.rig-detail-dialog h3 {
  text-align: center;
  margin-bottom: 1rem;
}

.rig-detail-photos {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.rig-detail-photo-slot {
  flex: 1;
  position: relative;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  border: 2px dashed var(--border-photo);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rig-detail-photo-slot:active {
  border-color: #5dade2;
  box-shadow: 0 0 12px rgba(93, 173, 226, 0.2);
}

.rig-detail-photo-slot img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
}

.rig-detail-photo-placeholder {
  width: 100%;
  height: 120px;
  background: var(--bg-placeholder);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-photo-placeholder);
}

.rig-detail-photo-label {
  display: block;
  text-align: center;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 0.3rem 0;
  background: var(--bg-input);
}

.rig-detail-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.rig-detail-input,
.rig-detail-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.75rem;
  min-height: 44px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rig-detail-input:focus,
.rig-detail-textarea:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 12px rgba(93, 173, 226, 0.1);
}

.rig-detail-textarea {
  resize: vertical;
  min-height: 70px;
}

.rig-detail-stats {
  display: flex;
  justify-content: space-around;
  padding: 0.6rem 0;
  margin-bottom: 0.75rem;
  background: var(--bg-input-light);
  border-radius: 10px;
  border: 1px solid var(--border-subtle-light);
}

/* === Today's Packs (editable counts in rig detail modal) === */
.rig-detail-today-packs {
  background: var(--bg-input-light);
  border-radius: 10px;
  border: 1px solid var(--border-subtle-light);
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.75rem;
}

.today-pack-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0;
}

.today-pack-row + .today-pack-row {
  border-top: 1px solid var(--border-subtle);
}

.today-pack-name {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.today-pack-field {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.today-pack-input {
  width: 3rem;
  background: var(--bg-input-heavy);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  text-align: center;
  padding: 0.3rem 0.2rem;
  min-height: 36px;
  -moz-appearance: textfield;
}

.today-pack-input::-webkit-inner-spin-button,
.today-pack-input::-webkit-outer-spin-button {
  opacity: 1;
}

.today-pack-input:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 8px rgba(93, 173, 226, 0.15);
}

/* === Detail Button === */
.detail-btn {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.3rem 0.6rem;
  min-height: 32px;
  border: 1px solid var(--border-detail);
  border-radius: 8px;
  transition: all 0.2s ease;
}

.detail-btn:active {
  background: var(--active-bg);
  color: var(--text-summary);
}

/* === Daily Summary Bar === */
.daily-summary {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  padding: 0.7rem 0.75rem;
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  justify-content: space-around;
  box-shadow: 0 2px 12px var(--shadow-light);
}

.summary-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.summary-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.summary-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-summary);
}

.summary-owed {
  color: var(--text-summary);
}

.summary-paid {
  color: #2ecc71;
}

.summary-due {
  color: #e74c3c;
}

/* === Main Packing View — Rig Grid === */
.rig-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.rig-card {
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 4px 20px var(--shadow-color);
  transition: box-shadow 0.2s ease;
}

.rig-card-header {
  display: flex;
  flex-direction: column;
  background: var(--bg-input);
}

.rig-photo {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--bg-body);
  display: block;
}

.rig-photo-placeholder {
  width: 100%;
  height: 120px;
  background: var(--bg-placeholder);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--text-photo-placeholder);
}

.rig-card-info {
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.rig-card-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.01em;
}

.rig-tally {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.rig-tally .full-count {
  color: #2ecc71;
  font-weight: 600;
}

.rig-tally .half-count {
  color: #f39c12;
  font-weight: 600;
}

.earn-count {
  color: #5dade2;
  font-weight: 600;
}

.rig-packers {
  padding: 0.5rem 0.75rem 0.75rem;
}

.packer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border-subtle-light);
}

.packer-row:last-child {
  border-bottom: none;
}

.packer-name {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-packer);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.packer-counts {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-right: 0.25rem;
}

.pack-btn {
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  min-width: 70px;
  min-height: 48px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.1s, box-shadow 0.2s;
  color: #fff;
}

.pack-btn:active {
  transform: scale(0.92);
}

.pack-btn.full-btn {
  background: linear-gradient(135deg, #27ae60, #2ecc71);
  box-shadow: 0 3px 12px rgba(39, 174, 96, 0.3);
}

.pack-btn.full-btn:active {
  background: linear-gradient(135deg, #2ecc71, #58d68d);
}

.pack-btn.half-btn {
  background: linear-gradient(135deg, #e67e22, #f39c12);
  box-shadow: 0 3px 12px rgba(230, 126, 34, 0.3);
}

.pack-btn.half-btn:active {
  background: linear-gradient(135deg, #f39c12, #f5b041);
}

/* Tap flash animation */
@keyframes tap-flash {
  0% { filter: brightness(1.6); transform: scale(0.92); }
  100% { filter: brightness(1); transform: scale(1); }
}

.pack-btn.flash {
  animation: tap-flash 0.3s ease-out;
}

/* Floating +1 pop */
@keyframes pack-pop {
  0%   { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -48px) scale(1.3); }
}

.pack-pop {
  position: fixed;
  z-index: 400;
  pointer-events: none;
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  animation: pack-pop 0.6s ease-out forwards;
}

.pack-pop-full { color: #2ecc71; }
.pack-pop-half { color: #f39c12; }

/* === Check-In View === */
.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 1.05rem;
  padding: 0.7rem 1rem;
  min-height: 48px;
  margin-bottom: 0.75rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input::placeholder {
  color: var(--text-placeholder);
}

.search-input:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 16px rgba(93, 173, 226, 0.1);
}

.checkin-rig-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.checkin-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.checkin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 2px solid var(--border-subtle);
  border-radius: 14px;
  color: var(--text-secondary);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 1rem;
  min-height: 64px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.checkin-btn.checked-in {
  background: rgba(39, 174, 96, 0.12);
  border-color: rgba(39, 174, 96, 0.4);
  color: #2ecc71;
  box-shadow: 0 0 16px rgba(46, 204, 113, 0.08);
}

.checkin-btn:active {
  transform: scale(0.96);
}

.checkin-indicator {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-checkin-indicator);
  flex-shrink: 0;
  transition: all 0.25s ease;
}

.checkin-btn.checked-in .checkin-indicator {
  background: #2ecc71;
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.4);
}

/* === Reload from previous day === */
.reload-day {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.reload-day label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.reload-day input[type="date"] {
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 0.5rem 0.7rem;
  min-height: 44px;
}

.btn-reload {
  background: linear-gradient(135deg, #1a4f8a, #2565a8);
  color: #fff;
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  min-height: 44px;
  box-shadow: 0 2px 8px rgba(26, 79, 138, 0.3);
}

.btn-reload:active {
  background: linear-gradient(135deg, #2565a8, #2e86de);
}

.btn-reload:disabled {
  opacity: 0.3;
  cursor: default;
  box-shadow: none;
}

/* === Admin/Settings View === */
.admin-section {
  margin-bottom: 2rem;
}

.admin-section h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-admin-heading);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.4rem;
  letter-spacing: 0.01em;
}

.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.admin-form input[type="text"] {
  flex: 1;
  min-width: 140px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  min-height: 48px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.admin-form input[type="text"]::placeholder {
  color: var(--text-placeholder);
}

.admin-form input[type="text"]:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 12px rgba(93, 173, 226, 0.1);
}

.file-upload-btn {
  background: linear-gradient(135deg, #1a4f8a, #2565a8);
  color: #ccc;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(26, 79, 138, 0.25);
}

.file-upload-btn:active {
  background: linear-gradient(135deg, #2565a8, #2e86de);
}

.file-name {
  font-size: 0.85rem;
  color: var(--text-file);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 1.2rem;
  min-height: 48px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:active {
  transform: scale(0.95);
}

.btn-add {
  background: linear-gradient(135deg, #27ae60, #2ecc71);
  color: #fff;
  box-shadow: 0 3px 12px rgba(39, 174, 96, 0.25);
}

.btn-add:active {
  background: linear-gradient(135deg, #2ecc71, #58d68d);
}

.btn-check-in {
  background: linear-gradient(135deg, #1a4f8a, #2565a8);
  color: #fff;
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  min-height: 40px;
  box-shadow: 0 2px 8px rgba(26, 79, 138, 0.25);
}

.btn-check-in:active {
  background: linear-gradient(135deg, #2565a8, #2e86de);
}

.btn-checked-in {
  background: rgba(39, 174, 96, 0.12);
  color: #2ecc71;
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  min-height: 40px;
  border: 1px solid rgba(39, 174, 96, 0.4);
  box-shadow: 0 0 12px rgba(46, 204, 113, 0.08);
}

.btn-checked-in:active {
  background: rgba(39, 174, 96, 0.2);
}

.btn-remove {
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  color: #fff;
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem;
  min-height: 40px;
  box-shadow: 0 2px 8px rgba(192, 57, 43, 0.25);
}

.btn-remove:active {
  background: linear-gradient(135deg, #e74c3c, #ec7063);
}

.admin-count {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.admin-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  transition: background 0.15s ease;
}

.admin-item-photo {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg-body);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.admin-item-name {
  flex: 1;
  font-size: 1rem;
  font-weight: 500;
}

/* === History View === */
.history-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.history-controls label {
  font-weight: 600;
  font-size: 1rem;
}

.history-controls input[type="date"] {
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 1rem;
  padding: 0.6rem 0.8rem;
  min-height: 48px;
}

#history-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-rig {
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  box-shadow: 0 4px 16px var(--shadow-light);
}

.history-rig-header {
  background: var(--bg-input);
  padding: 0.6rem 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.history-rig-body {
  padding: 0.5rem 0.75rem;
}

.history-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border-subtle-light);
  font-size: 0.95rem;
}

.history-row:last-child {
  border-bottom: none;
}

.history-totals {
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  padding: 0.75rem;
  box-shadow: 0 4px 16px var(--shadow-light);
}

.history-totals h3 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.history-total-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.95rem;
}

/* === Payout Summary === */
.payout-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.95rem;
}
.payout-divider {
  border-top: 1px solid var(--border-subtle);
  margin: 0.5rem 0;
}
.payout-packer-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.35rem 0;
  font-size: 0.95rem;
}
.payout-packer-name {
  font-weight: 600;
  color: var(--text-heading);
}
.payout-packer-calc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: right;
}
.payout-packer-calc strong {
  color: var(--text-heading);
  font-size: 0.95rem;
}

.history-none {
  text-align: center;
  color: var(--text-history-none);
  padding: 2rem;
  font-size: 1rem;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* === Login Page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-page[hidden] {
  display: none;
}

.login-card {
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px var(--shadow-color);
  text-align: center;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.login-dz-name {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.login-subtitle {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.login-label {
  display: block;
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.login-input {
  width: 100%;
  background: var(--bg-input-heavy);
  border: 2px solid var(--border-input);
  border-radius: 12px;
  color: var(--text-heading);
  font-size: 1.1rem;
  padding: 0.8rem 1rem;
  min-height: 52px;
  margin-bottom: 0.75rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-input:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 16px rgba(93, 173, 226, 0.15);
}

.login-pin-input {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.5em;
}

.login-error {
  color: #e74c3c;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.login-btn {
  width: 100%;
  font-size: 1.1rem;
  min-height: 52px;
}

/* === Packer PIN Input (Settings) === */
.packer-pin-input {
  width: 5rem;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  text-align: center;
  padding: 0.4rem 0.3rem;
  min-height: 36px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.packer-pin-input::placeholder {
  color: var(--text-placeholder);
  font-size: 0.8rem;
}

.packer-pin-input:focus {
  outline: none;
  border-color: #5dade2;
  box-shadow: 0 0 8px rgba(93, 173, 226, 0.15);
}

/* === Responsive === */
@media (max-width: 400px) {
  .rig-grid {
    grid-template-columns: 1fr;
  }

  .checkin-list {
    grid-template-columns: 1fr;
  }

  .admin-form {
    flex-direction: column;
  }

  .admin-form input[type="text"],
  .btn-add,
  .file-upload-btn {
    width: 100%;
  }
}
