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

:root {
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #000000;
  --tg-theme-hint-color: #999999;
  --tg-theme-button-color: #2481cc;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #f1f1f1;
  --radius: 12px;
  --gap: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 15px;
  line-height: 1.5;
  padding: 16px;
  min-height: 100vh;
}

h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }

/* Navigation tabs — horizontally scrollable, labels never wrap (mobile-friendly).
   On a wide screen they grow to fill the row; on a narrow phone they stay content-sized and the
   bar scrolls sideways instead of wrapping the text into broken, uneven rows. */
.tabs {
  display: flex; gap: 6px; margin-bottom: 16px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;            /* Firefox: hide scrollbar */
  padding-bottom: 2px;
}
.tabs::-webkit-scrollbar { display: none; }   /* Chrome/Safari: hide scrollbar */
.tab-btn {
  flex: 1 0 auto; white-space: nowrap;
  padding: 9px 14px; border: none; border-radius: var(--radius);
  background: var(--tg-theme-secondary-bg-color); color: var(--tg-theme-hint-color);
  font-size: 13px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.tab-btn.active { background: var(--tg-theme-button-color); color: var(--tg-theme-button-text-color); }

.screen { display: none; }
.screen.active { display: block; }

/* Cards */
.card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius); padding: 14px; margin-bottom: var(--gap);
}
.card.stat-clickable { cursor: pointer; transition: transform .08s ease, box-shadow .08s ease; }
.card.stat-clickable:hover { box-shadow: 0 0 0 2px var(--tg-theme-button-color) inset; }
.card.stat-clickable:active { transform: scale(.98); }
.card-row { display: flex; justify-content: space-between; align-items: center; }
.card-label { color: var(--tg-theme-hint-color); font-size: 13px; }
.card-value { font-weight: 600; font-size: 18px; }

/* Stat grid */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); margin-bottom: 16px; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge-active   { background: #d4f7dc; color: #1a7a2e; }
.badge-pending  { background: #fff3cd; color: #856404; }
.badge-expired  { background: #f8d7da; color: #721c24; }
.badge-cancelled{ background: #e2e3e5; color: #495057; }

/* Buttons */
.btn {
  display: inline-block; padding: 10px 18px; border-radius: var(--radius); border: none;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity 0.15s; width: 100%;
}
.btn:active { opacity: 0.75; }
.btn-primary  { background: var(--tg-theme-button-color); color: var(--tg-theme-button-text-color); }
.btn-danger   { background: #dc3545; color: #fff; }
.btn-success  { background: #28a745; color: #fff; }
.btn-warning  { background: #fd7e14; color: #fff; }
.btn-secondary{ background: var(--tg-theme-secondary-bg-color); color: var(--tg-theme-text-color); border: 1px solid var(--tg-theme-hint-color); }
.btn-sm { padding: 6px 12px; font-size: 13px; width: auto; }
.btn-xs { padding: 4px 8px; font-size: 12px; width: auto; }

/* Form inputs */
.input-group { margin-bottom: 10px; }
.input-group label { display: block; font-size: 13px; color: var(--tg-theme-hint-color); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1.5px solid var(--tg-theme-secondary-bg-color);
  background: var(--tg-theme-bg-color); color: var(--tg-theme-text-color); font-size: 15px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tg-theme-button-color); }

/* List items */
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
}
.list-item:last-child { border-bottom: none; }
.list-item-info { flex: 1; min-width: 0; }
.list-item-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 13px; color: var(--tg-theme-hint-color); }

/* Driver cards */
.driver-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius);
  background: var(--tg-theme-secondary-bg-color);
  margin-bottom: 8px; cursor: pointer;
  transition: opacity 0.15s;
}
.driver-card:active { opacity: 0.75; }

/* Avatar */
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; text-transform: uppercase;
}
.avatar-blue   { background: #2481cc; }
.avatar-green  { background: #28a745; }
.avatar-orange { background: #fd7e14; }
.avatar-purple { background: #6f42c1; }
.avatar-teal   { background: #20c997; }
.avatar-red    { background: #dc3545; }

.driver-info { flex: 1; min-width: 0; }
.driver-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.driver-meta { font-size: 13px; color: var(--tg-theme-hint-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pending payment cards */
.pending-card {
  background: #fffbeb; border: 1px solid #fde68a;
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
}
.pending-card .pending-header {
  display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px;
}
.pending-card .pending-name { font-weight: 600; font-size: 15px; }
.pending-card .pending-date { font-size: 12px; color: var(--tg-theme-hint-color); }
.pending-card .pending-ref { font-size: 13px; color: var(--tg-theme-hint-color); margin-bottom: 10px; word-break: break-all; }
.pending-actions { display: flex; gap: 8px; }
.pending-actions .btn { flex: 1; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-sheet {
  background: var(--tg-theme-bg-color); border-radius: 20px 20px 0 0;
  width: 100%; max-height: 90vh; overflow-y: auto;
  padding: 16px; padding-bottom: 32px;
}
.modal-handle {
  width: 40px; height: 4px; background: var(--tg-theme-hint-color);
  border-radius: 2px; margin: 0 auto 16px;
}
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; font-size: 22px;
  color: var(--tg-theme-hint-color); cursor: pointer; line-height: 1;
}

/* Profile header */
.profile-header {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px;
}
.profile-header .avatar { width: 60px; height: 60px; font-size: 22px; }
.profile-name { font-size: 18px; font-weight: 700; }
.profile-username { font-size: 14px; color: var(--tg-theme-hint-color); }

/* Info rows */
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--tg-theme-secondary-bg-color);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row .info-label { color: var(--tg-theme-hint-color); }
.info-row .info-value { font-weight: 500; text-align: right; max-width: 60%; word-break: break-all; }

/* Subscription timeline */
.timeline { margin-top: 8px; }
.timeline-item {
  padding: 10px 0 10px 24px; border-left: 2px solid var(--tg-theme-secondary-bg-color);
  position: relative; font-size: 14px;
}
.timeline-item::before {
  content: ""; position: absolute; left: -5px; top: 14px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--tg-theme-secondary-bg-color);
}
.timeline-item.active::before { background: #28a745; }
.timeline-item.pending::before { background: #ffc107; }
.timeline-item:last-child { border-left: 2px solid transparent; }
.timeline-date { font-size: 12px; color: var(--tg-theme-hint-color); }

/* Card number display */
.card-number-display {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius); padding: 14px; margin-bottom: var(--gap);
}
.card-number-label { font-size: 13px; color: var(--tg-theme-hint-color); margin-bottom: 4px; }
.card-number-value {
  font-size: 20px; font-weight: 700; letter-spacing: 2px;
  font-family: "Courier New", monospace;
}
.copy-btn {
  background: none; border: 1px solid var(--tg-theme-hint-color);
  color: var(--tg-theme-hint-color); border-radius: 8px;
  padding: 4px 10px; font-size: 13px; cursor: pointer; margin-top: 8px;
}
.copy-btn:active { opacity: 0.7; }

/* Section heading with badge */
.section-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.section-head h3 { margin-bottom: 0; }
.count-badge {
  background: var(--tg-theme-button-color); color: #fff;
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 10px;
}

/* Toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.toggle { position: relative; display: inline-block; width: 48px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 26px; transition: .3s;
}
.slider:before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%; transition: .3s;
}
input:checked + .slider { background: var(--tg-theme-button-color); }
input:checked + .slider:before { transform: translateX(22px); }

/* Progress bar */
.progress-bar { height: 8px; border-radius: 4px; background: var(--tg-theme-secondary-bg-color); overflow: hidden; margin-top: 8px; }
.progress-fill { height: 100%; border-radius: 4px; background: var(--tg-theme-button-color); transition: width 0.4s; }
.progress-fill.danger { background: #dc3545; }
.progress-fill.warning { background: #fd7e14; }

/* Keyword / filter sub-tabs */
.kw-tabs { display: flex; gap: 4px; margin-bottom: 10px; overflow-x: auto; scrollbar-width: none; }
.kw-tabs::-webkit-scrollbar { display: none; }
.kw-tab { flex:1 0 auto; white-space: nowrap; padding: 6px 12px; border: none; border-radius: 8px; background: var(--tg-theme-secondary-bg-color); color: var(--tg-theme-hint-color); font-size: 13px; cursor: pointer; }
.kw-tab.active { background: var(--tg-theme-button-color); color: var(--tg-theme-button-text-color); }

.keyword-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
  background: var(--tg-theme-secondary-bg-color); border-radius: 20px; font-size: 13px; margin: 3px;
}
.keyword-chip button { border: none; background: none; color: var(--tg-theme-hint-color); cursor: pointer; font-size: 14px; padding: 0; line-height: 1; }

/* Messaging */
.msg-target-btns { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg-target-btn {
  padding: 10px 14px; border: 1.5px solid var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius); background: var(--tg-theme-bg-color);
  text-align: left; cursor: pointer; font-size: 14px; transition: border-color 0.15s;
}
.msg-target-btn:hover, .msg-target-btn.selected { border-color: var(--tg-theme-button-color); background: #e8f4ff; }

/* Collapsible */
.collapsible-header {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; padding: 4px 0; user-select: none;
}
.collapsible-header h3 { margin-bottom: 0; }
.chevron { transition: transform 0.2s; display: inline-block; color: var(--tg-theme-hint-color); }
.chevron.open { transform: rotate(180deg); }
.collapsible-body { overflow: hidden; }

.empty-state { text-align: center; color: var(--tg-theme-hint-color); padding: 24px 0; font-size: 14px; }

/* Loading spinner */
.spinner { display: flex; justify-content: center; padding: 24px; }
.spinner::after {
  content: ""; width: 28px; height: 28px; border: 3px solid var(--tg-theme-secondary-bg-color);
  border-top-color: var(--tg-theme-button-color); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg { background: #f8d7da; color: #721c24; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.success-msg { background: #d4f7dc; color: #1a7a2e; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }

/* Small phones — tighten spacing so nothing overflows or feels cramped */
@media (max-width: 380px) {
  body { padding: 12px; font-size: 14px; }
  .tab-btn { padding: 8px 12px; font-size: 12px; }
  .card { padding: 12px; }
  .stats-grid { gap: 8px; }
  .card-value { font-size: 17px; }
  .pending-actions { flex-wrap: wrap; }   /* confirm/reject stack if too narrow */
}
