/* Палитра берётся из темы Telegram; значения после запятой — фолбэк для
   обычного браузера в dev-режиме (тёмная тема Telegram по умолчанию). */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --card: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #7d8b99);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --accent: var(--tg-theme-button-color, #5288c1);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --ok: #4bb34b;
  --warn: #f0a30a;
  --danger: #e5534b;
  --line: rgba(127, 143, 160, .18);
  --radius: 12px;
  --tabbar-h: calc(58px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  padding-bottom: var(--tabbar-h);
  -webkit-tap-highlight-color: transparent;
}

/* --- шапка --- */
#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px 10px;
  background: var(--bg);
}
#title { margin: 0; font-size: 20px; font-weight: 700; }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--card); color: var(--hint); font-size: 17px; cursor: pointer;
}
.icon-btn:active { color: var(--text); }

#view { padding: 0 16px 20px; display: flex; flex-direction: column; gap: 14px; }

/* --- карточки --- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; }
.card--tight { padding: 12px 14px; }
.card--alert { outline: 1px solid var(--danger); }
.card__label { color: var(--hint); font-size: 13px; }
.card__value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.card__note { color: var(--hint); font-size: 12px; }
.card__note--danger { color: var(--danger); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat { background: var(--card); border-radius: var(--radius); padding: 14px; border: 0;
        text-align: left; color: var(--text); font: inherit; cursor: pointer; min-height: 76px; }
.stat__num { font-size: 24px; font-weight: 700; display: block; }
.stat__num--warn { color: var(--warn); }
.stat__num--ok { color: var(--ok); }
.stat__num--danger { color: var(--danger); }
.stat__num--hint { color: var(--hint); }
.stat__label { color: var(--hint); font-size: 12px; }

.rows { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
       padding: 14px 16px; border-bottom: 1px solid var(--line); min-height: 48px; }
.row:last-child { border-bottom: 0; }
.row--tap { cursor: pointer; }
.row__label { color: var(--hint); font-size: 13px; }
.row__value { font-size: 13px; color: var(--text); text-align: right; }
.row__value--link { color: var(--link); }

.section-title { color: var(--hint); font-size: 13px; font-weight: 600;
                 text-transform: uppercase; letter-spacing: .04em; margin: 6px 2px -4px; }

/* --- бейджи --- */
.badge { font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.badge--awaiting  { background: rgba(240,163,10,.16);  color: var(--warn); }
.badge--delivered { background: rgba(75,179,75,.16);   color: var(--ok); }
.badge--failed    { background: rgba(229,83,75,.16);   color: var(--danger); }
.badge--unmapped  { background: rgba(125,139,153,.18); color: var(--hint); }
.badge--rejected  { background: rgba(125,139,153,.18); color: var(--hint); }
.badge--purchasing{ background: rgba(82,136,193,.18);  color: var(--link); }

/* --- кнопки --- */
.btn { display: block; width: 100%; min-height: 46px; border: 0; border-radius: 10px;
       background: var(--card); color: var(--text); font: 600 15px/1 inherit;
       padding: 14px; cursor: pointer; }
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--danger { background: rgba(229,83,75,.14); color: var(--danger); }
.btn--ghost { background: transparent; color: var(--hint); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* --- чипсы --- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; border: 0; border-radius: 999px; padding: 8px 14px; min-height: 36px;
        background: var(--card); color: var(--hint); font: 13px inherit; cursor: pointer; }
.chip--on { background: var(--accent); color: var(--accent-text); }

/* --- список заказов --- */
.item { background: var(--card); border-radius: var(--radius); padding: 14px; border: 0;
        width: 100%; text-align: left; color: var(--text); font: inherit; cursor: pointer;
        display: flex; flex-direction: column; gap: 6px; }
.item__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.item__name { font-size: 14px; font-weight: 600; line-height: 1.3; }
.item__meta { color: var(--hint); font-size: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* --- шкала времени аренды --- */
.bar { height: 6px; border-radius: 3px; background: rgba(127,143,160,.22); overflow: hidden; }
.bar__fill { height: 100%; background: var(--ok); }
.bar__fill--soon { background: var(--danger); }

/* --- чат --- */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; padding: 2px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 14px; font-size: 14px; word-break: break-word; }
.msg--buyer { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.msg--seller { align-self: flex-end; background: var(--accent); color: var(--accent-text);
               border-bottom-right-radius: 4px; }
.msg__time { display: block; font-size: 10px; opacity: .65; margin-top: 3px; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; min-height: 44px; max-height: 120px; padding: 12px;
                     border-radius: 10px; border: 1px solid var(--line);
                     background: var(--card); color: var(--text); font: inherit; }
.composer .btn { width: auto; padding: 12px 18px; }

/* --- формы --- */
input[type="text"], input[type="number"], input[type="search"], textarea, select {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__hint { color: var(--hint); font-size: 12px; }

.switch { position: relative; width: 46px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track { position: absolute; inset: 0; border-radius: 999px;
                 background: rgba(127,143,160,.35); transition: background .15s; pointer-events: none; }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
                        border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch__track { background: var(--ok); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

/* --- график --- */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.chart__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end;
              align-items: center; gap: 4px; height: 100%; }
.chart__bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart__label { color: var(--hint); font-size: 10px; }

/* --- служебные состояния --- */
.empty { text-align: center; color: var(--hint); padding: 44px 20px; }
.empty__icon { font-size: 34px; opacity: .5; display: block; margin-bottom: 10px; }
.skeleton { background: var(--card); border-radius: var(--radius); height: 76px;
            animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .55 } }

/* --- таб-бар --- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
}
.tab { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
       border: 0; background: none; color: var(--hint); font: 10px inherit; cursor: pointer;
       padding: 4px 0; min-height: 44px; }
.tab--on { color: var(--accent); }
.tab__icon { font-size: 17px; line-height: 1; }
.tab__dot { position: absolute; top: 2px; right: 50%; margin-right: -18px;
            width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

/* --- тост --- */
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + 12px); z-index: 20;
         background: var(--card); border-radius: 10px; padding: 12px 14px; font-size: 14px;
         box-shadow: 0 6px 24px rgba(0,0,0,.35); }
#toast.toast--err { color: var(--danger); }
