/* ============================================================
   Qarz Daftari · Debt Book — веб-версия (desktop-first, светлая тема)
   Двухпанельный макет: список клиентов слева, детали/статистика справа.
   ============================================================ */

:root {
    color-scheme: light;
    --bg: #f1f3f6;
    --bg-grad-1: #ecfdf5;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef1f5;
    --border: #e6e8ec;
    --border-strong: #d6dae0;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --primary: #10b981;
    --primary-600: #059669;
    --primary-700: #047857;
    --primary-soft: #ecfdf5;
    --primary-soft-border: #c7f0dd;
    --danger: #ef4444;
    --danger-600: #dc2626;
    --danger-soft: #fef2f2;
    --danger-soft-border: #fbd5d5;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --info: #3b82f6;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 16px rgba(15, 23, 42, .08);
    --shadow-lg: 0 18px 48px rgba(15, 23, 42, .18);
    --radius: 16px;
    --radius-sm: 12px;
    --radius-lg: 22px;
    --header-h: 62px;
    --left-w: 380px;
    --right-maxw: 900px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
::selection { background: var(--primary); color: #fff; }

.mobile-only { display: none !important; }
.desktop-only { display: inline-flex; }

/* ---------- Spinner ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .7s linear infinite; }
.spinner.sm { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Кнопки
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 42px; padding: 0 16px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 14.5px;
    background: var(--surface-3); color: var(--text);
    transition: transform .08s ease, background .15s ease, box-shadow .15s ease, opacity .15s, border-color .15s;
    white-space: nowrap; user-select: none; border: 1px solid transparent;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px -8px var(--primary); }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-600); }
.btn-soft { background: var(--surface); border-color: var(--border); }
.btn-soft:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-block { width: 100%; }
.btn-lg { height: 50px; font-size: 16px; border-radius: var(--radius); }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn-icon { width: 40px; height: 40px; padding: 0; border-radius: 11px; }
.btn-icon.btn-sm { width: 34px; height: 34px; }
.btn-debt { background: var(--danger-soft); color: var(--danger-600); border-color: var(--danger-soft-border); }
.btn-debt:hover { background: var(--danger); color: #fff; border-color: transparent; }
.btn-pay { background: var(--primary-soft); color: var(--primary-700); border-color: var(--primary-soft-border); }
.btn-pay:hover { background: var(--primary); color: #fff; border-color: transparent; }

/* ============================================================
   Поля ввода
   ============================================================ */
.field { display: block; margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 7px; }
.input, .textarea, .select {
    width: 100%; height: 46px; padding: 0 14px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s; font-size: 15px;
}
.textarea { height: auto; min-height: 84px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.select {
    appearance: none; -webkit-appearance: none; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px;
}
.input-money { font-size: 26px; font-weight: 700; height: 60px; letter-spacing: -.5px; }

.segment { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-3); border-radius: 12px; border: 1px solid var(--border); }
.segment.full { display: flex; }
.segment.full > button { flex: 1; }
.segment > button { height: 38px; padding: 0 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--text-muted); transition: all .15s; white-space: nowrap; }
.segment > button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segment.accent > button.active { background: var(--primary); color: #fff; }

/* ============================================================
   Каркас приложения: header + две панели
   ============================================================ */
.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.header {
    height: var(--header-h); flex: none; z-index: 30;
    display: flex; align-items: center; gap: 14px; padding: 0 20px;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 800; letter-spacing: -.3px; }
.brand .logo { width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-700)); box-shadow: 0 6px 14px -6px var(--primary); }
.brand .logo svg { width: 21px; height: 21px; }
.brand .name { font-size: 16px; }
.brand .name small { display: block; font-size: 11px; font-weight: 600; color: var(--text-faint); letter-spacing: 0; }
.header .spacer { flex: 1; }
.header .shop-select { height: 40px; min-width: 180px; max-width: 240px; }

.app-links { display: flex; gap: 8px; align-items: center; }
.app-badge { display: inline-flex; border-radius: 7px; transition: opacity .15s, transform .1s; }
.app-badge:hover { opacity: .82; }
.app-badge:active { transform: scale(.97); }
.store-badge { height: 36px; width: auto; display: block; }

.tg-link { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 10px; color: var(--text); font-size: 13px; font-weight: 600; transition: background .15s; white-space: nowrap; }
.tg-link:hover { background: var(--surface-3); }
.tg-link svg { width: 18px; height: 18px; color: #229ED9; flex: none; }
.tg-link .tg-role { color: var(--text-faint); font-weight: 600; }

.lang-toggle { display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 3px; border: 1px solid var(--border); }
.lang-toggle button { padding: 5px 10px; border-radius: 7px; font-size: 12px; font-weight: 700; color: var(--text-faint); }
.lang-toggle button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.menu-wrap { position: relative; }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--primary-700)); color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center; }
.dropdown { position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 240px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden; padding: 6px; animation: pop .12s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.dropdown .dd-head { padding: 10px 12px; }
.dropdown .dd-head .nm { font-weight: 700; }
.dropdown .dd-head .sub { font-size: 13px; color: var(--text-muted); }
.dropdown .dd-sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown .dd-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border-radius: 10px; font-weight: 500; font-size: 14px; text-align: left; }
.dropdown .dd-item:hover { background: var(--surface-3); }
.dropdown .dd-item svg { width: 18px; height: 18px; color: var(--text-muted); }
.dropdown .dd-item.danger { color: var(--danger); }
.dropdown .dd-item.danger svg { color: var(--danger); }

.layout { flex: 1; display: flex; min-height: 0; }

/* ---------- Левая панель: список ---------- */
.left-pane { width: var(--left-w); flex: none; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.left-head { flex: none; padding: 16px 16px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 11px; }
.left-top { display: flex; align-items: center; justify-content: space-between; }
.left-top .ttl { font-size: 16px; font-weight: 800; letter-spacing: -.3px; }
.left-top .ttl .cnt { font-size: 13px; font-weight: 600; color: var(--text-faint); margin-left: 6px; }
.left-tools { display: flex; gap: 8px; }
.left-tools .search { flex: 1; }
.left-tools .sort-select { flex: none; width: 44px; padding: 0; }
.left-list { flex: 1; overflow-y: auto; min-height: 0; }

.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-faint); pointer-events: none; }
.search .input { padding-left: 40px; height: 44px; }
.search .clear { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: var(--text-faint); }
.search .clear:hover { background: var(--surface-3); color: var(--text); }

/* компактная иконка-кнопка сортировки с нативным select поверх */
.sort-wrap { position: relative; flex: none; }
.sort-wrap .sort-btn { width: 44px; height: 44px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; color: var(--text-muted); }
.sort-wrap .sort-btn:hover { border-color: var(--border-strong); }
.sort-wrap .sort-btn svg { width: 19px; height: 19px; }
.sort-wrap select { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .cnt { font-size: 11px; opacity: .7; }
.chip-manage { background: var(--surface-3); color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.chip-manage svg { width: 15px; height: 15px; }

/* Управление папками */
.folder-rows { display: flex; flex-direction: column; }
.folder-row { display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-bottom: 1px solid var(--border); }
.folder-row:last-child { border-bottom: none; }
.folder-row .fr-ic { color: var(--text-faint); display: inline-flex; flex: none; }
.folder-row .fr-ic svg { width: 18px; height: 18px; }
.folder-row .fr-name { flex: 1; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-row .fr-cnt { font-size: 12px; font-weight: 700; color: var(--text-faint); background: var(--surface-3); padding: 2px 9px; border-radius: 999px; flex: none; }

/* Выбор папок в форме клиента */
.folder-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.folder-toggle { cursor: pointer; }
.folder-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Настройки */
.modal-card.settings-modal { max-width: 600px; }
.settings-tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--border); flex: none; }
.settings-tab { padding: 13px 14px; font-weight: 600; font-size: 14px; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.settings-tab.active { color: var(--primary-700); border-bottom-color: var(--primary); }
.settings-tab:hover { color: var(--text); }

.shop-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.shop-card-head { display: flex; align-items: center; gap: 12px; }
.shop-card-head .sc-ic { width: 40px; height: 40px; border-radius: 11px; background: var(--surface-3); display: grid; place-items: center; color: var(--text-muted); flex: none; }
.shop-card-head .sc-ic svg { width: 20px; height: 20px; }
.sc-info { flex: 1; min-width: 0; }
.sc-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 1px; }
.sc-section { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.sc-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); margin-bottom: 8px; }
.cashier-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 14px; }
.cashier-row > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.acc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 2px; border-bottom: 1px solid var(--border); }
.acc-row .acc-label { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.acc-row .acc-val { font-weight: 600; }

/* Аналитика: график и мини-списки */
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 26px 0 12px; }
.chart-head .segment { padding: 3px; }
.chart-head .segment > button { height: 30px; padding: 0 12px; font-size: 13px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.chart-svg { width: 100%; height: 150px; display: block; }
.chart-legend { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.chart-legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .lg::before { content: ''; width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-legend .lg-debt::before { background: var(--danger); }
.chart-legend .lg-pay::before { background: var(--primary); }
.chart-legend .chart-max { margin-left: auto; color: var(--text-faint); font-weight: 700; }
.chart-empty { text-align: center; color: var(--text-faint); padding: 46px 0; font-size: 14px; }

.mini-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.mini-row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--border); width: 100%; text-align: left; background: transparent; transition: background .12s; }
.mini-row:last-child { border-bottom: none; }
.mini-row:hover { background: var(--surface-2); }
.mini-av { width: 36px; height: 36px; border-radius: 11px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; }
.mini-meta { flex: 1; min-width: 0; }
.mini-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-sub { font-size: 12px; color: var(--text-faint); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row .amount { font-size: 14px; flex: none; }

/* строки клиентов */
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); transition: background .12s; text-align: left; width: 100%; background: transparent; position: relative; }
.row:hover { background: var(--surface-2); }
.row.active { background: var(--primary-soft); }
.row.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); }
.row .meta { flex: 1; min-width: 0; }
.row .nm { font-weight: 600; font-size: 14.5px; display: flex; align-items: center; gap: 6px; }
.row .nm .tx-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .nm .pin { width: 13px; height: 13px; color: var(--warning); flex: none; }
.row .sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .bal { text-align: right; flex: none; max-width: 46%; }

.avatar { width: 42px; height: 42px; border-radius: 13px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; background-size: cover; background-position: center; }

.amount { font-weight: 800; letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.amount.owe { color: var(--danger); }
.amount.credit { color: var(--primary-600); }
.amount.zero { color: var(--text-faint); }
.amount-sub { font-size: 12px; font-weight: 700; margin-top: 1px; }
.bal-label { font-size: 10.5px; color: var(--text-faint); font-weight: 600; margin-top: 1px; }

.load-more { margin: 14px auto; display: block; }

/* ---------- Правая панель ---------- */
.right-pane { flex: 1; overflow-y: auto; background: var(--bg); min-height: 0; }
.right-inner { max-width: var(--right-maxw); margin: 0 auto; padding: 26px 28px 60px; }
.right-center { height: 100%; display: grid; place-items: center; }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); margin: 26px 2px 12px; }
.overview-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.overview-head h1 { font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.overview-head .muted { color: var(--text-faint); font-size: 14px; }

/* ============================================================
   Карточки статистики
   ============================================================ */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat.wide { grid-column: span 2; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat .lbl { font-size: 12.5px; color: var(--text-muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .lbl svg { width: 15px; height: 15px; }
.stat .val { font-size: 24px; font-weight: 800; margin-top: 9px; letter-spacing: -.5px; line-height: 1.15; }
.stat .val.sub { font-size: 15px; font-weight: 700; color: var(--text-muted); margin-top: 3px; }
.stat.accent { background: linear-gradient(135deg, var(--primary), var(--primary-700)); border-color: transparent; color: #fff; }
.stat.accent .lbl { color: rgba(255, 255, 255, .85); }
.stat.accent .val.sub { color: rgba(255, 255, 255, .85); }
.stat.danger .val { color: var(--danger); }
.stat .pill { position: absolute; top: 14px; right: 14px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--danger-soft); color: var(--danger-600); }

/* ---------- Пустое состояние ---------- */
.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty .ic { width: 64px; height: 64px; border-radius: 20px; background: var(--surface-3); display: grid; place-items: center; margin: 0 auto 16px; }
.empty .ic svg { width: 30px; height: 30px; color: var(--text-faint); }
.empty h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 14px; max-width: 300px; margin: 0 auto 18px; }
.empty.list-empty { padding: 40px 20px; }

/* ============================================================
   Карточка клиента (правая панель)
   ============================================================ */
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.back-btn { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text-muted); padding: 8px 12px 8px 8px; border-radius: 10px; }
.back-btn:hover { background: var(--surface-3); color: var(--text); }
.back-btn svg { width: 19px; height: 19px; }
.head-actions { display: flex; gap: 6px; margin-left: auto; }

.cust-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 26px; box-shadow: var(--shadow-sm); }
.cust-top { display: flex; align-items: center; gap: 18px; }
.cust-top .avatar { width: 72px; height: 72px; border-radius: 22px; font-size: 27px; flex: none; }
.cust-top .ci { min-width: 0; }
.cust-top .cname { font-size: 22px; font-weight: 800; letter-spacing: -.4px; }
.cust-top .cphone { color: var(--text-muted); font-size: 14px; margin-top: 3px; display: inline-flex; align-items: center; gap: 6px; }
.cust-top .cphone svg { width: 14px; height: 14px; }
.cust-card .cnotes { color: var(--text-muted); font-size: 14px; margin-top: 16px; padding: 12px 16px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--border); }

.balances { display: flex; gap: 14px; margin-top: 22px; }
.bal-box { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.bal-box .l { font-size: 12px; color: var(--text-muted); font-weight: 700; }
.bal-box .v { font-size: 24px; font-weight: 800; margin-top: 5px; letter-spacing: -.5px; }
.bal-box .s { font-size: 11.5px; font-weight: 600; margin-top: 2px; color: var(--text-faint); }

.cust-actions { display: flex; gap: 14px; margin-top: 22px; }
.cust-actions .btn { flex: 1; height: 52px; font-size: 15px; }

/* ---------- Транзакции ---------- */
.tx-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.tx { border-bottom: 1px solid var(--border); }
.tx:last-child { border-bottom: none; }
.tx-main { display: flex; align-items: center; gap: 14px; padding: 15px 18px; width: 100%; text-align: left; background: transparent; transition: background .12s; }
.tx-main:hover { background: var(--surface-2); }
.tx .tx-ic { width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center; }
.tx .tx-ic svg { width: 19px; height: 19px; }
.tx-ic.debt { background: var(--danger-soft); color: var(--danger-600); }
.tx-ic.payment { background: var(--primary-soft); color: var(--primary-700); }
.tx .tx-meta { flex: 1; min-width: 0; }
.tx .tx-type { font-weight: 600; font-size: 14.5px; }
.tx .tx-desc { font-size: 13px; color: var(--text-muted); margin-top: 2px; word-break: break-word; }
.tx .tx-date { font-size: 12px; color: var(--text-faint); margin-top: 3px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tx .tx-right { text-align: right; flex: none; }
.tx .tx-amt { font-weight: 800; white-space: nowrap; font-size: 15px; }
.tx-amt.owe { color: var(--danger); }
.tx-amt.credit { color: var(--primary-600); }
.due-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--text-muted); }
.due-badge svg { width: 11px; height: 11px; }
.due-badge.overdue { background: var(--danger-soft); color: var(--danger-600); }
.edit-hint { width: 18px; height: 18px; color: var(--text-faint); opacity: 0; transition: opacity .15s; flex: none; }
.tx-main:hover .edit-hint { opacity: 1; }
.tx-thumbs { display: flex; gap: 6px; padding: 0 18px 12px 72px; flex-wrap: wrap; }
.tx-thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; cursor: pointer; border: 1px solid var(--border); transition: transform .1s; }
.tx-thumb:hover { transform: scale(1.05); }
.tx-more { font-size: 12px; font-weight: 700; color: var(--text-faint); align-self: center; }

/* Аватар с загрузкой */
.avatar-wrap { position: relative; flex: none; }
.avatar-edit { position: relative; overflow: hidden; cursor: pointer; padding: 0; }
.avatar-edit .av-cam { position: absolute; left: 0; right: 0; bottom: 0; height: 40%; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .15s; }
.avatar-edit:hover .av-cam { opacity: 1; }
.avatar-edit .av-cam svg { width: 16px; height: 16px; color: #fff; }
.av-del { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.av-del svg { width: 13px; height: 13px; }

/* Сетка фото */
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-cell { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.photo-cell img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; }
.photo-cell .ph-del { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }
.photo-cell .ph-del svg { width: 12px; height: 12px; }

/* Лайтбокс */
.lightbox { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.88); display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; animation: fade .15s ease; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lightbox .lb-close { position: fixed; top: 18px; right: 18px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; display: grid; place-items: center; }
.lightbox .lb-close svg { width: 22px; height: 22px; }

/* Вкладки карточки клиента */
.cust-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 24px 0 16px; }
.cust-tab { padding: 11px 16px; font-weight: 600; font-size: 14.5px; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.cust-tab.active { color: var(--primary-700); border-bottom-color: var(--primary); }
.cust-tab:hover { color: var(--text); }

/* Заметки */
.notes-list { display: flex; flex-direction: column; gap: 12px; }
.note-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.note-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.note-by { font-size: 12px; color: var(--text-faint); font-weight: 600; }
.note-acts { display: flex; gap: 2px; }
.note-text { margin-top: 8px; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.note-card .photo-grid { margin-top: 10px; }

/* SMS история */
.sms-hist { display: flex; flex-direction: column; gap: 8px; max-height: 220px; overflow-y: auto; }
.sms-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
.sms-meta { font-size: 11.5px; color: var(--text-faint); font-weight: 600; }
.sms-txt { font-size: 13px; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }

/* ============================================================
   Модалки
   ============================================================ */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-card { width: 100%; max-width: 460px; max-height: calc(100vh - 40px); background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; display: flex; flex-direction: column; animation: modal-in .2s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 20px 20px 6px; }
.modal-head h2 { font-size: 19px; font-weight: 800; letter-spacing: -.3px; flex: 1; }
.modal-head .x { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--text-muted); flex: none; }
.modal-head .x:hover { background: var(--surface-3); color: var(--text); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px 20px; display: flex; gap: 10px; }
.modal-foot .btn { flex: 1; }
.confirm-icon { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; margin: 6px auto 14px; background: var(--danger-soft); color: var(--danger); }
.confirm-icon svg { width: 26px; height: 26px; }
.confirm-text { text-align: center; }
.confirm-text h2 { font-size: 18px; margin-bottom: 6px; }
.confirm-text p { color: var(--text-muted); font-size: 14px; }

/* ============================================================
   Тосты
   ============================================================ */
#toast-root { position: fixed; left: 0; right: 0; bottom: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px 24px; pointer-events: none; }
.toast { pointer-events: auto; max-width: 440px; display: flex; align-items: center; gap: 10px; background: var(--text); color: var(--surface); padding: 13px 18px; border-radius: 13px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; animation: toast-in .25s cubic-bezier(.2, .9, .3, 1.1); }
.toast.out { animation: toast-out .2s ease forwards; }
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.success svg { color: var(--primary); }
.toast.error svg { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(16px); } }

/* ============================================================
   Аутентификация
   ============================================================ */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 18px; background-image: radial-gradient(1100px 560px at 50% -10%, var(--bg-grad-1), transparent 70%); }
.auth-card { width: 100%; max-width: 410px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 32px 28px; animation: fade .3s ease; }
.auth-logo { width: 62px; height: 62px; border-radius: 18px; margin: 0 auto 18px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-700)); box-shadow: 0 12px 26px -10px var(--primary); }
.auth-logo svg { width: 33px; height: 33px; }
.auth h1 { text-align: center; font-size: 24px; font-weight: 800; letter-spacing: -.5px; }
.auth .tagline { text-align: center; color: var(--text-muted); font-size: 14px; margin-top: 6px; margin-bottom: 24px; }
.auth .segment.full { margin-bottom: 20px; }
.auth-foot { text-align: center; font-size: 12.5px; color: var(--text-faint); margin-top: 20px; }
.auth-apps { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); text-align: center; }
.auth-apps-label { font-size: 12.5px; font-weight: 600; color: var(--text-faint); margin-bottom: 12px; }
.auth-apps-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.auth-apps .store-badge { height: 40px; }
.code-inputs { display: flex; gap: 10px; justify-content: center; margin: 8px 0 4px; }
.code-inputs input { width: 56px; height: 64px; text-align: center; font-size: 26px; font-weight: 800; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
.code-inputs input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.auth-back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-weight: 600; font-size: 14px; margin-bottom: 16px; cursor: pointer; }
.auth-back svg { width: 18px; height: 18px; }
.sent-to { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }
.sent-to b { color: var(--text); }
.link-btn { color: var(--primary-600); font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.field-err { color: var(--danger); font-size: 13px; margin-top: 8px; text-align: center; font-weight: 500; }
.lang-floating { position: fixed; top: 18px; right: 18px; }

/* ============================================================
   Скелетоны
   ============================================================ */
.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.skel-av { width: 42px; height: 42px; border-radius: 13px; flex: none; }
.skel-line { height: 12px; }

/* ============================================================
   Адаптив: на узких экранах сворачиваем в одну панель
   ============================================================ */
@media (max-width: 920px) {
    .app { height: auto; min-height: 100vh; overflow: visible; }
    .header { position: sticky; top: 0; padding: 0 14px; gap: 10px; }
    .header .shop-select { min-width: 130px; max-width: 160px; }
    .brand .name { font-size: 15px; }
    .app-links { display: none; }
    .tg-link .tg-text { display: none; }
    .tg-link { padding: 7px; }
    .layout { display: block; min-height: 0; }
    .left-pane { width: auto; border-right: none; }
    .left-list { overflow: visible; }
    .right-pane { overflow: visible; background: var(--bg); }
    .right-inner { padding: 18px 16px 80px; }
    .mobile-only { display: inline-flex !important; }
    .desktop-only { display: none !important; }
    body.qd-detail .left-pane { display: none; }
    body.qd-list .right-pane { display: none; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .cust-actions { position: sticky; bottom: 0; }
}

@media (max-width: 560px) {
    .modal { align-items: flex-end; padding: 0; }
    .modal-card { max-width: none; border-radius: 22px 22px 0 0; max-height: 92vh; animation: sheet-in .26s cubic-bezier(.2, .9, .3, 1); }
    @keyframes sheet-in { from { transform: translateY(100%); } }
    .modal-foot { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
    .cust-top { flex-direction: column; text-align: center; gap: 12px; }
    .cust-top .head-actions { margin: 0; }
    .balances { flex-direction: column; }
}
