:root {
  --tg-blue: #3390ec;
  --tg-blue-dark: #2b7fd4;
  --bg: #ffffff;
  --side-bg: #ffffff;
  --hover: #f4f4f5;
  --active: #3390ec;
  --text: #000000;
  --muted: #707579;
  --border: #dadce0;
  --bubble-in: #ffffff;
  --bubble-out: #e3fee0;
  --chat-bg: #c9d9a4;
  --green: #4fae4e;
  --red: #e53935;
  --orange: #f29b0f;
  --shadow: 0 1px 2px rgba(16, 35, 47, .15);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121; --side-bg: #212121; --hover: #2c2c2c; --text: #ffffff; --muted: #aaaaaa;
    --border: #303030; --bubble-in: #212121; --bubble-out: #766ac8; --chat-bg: #0f0f0f;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; color: var(--text); background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Auth ---------- */
.screen { height: 100%; }
#auth, #pending {
  display: flex; align-items: flex-start; justify-content: center; overflow-y: auto;
  background: linear-gradient(135deg, #6fb1fc 0%, #4364f7 50%, #0052d4 100%);
  padding: 32px 16px;
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--bg); border-radius: 18px; padding: 28px 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25); margin: auto 0;
}
.auth-card.center { text-align: center; }
.auth-card h1 { margin: 8px 0 4px; text-align: center; font-size: 24px; }
.auth-card > .muted { text-align: center; margin: 0 0 20px; }
.logo {
  width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; background: var(--tg-blue);
  display: grid; place-items: center; font-size: 42px;
}
.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { transform: scale(1.07); opacity: .85; } }
.tabs { display: flex; background: var(--hover); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: none; padding: 9px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--bg); color: var(--tg-blue); box-shadow: var(--shadow); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form input:not([type=radio]):not([type=file]):not([type=checkbox]):not([type=hidden]), .form textarea, .form select {
  border: 1.5px solid var(--border); border-radius: 10px; padding: 11px 12px; background: var(--bg);
  outline: none; font-size: 15px; resize: vertical; width: 100%;
}
.form input:focus, .form textarea:focus, .form select:focus { border-color: var(--tg-blue); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label.showpw { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; margin-top: -4px; font-weight: 400; justify-content: flex-start; }
.form label.showpw input { width: 16px; height: 16px; margin: 0; }
.error { color: var(--red); font-size: 13px; min-height: 0; }
.error:empty { display: none; }

.upload { position: relative; border: 2px dashed var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; }
.upload:hover { border-color: var(--tg-blue); }
.upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2; }
.upload-inner { padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--muted); font-weight: 400; }
.upload-inner img { max-width: 100%; max-height: 200px; border-radius: 8px; }
.upload-icon { font-size: 30px; }

.btn { border: 0; border-radius: 10px; padding: 12px 18px; cursor: pointer; font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--tg-blue); color: #fff; }
.btn.primary:hover { background: var(--tg-blue-dark); }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--tg-blue); }
.btn.ghost:hover { background: var(--hover); }
.btn.green { background: var(--green); color: #fff; }
.btn.red { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.info-box { background: var(--hover); border-radius: 12px; padding: 12px; text-align: left; margin: 16px 0; font-size: 14px; line-height: 1.6; }
.info-box b { font-weight: 600; }
#pending .form { text-align: left; margin-bottom: 8px; }

/* ---------- Main layout ---------- */
#main { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 360px; min-width: 280px; border-right: 1px solid var(--border); background: var(--side-bg);
  display: flex; flex-direction: column; position: relative;
}
.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.search {
  flex: 1; border: 0; background: var(--hover); border-radius: 22px; padding: 10px 16px; outline: none;
}
.search:focus { box-shadow: 0 0 0 2px var(--tg-blue) inset; background: var(--bg); }
.icon-btn {
  width: 40px; height: 40px; border: 0; background: none; border-radius: 50%; cursor: pointer;
  font-size: 20px; color: var(--muted); display: grid; place-items: center; flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); }
.menu {
  position: absolute; top: 54px; left: 10px; z-index: 20; background: var(--bg); border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2); min-width: 250px; padding: 6px 0; overflow: hidden;
}
.menu-me { padding: 10px 16px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.menu-me b { display: block; color: var(--text); font-size: 15px; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 16px; cursor: pointer; }
.menu-item:hover { background: var(--hover); }

.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.chat-item {
  display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; cursor: pointer;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); color: #fff; }
.chat-item.active .muted, .chat-item.active .time, .chat-item.active .preview { color: rgba(255, 255, 255, .85); }
.avatar {
  width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 600; font-size: 19px; flex-shrink: 0;
}
.chat-head .avatar { width: 42px; height: 42px; font-size: 16px; }
.avatar.sum { background: linear-gradient(#ffb74d, #f57c00); font-size: 20px; }
.ci-body { flex: 1; min-width: 0; }
.ci-top, .ci-bot { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.ci-top .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; margin-top: 3px; }
.badge {
  background: #c4c9cc; color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 7px;
  font-size: 12px; font-weight: 600; display: grid; place-items: center; flex-shrink: 0;
}
.badge.blue { background: var(--tg-blue); }
.badge.orange { background: var(--orange); }
.chat-item.active .badge { background: #fff; color: var(--tg-blue); }
.bal-tag { font-size: 12px; font-weight: 600; margin-top: 2px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.chat-item.active .pos, .chat-item.active .neg { color: #fff; }
.list-empty { text-align: center; color: var(--muted); padding: 30px 16px; font-size: 14px; }
.pinned { background: var(--hover); }

/* ---------- Chat ---------- */
.chat {
  flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative;
  background-color: var(--chat-bg);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, .25) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, .2) 0 2px, transparent 3px),
    linear-gradient(135deg, #d4e5a5 0%, #9fc7a0 50%, #8bb9b4 100%);
  background-size: 60px 60px, 80px 80px, cover;
}
@media (prefers-color-scheme: dark) {
  .chat { background-image: linear-gradient(135deg, #1b2a1f, #10161d); }
}
.empty-chat { flex: 1; display: grid; place-items: center; }
.bubble-hint { background: rgba(0, 0, 0, .25); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 14px; font-weight: 500; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--bg);
  border-bottom: 1px solid var(--border); min-height: 58px;
}
.chat-title { min-width: 0; }
.chat-title .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title .sub.typing { color: var(--tg-blue); }
.back { display: none; }
.balance-bar {
  background: var(--bg); padding: 8px 16px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  border-bottom: 1px solid var(--border); font-size: 14px;
}
.bal-chip { padding: 4px 10px; border-radius: 14px; font-weight: 600; font-size: 13px; }
.bal-chip.pos { background: rgba(79, 174, 78, .14); }
.bal-chip.neg { background: rgba(229, 57, 53, .12); }
.bal-chip.zero { background: var(--hover); color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 12px 6% 8px; display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; background: rgba(0, 0, 0, .22); color: #fff; padding: 3px 11px; border-radius: 14px; font-size: 13px; font-weight: 500; margin: 8px 0; }
.msg { max-width: min(480px, 85%); display: flex; }
.msg.out { align-self: flex-end; }
.msg.in { align-self: flex-start; }
.bubble {
  background: var(--bubble-in); border-radius: 14px; padding: 6px 10px 6px 11px; box-shadow: var(--shadow);
  position: relative; word-wrap: break-word; white-space: pre-wrap; line-height: 1.35; min-width: 60px;
}
.msg.out .bubble { background: var(--bubble-out); border-bottom-right-radius: 4px; }
.msg.in .bubble { border-bottom-left-radius: 4px; }
.meta { float: right; font-size: 11.5px; color: var(--muted); margin: 6px 0 -4px 10px; white-space: nowrap; }
.msg.out .meta { color: #5fa65f; }
@media (prefers-color-scheme: dark) { .msg.out .meta { color: #d6d2f5; } }

.card { white-space: normal; min-width: 250px; }
.card-head { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.card-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; padding: 2px 0; }
.card-row span:first-child { color: var(--muted); }
.card-row span:last-child { text-align: right; font-weight: 500; }
.card-amount { font-size: 20px; font-weight: 700; margin: 6px 0 2px; }
.card-effect { font-size: 12.5px; color: var(--muted); }
.status { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-top: 6px; }
.status.pending { background: rgba(242, 155, 15, .16); color: #c07a00; }
.status.confirmed { background: rgba(79, 174, 78, .16); color: #2e8b2e; }
.status.rejected, .status.cancelled { background: rgba(229, 57, 53, .12); color: var(--red); }
.card-actions { display: flex; gap: 6px; margin-top: 8px; }
.card-actions .btn { flex: 1; }
.card.void { opacity: .7; }
.card.void .card-amount { text-decoration: line-through; }

.composer {
  display: flex; align-items: flex-end; gap: 4px; padding: 8px 6% 12px; background: transparent;
}
.composer textarea {
  flex: 1; border: 0; outline: none; resize: none; padding: 12px 14px; border-radius: 14px; background: var(--bg);
  box-shadow: var(--shadow); max-height: 140px; line-height: 1.35;
}
.composer .icon-btn { background: var(--bg); box-shadow: var(--shadow); width: 46px; height: 46px; }
.send {
  width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--tg-blue); color: #fff; font-size: 20px;
  cursor: pointer; flex-shrink: 0; box-shadow: var(--shadow);
}
.send:hover { background: var(--tg-blue-dark); }

/* ---------- Summary ---------- */
.summary { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 12px; }
.sum-card { background: var(--bg); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.sum-card h4 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sum-big { font-size: 18px; font-weight: 700; line-height: 1.5; }
.sum-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); cursor: pointer; }
.sum-row:first-of-type { border-top: 0; }
.sum-row .avatar { width: 38px; height: 38px; font-size: 14px; }
.sum-row .who { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* ---------- Avtomatik hisob ---------- */
.parse-result { background: rgba(79, 174, 78, .12); color: #2e7d32; border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.parse-result.warn { background: rgba(242, 155, 15, .14); color: #a86a00; }
.form .autofilled { border-color: var(--green) !important; background: rgba(79, 174, 78, .06) !important; }
.form .inline { display: flex; gap: 6px; }
.form .inline input { flex: 1; min-width: 0; }
.form .inline select { width: auto !important; flex-shrink: 0; padding-left: 8px !important; padding-right: 8px !important; }
.calc-box { background: var(--hover); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.calc-box:empty { display: none; }
.calc-row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.calc-row.total { border-top: 1px dashed var(--border); margin-top: 4px; padding-top: 6px; font-weight: 700; }
.card-calc { background: rgba(0, 0, 0, .04); border-radius: 8px; padding: 6px 8px; margin-top: 6px; font-size: 12.5px; }
.card-calc .calc-row.total { font-size: 13px; }
details.raw { margin-top: 6px; font-size: 12.5px; }
details.raw summary { cursor: pointer; color: var(--tg-blue); }
details.raw pre { white-space: pre-wrap; word-break: break-word; background: rgba(0, 0, 0, .04); padding: 6px 8px; border-radius: 8px; margin: 4px 0 0; font-size: 11.5px; max-height: 220px; overflow: auto; }

/* ---------- Pasport ---------- */
.pass-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pass-grid input.bad { border-color: var(--orange) !important; }
.pass-grid input.good { border-color: var(--green) !important; }
.ocr-status { font-size: 13px; padding: 8px 12px; border-radius: 10px; background: var(--hover); }
.ocr-status.ok { background: rgba(79, 174, 78, .12); color: #2e7d32; }
.ocr-status.warn { background: rgba(242, 155, 15, .14); color: #a86a00; }
.pass-out { background: var(--hover); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.out-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.out-row { display: flex; align-items: center; gap: 6px; }
.out-row code { flex: 1; font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--bg); padding: 8px 10px; border-radius: 8px; word-break: break-all; user-select: all; }
#passPreview img, #payPreview img { max-height: 160px; }
#payDrop .upload-inner { padding: 12px; }
.pass-card { min-width: 280px; display: flex; flex-direction: column; gap: 4px; }
.card .pass-photo, .pass-card .pass-photo { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; cursor: zoom-in; background: var(--hover); margin-bottom: 4px; }
.pass-card .out-row code { font-size: 12px; padding: 6px 8px; background: rgba(0, 0, 0, .05); }
.pass-card .out-row .btn { padding: 4px 8px; }
.chat.drag-over::after { content: '🛂 Pasport rasmini shu yerga tashlang'; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(51, 144, 236, .25); color: #fff; font-size: 20px; font-weight: 600; z-index: 5; border: 3px dashed #fff; }
@media (max-width: 760px) { .pass-grid { grid-template-columns: 1fr; } }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--bg); border-radius: 16px; padding: 20px; width: 100%; max-width: 460px; max-height: 92dvh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--hover); padding: 4px; border-radius: 12px; }
.seg label { cursor: pointer; }
.seg input { display: none; }
.seg span { display: block; text-align: center; padding: 9px 6px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.seg input:checked + span { background: var(--bg); color: var(--tg-blue); box-shadow: var(--shadow); font-weight: 600; }
#imgModal img { max-width: 95vw; max-height: 90vh; border-radius: 10px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, .8); color: #fff;
  padding: 10px 18px; border-radius: 12px; z-index: 100; font-size: 14px; max-width: 90vw;
}

/* ---------- Admin ---------- */
#admin { overflow-y: auto; background: #f1f3f6; }
@media (prefers-color-scheme: dark) { #admin { background: #181818; } }
.admin-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; gap: 10px; }
.admin-head h2 { margin: 0; font-size: 18px; }
.admin-filter { display: flex; gap: 8px; padding: 14px 20px 0; flex-wrap: wrap; }
.chip { border: 1.5px solid var(--border); background: var(--bg); border-radius: 18px; padding: 6px 14px; cursor: pointer; }
.chip.active { background: var(--tg-blue); border-color: var(--tg-blue); color: #fff; }
.admin-list { padding: 14px 20px 40px; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.admin-card { background: var(--bg); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.admin-card img { width: 100%; height: 190px; object-fit: cover; border-radius: 10px; cursor: zoom-in; background: var(--hover); }
.admin-card .kv { font-size: 14px; line-height: 1.5; }
.admin-card .kv span { color: var(--muted); }
.admin-card .actions { display: flex; gap: 8px; }
.admin-card .actions .btn { flex: 1; }

/* ---------- Admin: bo'limlar va yozishmalar ---------- */
#admin { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
#admin .apanel { flex: 1; min-height: 0; overflow-y: auto; }
#admin #ap-chats { overflow: hidden; }
.admin-tabs { display: flex; gap: 4px; background: var(--hover); padding: 4px; border-radius: 12px; }
.atab { border: 0; background: none; padding: 8px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.atab.active { background: var(--bg); color: var(--tg-blue); box-shadow: var(--shadow); }
.achats { display: flex; height: 100%; }
.achat-side { width: 360px; min-width: 280px; border-right: 1px solid var(--border); background: var(--bg); display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }
.achat-side .search { margin: 0 12px; flex: 0 0 auto; }
.achat-side .chat-list { flex: 1; min-height: 0; }
.achat-main { flex: 1; }
.pair-avatars { display: flex; flex-shrink: 0; }
.pair-avatars .avatar { width: 40px; height: 40px; font-size: 14px; border: 2px solid var(--bg); }
.pair-avatars .avatar + .avatar { margin-left: -14px; }
.admin-ro .msg .bubble { max-width: 100%; }
.who-tag { font-size: 12.5px; font-weight: 700; margin-bottom: 3px; }
.search-hit { padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.search-hit:hover { background: var(--hover); }
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table th, .report-table td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.report-table th { color: var(--muted); font-weight: 600; font-size: 12.5px; border-top: 0; }
.report-table td.num { text-align: right; white-space: nowrap; font-weight: 600; }

/* ---------- Mobil ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; min-width: 0; border-right: 0; }
  .chat { position: fixed; inset: 0; transform: translateX(100%); transition: transform .22s ease; z-index: 10; }
  #main.chat-open .chat { transform: none; }
  .back { display: grid; }
  .chat-head { padding: 6px 8px; gap: 8px; }
  .messages, .composer, .summary { padding-left: 8px; padding-right: 8px; }
  .msg { max-width: 90%; }
  .form .row { grid-template-columns: 1fr; }
  .sum-grid { grid-template-columns: 1fr; }
  .admin-list { grid-template-columns: 1fr; padding: 12px; }
  .admin-head { padding: 12px; }
  .admin-head h2 { font-size: 15px; }
  .admin-head { flex-wrap: wrap; }
  .admin-tabs { order: 3; width: 100%; }
  .atab { flex: 1; padding: 8px 6px; font-size: 13px; }
  .achat-side { width: 100%; border-right: 0; }
  .achat-main { position: fixed; inset: 0; transform: translateX(100%); transition: transform .22s ease; z-index: 10; }
  #ap-chats.open .achat-main { transform: none; }
}
