:root {
  --accent: #3390EC;
  --success: #34C759;
  --warn: #FF9500;
  --text: #1C1C1E;
  --muted: #8A8A8E;
  --bg: #EFEFF4;
  --card: #FFFFFF;
  --st-blue-fg: #3390EC; --st-blue-bg: #E7F2FD;
  --st-orange-fg: #FF9500; --st-orange-bg: #FFF1DF;
  --st-green-fg: #34C759; --st-green-bg: #E4F7E9;
  --st-gray-fg: #8A8A8E; --st-gray-bg: #EDEDED;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  width: 100%;
  max-width: 1024px;   /* на ПК заполняем окно; на мобилке — вся ширина */
  margin: 0 auto;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.screen { padding: 16px; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 100vh; gap: 12px; }

/* spinner */
.spinner { width: 36px; height: 36px; border: 3px solid #d9d9de; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* state icons */
.shield { width: 88px; height: 88px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 40px; color: #fff; }
.shield.blue { background: var(--accent); }
.shield.red { background: #FF3B30; }
.state-icon { font-size: 48px; }

h1 { font-size: 30px; font-weight: 800; margin: 8px 0 0; }
h2 { font-size: 22px; font-weight: 700; margin: 4px 0; }

/* login */
.badge-verified { background: var(--st-green-bg); color: var(--success); font-weight: 600; padding: 10px 18px; border-radius: 16px; margin: 8px 0; }
.code-cells { display: flex; gap: 10px; margin: 8px 0; }
.cell { width: 48px; height: 56px; border: 2px solid #E1E1E6; border-radius: 14px; background: #fff; text-align: center; font-size: 24px; font-weight: 700; outline: none; }
.cell:focus { border-color: var(--accent); }
.footnote { font-size: 14px; margin-top: 4px; }
.error-text { color: #FF3B30; font-weight: 600; font-size: 14px; }

/* buttons */
.btn { border: none; border-radius: 14px; padding: 16px; font-size: 17px; font-weight: 700; cursor: pointer; width: 100%; }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-warn { background: var(--st-orange-bg); color: var(--warn); }
.btn-success { background: var(--success); color: #fff; }

.plate { background: var(--card); border-radius: 14px; padding: 14px 18px; width: 100%; max-width: 320px; }
.plate-row { font-weight: 600; }

/* list */
.list-header { padding-bottom: 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.list-header h1 { margin: 4px 0 12px; }
.search { display: flex; align-items: center; gap: 8px; background: #E4E4E9; border-radius: 12px; padding: 0 12px; }
.search-icon { opacity: .5; }
.search input { border: none; background: transparent; padding: 13px 0; flex: 1; font-size: 16px; outline: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; border: none; background: #E4E4E9; color: var(--text); border-radius: 18px; padding: 9px 14px; font-size: 15px; font-weight: 600; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.chip.active { background: var(--accent); color: #fff; }
.chip .cnt { background: rgba(0,0,0,.08); border-radius: 10px; padding: 0 7px; font-size: 13px; }
.chip.active .cnt { background: rgba(255,255,255,.25); }

.list-items { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.app-card { background: var(--card); border-radius: 16px; padding: 16px; cursor: pointer; }
.ac-top { display: flex; justify-content: space-between; align-items: center; }
.ac-title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.ac-email { color: var(--muted); margin: 8px 0 6px; }
.ac-mid { display: flex; justify-content: space-between; align-items: baseline; }
.ac-amount { font-size: 19px; font-weight: 800; }
.ac-time { color: var(--muted); font-size: 14px; }
.ac-reason { color: var(--muted); margin-top: 8px; }

.status-badge { font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 12px; white-space: nowrap; }
.st-blue { background: var(--st-blue-bg); color: var(--st-blue-fg); }
.st-orange { background: var(--st-orange-bg); color: var(--st-orange-fg); }
.st-green { background: var(--st-green-bg); color: var(--st-green-fg); }
.st-gray { background: var(--st-gray-bg); color: var(--st-gray-fg); }

.empty { gap: 10px; padding-top: 80px; }
.empty .state-icon.green { color: var(--success); }

/* detail */
#screen-detail { padding: 0; display: flex; flex-direction: column; height: 100vh; }
.detail-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--card); position: sticky; top: 0; z-index: 5; }
.back { border: none; background: none; color: var(--accent); font-size: 30px; line-height: 1; cursor: pointer; padding: 0 4px; }
.detail-head-text { flex: 1; }
.detail-head-text h2 { margin: 0; }
.detail-body { flex: 1; overflow-y: auto; padding: 16px; }
.section-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-label { color: var(--muted); font-weight: 600; }
.conv-label { display: block; margin: 18px 0 10px; }
.link { border: none; background: none; color: var(--accent); font-weight: 600; font-size: 16px; cursor: pointer; }

.fields.card { background: var(--card); border-radius: 16px; padding: 4px 16px; }
.field { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid #ECECEC; }
.field:last-child { border-bottom: none; }
.field-main { flex: 1; min-width: 0; }
.field-label { color: var(--muted); font-size: 14px; }
.field-value { font-size: 17px; font-weight: 600; word-break: break-word; }
.copy-btn { border: none; background: #F1F1F4; border-radius: 10px; width: 44px; height: 44px; font-size: 18px; cursor: pointer; flex: none; }
.edit-input { width: 100%; border: 2px solid var(--accent); border-radius: 10px; padding: 8px 10px; font-size: 17px; outline: none; margin-top: 2px; }

.conversation { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 12px 14px; border-radius: 16px; font-size: 16px; word-break: break-word; }
.bubble .time { font-size: 11px; opacity: .6; display: block; margin-top: 4px; }
.bubble.in { background: var(--card); align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.out { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble.sys { align-self: center; background: transparent; color: var(--muted); font-size: 13px; max-width: 90%; text-align: center; }
.att { font-style: italic; opacity: .85; }

.composer { background: var(--card); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid #ECECEC; }
.templates { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.templates::-webkit-scrollbar { display: none; }
.tmpl { white-space: nowrap; border: none; background: var(--st-blue-bg); color: var(--accent); border-radius: 16px; padding: 9px 14px; font-size: 15px; font-weight: 600; cursor: pointer; }
.action-row { display: flex; gap: 10px; margin-bottom: 10px; }
.action-row .btn { padding: 14px; }
.send-row { display: flex; gap: 10px; align-items: center; }
.send-row input { flex: 1; border: none; background: #E4E4E9; border-radius: 20px; padding: 13px 16px; font-size: 16px; outline: none; }
.send-btn { border: none; background: var(--accent); color: #fff; width: 46px; height: 46px; border-radius: 50%; font-size: 18px; cursor: pointer; flex: none; }
.send-btn:disabled { opacity: .5; }

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

/* ───────── полировка ───────── */
.app-card { box-shadow: 0 1px 5px rgba(0,0,0,.05); transition: transform .08s ease; }
.app-card:active { transform: scale(.99); }
.chip.active { box-shadow: 0 3px 10px rgba(51,144,236,.32); }
.fields.card { box-shadow: 0 1px 5px rgba(0,0,0,.05); }
.btn { transition: transform .08s ease, opacity .15s; }
.btn:active { transform: scale(.985); }

/* чек оплаты + вложения в переписке */
.receipt-field .field-main { width: 100%; }
.receipt-img { max-width: 100%; max-height: 280px; border-radius: 12px; margin-top: 8px; display: block; cursor: zoom-in; object-fit: contain; background: #f0f0f3; }

/* полноэкранный просмотр фото */
.img-viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.img-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.iv-close { position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px; width: 42px; height: 42px; border-radius: 50%; border: none; background: rgba(255,255,255,.18); color: #fff; font-size: 20px; cursor: pointer; z-index: 101; }

/* кнопка «развернуть на весь экран» (ПК) */
.fs-toggle { position: fixed; top: calc(6px + env(safe-area-inset-top)); right: 12px; width: 36px; height: 36px; border-radius: 50%; border: none; background: rgba(0,0,0,.10); color: var(--text); font-size: 17px; line-height: 1; cursor: pointer; z-index: 90; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.msg-img { max-width: 220px; max-height: 240px; border-radius: 12px; margin-top: 6px; display: block; cursor: zoom-in; object-fit: cover; background: rgba(0,0,0,.05); }
.img-failed { min-width: 120px; min-height: 56px; }
.att-open { border: none; background: rgba(0,0,0,.06); color: inherit; border-radius: 10px; padding: 7px 11px; margin-top: 6px; cursor: pointer; font-size: 14px; font-weight: 600; }
.bubble.out .att-open { background: rgba(255,255,255,.25); color: #fff; }

/* блок + удаление */
.meta-row { display: flex; gap: 10px; padding-bottom: 10px; }
.mini-btn { flex: 1; border: none; border-radius: 12px; padding: 11px; font-size: 14px; font-weight: 600; cursor: pointer; background: #EDEDF0; color: var(--text); }
.mini-btn.danger { color: #FF3B30; }
.mini-btn.active-danger { background: #FFE9E7; color: #FF3B30; }

/* ───────── адаптив для ПК (Telegram Desktop / широкое окно) ───────── */
@media (min-width: 640px) {
  .list-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
  .list-header h1 { font-size: 34px; }
}
@media (min-width: 760px) {
  .detail-body { padding: 20px 24px; }
  .fields.card, .conversation, .section-row, .conv-label { max-width: 760px; margin-left: auto; margin-right: auto; }
  .detail-header, .composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
  .bubble { max-width: 60%; }
}
