:root {
  --bg: #0a0f1e;
  --bg-2: #0e1530;
  --card: #131b33;
  --card-2: #172040;
  --border: #26315a;
  --text: #e9edf9;
  --muted: #93a0c2;
  --accent: #4f7cff;
  --accent-2: #6f95ff;
  --green: #2ecc8f;
  --red: #ff5f6d;
  --orange: #f5a524;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 10% -10%, #16234a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { color: #9db6ff; }

.app { display: flex; min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: rgba(10, 16, 34, 0.86);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; padding: 0 6px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  font-weight: 800; font-size: 18px; color: #fff;
  box-shadow: 0 8px 18px rgba(79, 124, 255, 0.35);
}
.brand strong { display: block; font-size: 16px; letter-spacing: .3px; }
.brand small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--card); color: var(--text); }
.nav a.active { background: linear-gradient(90deg, rgba(79,124,255,.22), rgba(79,124,255,.05)); color: #fff; border: 1px solid rgba(79,124,255,.35); }
.nav .ico { width: 18px; text-align: center; }

.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.sidebar-foot a { color: var(--muted); }

/* ------------------------------------------------------------------- main */
.main { flex: 1; padding: 26px 32px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: .2px; }
.topbar .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ------------------------------------------------------------------ cards */
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: .4px; }
.stat .value span { color: var(--muted); font-size: 14px; font-weight: 500; }
.stat .hint { color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ------------------------------------------------------------------ table */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 10px; text-align: left; border-bottom: 1px solid rgba(38, 49, 90, .7); vertical-align: middle; }
.table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .7px; font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(79, 124, 255, 0.06); }
.table .num { font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* ----------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .2px;
  border: 1px solid transparent;
}
.badge.ok { color: #6ff0be; background: rgba(46, 204, 143, .12); border-color: rgba(46, 204, 143, .32); }
.badge.muted { color: #a9b4d0; background: rgba(147, 160, 194, .12); border-color: rgba(147, 160, 194, .25); }
.badge.warn { color: #ffd27a; background: rgba(245, 165, 36, .12); border-color: rgba(245, 165, 36, .32); }
.badge.danger { color: #ff9aa2; background: rgba(255, 95, 109, .12); border-color: rgba(255, 95, 109, .32); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card-2); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: .15s ease; white-space: nowrap;
}
.btn:hover { border-color: #3a4a7d; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #7458f0); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.success { background: rgba(46, 204, 143, .16); border-color: rgba(46, 204, 143, .45); color: #7bf0c4; }
.btn.warn { background: rgba(245, 165, 36, .14); border-color: rgba(245, 165, 36, .4); color: #ffd27a; }
.btn.danger { background: rgba(255, 95, 109, .12); border-color: rgba(255, 95, 109, .38); color: #ff9aa2; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ------------------------------------------------------------------ forms */
.field { margin-bottom: 13px; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; font-weight: 500; }
.field .hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="tel"],
input[type="file"], select, textarea {
  width: 100%; padding: 10px 12px;
  border-radius: 9px; border: 1px solid var(--border);
  background: #0c1327; color: var(--text);
  font-size: 13px; font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 124, 255, .16); }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #5c6a91; }

.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.checkline { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.checkline input { width: auto; }

/* checkboxes list */
.check-list { max-height: 280px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: rgba(8, 13, 27, .5); }
.check-item { display: flex; align-items: flex-start; gap: 9px; padding: 8px 9px; border-radius: 8px; cursor: pointer; }
.check-item:hover { background: rgba(79, 124, 255, .09); }
.check-item input { margin-top: 2px; width: auto; }
.check-item .meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.empty { color: var(--muted); text-align: center; padding: 22px 10px; font-size: 13px; }

/* ------------------------------------------------------------------ modal */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 7, 18, .72); backdrop-filter: blur(3px); }
.modal-box {
  position: relative; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  background: linear-gradient(180deg, #162040, #0d1429);
  border: 1px solid #2c3a68; border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: .7; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }

/* ---------------------------------------------------------------- notices */
.alert { border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.warn { background: rgba(245, 165, 36, .1); border-color: rgba(245, 165, 36, .3); color: #ffd88f; }
.alert.info { background: rgba(79, 124, 255, .1); border-color: rgba(79, 124, 255, .3); color: #b9c9ff; }
.alert.danger { background: rgba(255, 95, 109, .1); border-color: rgba(255, 95, 109, .3); color: #ffb3b9; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 9px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-size: 13px; }

/* --------------------------------------------------------------- campaign */
.camp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.camp-card { background: linear-gradient(180deg, var(--card), var(--bg-2)); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.camp-card .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.camp-card h3 { margin: 0; font-size: 15px; }
.camp-card .meta { color: var(--muted); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.camp-card .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 8px; flex-wrap: wrap; }

.msg-row { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: rgba(8, 13, 27, .45); }
.msg-row .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.msg-preview { white-space: pre-wrap; font-family: inherit; margin: 0; font-size: 12.5px; line-height: 1.5; color: #d7dff3; word-break: break-word; }

.pager { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 200;
  padding: 12px 16px; border-radius: 10px; font-size: 13px; font-weight: 500;
  background: #1a2444; border: 1px solid #33427a; color: var(--text);
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease;
  max-width: 380px; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: rgba(46, 204, 143, .5); }
.toast.err { border-color: rgba(255, 95, 109, .55); }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: linear-gradient(180deg, var(--card), var(--bg-2)); border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.login-card .logo { width: 52px; height: 52px; margin-bottom: 16px; }
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card p { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

.worker-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 4px rgba(255,95,109,.12); }
.dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(46,204,143,.14); }

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

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  /* Mobil: navigatsiya pastdagi tab-bar bo'ladi, tepada hech narsa qolmaydi. */
  .app { flex-direction: column; }

  .sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; height: auto;
    flex: none;
    z-index: 60;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 1px solid var(--border);
    background: rgba(10, 16, 34, 0.96);
    backdrop-filter: blur(16px);
  }
  .brand, .sidebar-foot { display: none; }

  .nav {
    flex-direction: row;
    gap: 2px;
    overflow: visible;
    padding: 0;
  }
  .nav a {
    flex: 1 1 0;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
    padding: 7px 2px 6px;
    border-radius: 10px;
    font-size: 9.5px;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .nav a .ico { width: auto; font-size: 17px; line-height: 1; }
  .nav a.active { border: none; background: rgba(79, 124, 255, .18); color: #fff; }

  .main { padding: 14px 13px 96px; }
  .topbar { margin-bottom: 16px; }
  .topbar h1 { font-size: 20px; }

  .logout-mobile { display: inline-flex; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row, .row-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 3px 0; }
  .kv dd { margin-bottom: 8px; }
}

/* Mobil "chiqish" tugmasi (sidebar yashiringani uchun topbar ichida) */
.logout-mobile {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 16px;
  flex: none;
}
.logout-mobile:hover { color: var(--red); border-color: rgba(255,95,109,.45); }

/* ------------------------------------------- Telegram Mini App (fullscreen) */
html.tg-app,
html.tg-app body { background: var(--bg); }

html.tg-fullscreen body {
  background: radial-gradient(1200px 800px at 10% -10%, #16234a 0%, var(--bg) 55%);
}

@media (max-width: 760px) {
  /* To'liq ekranda Telegram'ning yopish "✕" va "⋯" tugmalari ustidan
     tushmasligi uchun tepada bo'sh joy qoldiramiz. */
  html.tg-fullscreen body {
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--tg-top-gap, 54px));
    padding-bottom: 0;
  }
  html.tg-fullscreen .app,
  html.tg-fullscreen .login-wrap {
    min-height: calc(100dvh - env(safe-area-inset-top, 0px) - var(--tg-top-gap, 54px));
  }
  html.tg-fullscreen .login-wrap { padding: 10px 16px; }
}

/* --------------------------------------------------- chips / bo'limlar (sect) */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.chips.tight { margin-bottom: 0; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(19, 27, 51, .9); border: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }
.chip.ok { color: var(--green); border-color: rgba(46, 204, 143, .35); }
.chip.warn { color: var(--orange); border-color: rgba(245, 165, 36, .35); }
.chip.danger { color: var(--red); border-color: rgba(255, 95, 109, .35); }
.chip .dot { width: 7px; height: 7px; box-shadow: none; }

.sect {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  margin-bottom: 12px;
  overflow: hidden;
}
.sect > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px;
  font-weight: 600; font-size: 14px;
  user-select: none;
}
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary::after {
  content: "▾"; margin-left: auto; color: var(--muted); font-size: 11px;
  transition: transform .18s ease;
}
.sect[open] > summary::after { transform: rotate(180deg); }
.sect > summary .badge { margin-left: 2px; }
.sect > .sect-body { padding: 0 16px 16px; }
.sect > .sect-body > .card-head { margin-top: 0; }

.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icon-btn { padding: 8px 11px; line-height: 1; }

.camp-card { border-left: 3px solid var(--border); }
.camp-card.running { border-left-color: var(--green); }
.camp-card.paused { border-left-color: var(--orange); }
.camp-card.error { border-left-color: var(--red); }
.camp-card.draft { border-left-color: var(--muted); }
.camp-times { display: flex; flex-direction: column; gap: 2px; }

.hide-xs { }

@media (max-width: 760px) {
  .chips { gap: 6px; }
  .chip { font-size: 11px; padding: 5px 9px; }
  .sect > summary { padding: 13px 14px; font-size: 13.5px; }
  .sect > .sect-body { padding: 0 14px 14px; }
  .camp-card { padding: 14px; }
  .camp-card .actions { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }
  .camp-card .actions .btn { justify-content: center; }
  .page-actions { width: 100%; }
  .page-actions .btn:not(.icon-btn) { flex: 1; justify-content: center; }
  .hide-xs { display: none; }
}

/* ------------------------------------------------- kampaniya yaratish oynasi */
.modal-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 14px 2px;
  margin-bottom: 14px;
  background: rgba(8, 13, 27, .35);
}
.modal-group-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--text);
  margin-bottom: 12px; letter-spacing: .2px;
}
.step {
  display: inline-grid; place-items: center;
  width: 19px; height: 19px; border-radius: 6px;
  background: rgba(79, 124, 255, .18);
  border: 1px solid rgba(79, 124, 255, .42);
  color: #a9c0ff; font-size: 11px; font-weight: 700;
  flex: none;
}
.field .hint { line-height: 1.45; }
.range-pair { display: flex; align-items: center; gap: 8px; }
.range-pair input { width: 84px; text-align: center; }
.range-pair span { color: var(--muted); font-size: 12px; white-space: nowrap; }

.summary {
  border: 1px solid rgba(79, 124, 255, .32);
  background: rgba(79, 124, 255, .09);
  border-radius: 12px;
  padding: 13px 15px;
  font-size: 12.5px;
  line-height: 1.6;
}
.summary-title { font-weight: 600; margin-bottom: 6px; color: #c5d4ff; }
.summary ul { margin: 0; padding-left: 17px; color: var(--muted); }
.summary li { margin-bottom: 2px; }
.summary b { color: var(--text); font-weight: 600; }
.summary-note { margin-top: 8px; color: var(--muted); font-size: 11.5px; opacity: .85; }

@media (max-width: 760px) {
  .modal { padding: 10px; align-items: flex-end; }
  .modal-box { max-height: 92dvh; border-radius: 16px 16px 12px 12px; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .modal-foot .btn { flex: 1; justify-content: center; }
  .modal-group { padding: 12px 12px 2px; }
  .range-pair input { width: 74px; }
}

/* --------------------------------------------------- ko'p matn yuklash bloki */
.import-box {
  border: 1px dashed rgba(79, 124, 255, .45);
  background: rgba(79, 124, 255, .06);
  border-radius: 12px;
  padding: 14px;
  margin-top: 14px;
}
.import-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 6px; font-size: 13px;
}
.import-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.import-row input[type="file"] { flex: 1 1 190px; min-width: 0; padding: 8px 10px; }
.import-row .btn { flex: none; }
.import-paste { margin-top: 12px; }
.import-paste > summary {
  cursor: pointer; list-style: none; color: var(--accent-2);
  font-size: 12.5px; padding: 4px 0;
}
.import-paste > summary::-webkit-details-marker { display: none; }
.import-paste > summary:hover { color: #9db6ff; }
.import-paste textarea { margin: 8px 0; font-size: 12.5px; }
.import-paste .import-row { justify-content: space-between; }

@media (max-width: 760px) {
  .import-row { flex-direction: column; align-items: stretch; }
  .import-row .btn { width: 100%; }
  .import-paste .import-row { flex-direction: column-reverse; }
}

/* ----------------------------------------------------- fon vazifasi paneli */
.job-panel {
  border: 1px solid rgba(79, 124, 255, .38);
  background: linear-gradient(180deg, rgba(79, 124, 255, .14), rgba(79, 124, 255, .05));
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.job-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.job-percent { font-weight: 700; color: #a9c0ff; }
.progress { height: 7px; border-radius: 99px; background: rgba(8, 13, 27, .75); overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #4f7cff, #8b5cf6); transition: width .4s ease; }
.job-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 7px; font-size: 12px; color: var(--muted); }
