:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(128, 128, 128, 0.22);
  --danger: #e5484d;
  --ok: #22a06b;
}

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

body {
  margin: 0;
  padding: 0 0 76px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

#content { padding: 12px 12px 0; }

.loading, .empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--hint);
}

/* Filtr chiplar */
.chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chip {
  flex: 1;
  padding: 9px 12px;
  border: none;
  border-radius: 10px;
  background: var(--card);
  color: var(--hint);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-text); }

/* Kartochka */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.card-id { font-weight: 700; font-size: 16px; }

.badge {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge.jarayonda { background: #ffb02e22; color: #b26a00; }
.badge.tayyor { background: #2481cc22; color: var(--accent); }
.badge.topshirildi { background: #22a06b22; color: var(--ok); }
.badge.opening { background: #e5484d22; color: var(--danger); }

.card-name { font-weight: 600; margin-bottom: 2px; }
.card-phone { color: var(--hint); font-size: 14px; text-decoration: none; }

.warn { margin-top: 6px; font-size: 12px; color: var(--hint); }

.rows { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  font-size: 14px;
}
.row span:first-child { color: var(--hint); }
.row span:last-child { font-weight: 500; text-align: right; }
.row .debt { color: var(--danger); font-weight: 700; }
.row .paid-full { color: var(--ok); font-weight: 600; }

.actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { flex: 0 0 46px; color: var(--danger); }
.btn.wide { width: 100%; }

/* FAB */
.fab {
  position: fixed;
  right: 16px;
  bottom: 88px;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

/* Pastki menyu */
#nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  padding: 9px 4px;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
}
.nav-btn span { display: block; font-size: 21px; margin-bottom: 2px; }
.nav-btn.active { color: var(--accent); }

/* Modal oyna */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.sheet {
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.icon-btn {
  border: none;
  background: none;
  color: var(--hint);
  font-size: 20px;
  cursor: pointer;
}

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--hint); }
input {
  width: 100%;
  margin-top: 5px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
input:focus { outline: none; border-color: var(--accent); }

.error { color: var(--danger); font-size: 14px; margin-bottom: 10px; }

.hint-box {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 13px;
  color: var(--hint);
}

.date-btn {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

/* Sana va vaqt tanlash — suriladigan g'ildirak */
.field { margin-bottom: 14px; }
.field-label { margin-bottom: 7px; font-size: 13px; color: var(--hint); }

.wheel {
  position: relative;
  display: flex;
  gap: 4px;
  height: 180px;
  margin-bottom: 10px;
  padding: 0 6px;
  border-radius: 12px;
  background: var(--bg);
  overflow: hidden;
}
.wheel-highlight {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 72px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  opacity: 0.16;
  pointer-events: none;
}
.wheel-col {
  flex: 1;
  height: 100%;
  padding: 72px 0;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  text-align: center;
}
.wheel-col::-webkit-scrollbar { width: 0; }
#w-day { flex: 1.7; }

.wheel-item {
  height: 36px;
  line-height: 36px;
  font-size: 15px;
  color: var(--hint);
  white-space: nowrap;
  scroll-snap-align: center;
}
.wheel-item.sel { color: var(--text); font-weight: 700; }

/* Taqvim */
/* O'q tugmalari markazda — sahifani yopish tugmasidan uzoqda turishi uchun */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 6px 0 14px;
}
.cal-title {
  min-width: 132px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}
.cal-nav {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.cal-nav:active { background: var(--accent); color: var(--accent-text); }
.cal-week, .cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}
.cal-week { margin-bottom: 6px; font-size: 12px; color: var(--hint); }
.cal-day {
  padding: 9px 0;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
}
.cal-day.other { opacity: 0.35; }
.cal-day.today { font-weight: 700; color: var(--accent); }
.cal-day.in-range {
  background: rgba(36, 129, 204, 0.2); /* eski Android WebView uchun */
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.cal-day.edge { background: var(--accent); color: var(--accent-text); font-weight: 700; }

/* Qidiruv */
.search {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.search:focus { outline: none; border-color: var(--accent); }

/* Mavjud mijozni tanlash taklifi */
.suggest {
  margin: -6px 0 12px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  overflow: hidden;
}
.suggest-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item small { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--hint); }

.card.tap { cursor: pointer; }
.btn.small { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; }

/* Solishtiruv — harakatlar tarixi */
.timeline {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}
.tl {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 13px;
}
.tl span:last-child { color: var(--hint); white-space: nowrap; }

.range-label {
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--hint);
  text-align: center;
}

.picked-summary {
  margin: 4px 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
}

.rank {
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 700;
  color: var(--hint);
}

.row .strong { font-weight: 700; }

/* Hisobot */
.stat { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.stat:last-child { border-bottom: none; }
.stat-label { color: var(--hint); }
.stat-value { font-weight: 600; }
.stat-value.big { font-size: 17px; }
.stat-value.debt { color: var(--danger); }
