/* ==========================================================================
   Codi — кабинет в стиле Telegram.
   Палитра по умолчанию — тёмная тема Telegram; если приложение открыто
   внутри Telegram, значения перебиваются themeParams (см. app.js).
   ========================================================================== */

:root {
    --bg:          #17212b;   /* фон экрана          */
    --bg-secondary:#0e1621;   /* фон под списками    */
    --card:        #1e2c3a;   /* карточка / секция   */
    --card-hi:     #24313f;   /* нажатая карточка    */
    --sep:         #101a23;   /* разделитель         */
    --text:        #ffffff;
    --hint:        #7d8b99;
    --link:        #62a0dd;
    --accent:      #2ea6ff;   /* синий Telegram      */
    --accent-text: #ffffff;
    --bubble-in:   #1e2c3a;   /* сообщение заказчика */
    --bubble-out:  #2b5278;   /* наше сообщение      */
    --green:       #4dcb5f;
    --red:         #f55f56;
    --orange:      #f5a623;
    --purple:      #a986ec;

    --radius:      12px;
    --radius-lg:   16px;
    --tabbar-h:    calc(56px + env(safe-area-inset-bottom, 0px));
    --header-h:    52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overscroll-behavior-y: none;
}

body {
    background: var(--bg-secondary);
    color: var(--text);
    font: 15px/1.42 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
          system-ui, Roboto, "Helvetica Neue", sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { -webkit-appearance: none; }

/* ─── Каркас ───────────────────────────────────────────────── */

.app {
    display: flex;
    flex-direction: column;
    min-height: 100%;
    max-width: 620px;
    margin: 0 auto;
    background: var(--bg-secondary);
}

.header {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--sep);
}

.header__title  { font-size: 17px; font-weight: 600; flex: 1; min-width: 0;
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header__sub    { font-size: 12px; color: var(--hint); font-weight: 400; }
.header__back   { background: none; border: 0; padding: 6px 4px 6px 0; color: var(--accent);
                  display: flex; align-items: center; cursor: pointer; flex: none; }
.header__back svg { width: 24px; height: 24px; }
.header__action { background: none; border: 0; color: var(--accent); font-size: 15px;
                  padding: 6px 2px; cursor: pointer; }

.screen {
    flex: 1;
    padding: 12px 12px calc(var(--tabbar-h) + 16px);
    animation: fade .18s ease;
}
.screen--flush { padding-left: 0; padding-right: 0; }
.screen--chat  { padding: 0; display: flex; flex-direction: column; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ─── Нижний таб-бар ───────────────────────────────────────── */

.tabbar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 100%;
    max-width: 620px;
    height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: flex;
    background: var(--bg);
    border-top: 1px solid var(--sep);
    z-index: 40;
}

.tab {
    flex: 1;
    background: none;
    border: 0;
    padding: 6px 2px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--hint);
    font-size: 10px;
    cursor: pointer;
    position: relative;
}
.tab svg { width: 25px; height: 25px; }
.tab--on { color: var(--accent); }

.tab__dot {
    position: absolute;
    top: 4px;
    left: 50%;
    margin-left: 4px;
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--red);
    color: #fff;
    font-size: 11px;
    line-height: 17px;
    font-weight: 600;
    text-align: center;
}

/* ─── Секции-списки (как настройки Telegram) ───────────────── */

.section        { margin: 0 0 18px; }
.section__title { padding: 6px 16px; font-size: 13px; color: var(--hint);
                  text-transform: uppercase; letter-spacing: .3px; }
.section__note  { padding: 8px 16px 0; font-size: 13px; color: var(--hint); }
.list           { background: var(--card); border-radius: var(--radius); overflow: hidden; }

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--sep);
    background: none;
    border-left: 0; border-right: 0; border-top: 0;
    width: 100%;
    text-align: left;
    cursor: pointer;
    color: var(--text);
}
.row:last-child { border-bottom: 0; }
.row:active     { background: var(--card-hi); }
.row--static    { cursor: default; }
.row--static:active { background: none; }

.row__ic    { width: 29px; height: 29px; border-radius: 8px; display: flex;
              align-items: center; justify-content: center; flex: none; }
.row__ic svg{ width: 18px; height: 18px; }
.row__body  { flex: 1; min-width: 0; display: block; }
.row__title { display: block; font-size: 15px;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub   { display: block; font-size: 13px; color: var(--hint); margin-top: 2px;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__val   { display: block; font-size: 15px; color: var(--hint); flex: none; max-width: 45%;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__chev  { color: var(--hint); opacity: .6; flex: none; display: flex; }
.row__chev svg { width: 18px; height: 18px; }

/* ─── Плитки метрик ────────────────────────────────────────── */

.grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric{ background: var(--card); border-radius: var(--radius); padding: 13px 14px; }
.metric__v { font-size: 22px; font-weight: 600; letter-spacing: -.4px; }
.metric__k { font-size: 12px; color: var(--hint); margin-top: 3px; }
.metric__d { font-size: 11px; margin-top: 4px; }

/* ─── Карточка тарифа ──────────────────────────────────────── */

.plan {
    background: linear-gradient(135deg, #2b5278, #1e3a54);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 14px;
}
.plan__top   { display: flex; align-items: center; justify-content: space-between; }
.plan__name  { font-size: 19px; font-weight: 600; }
.plan__badge { font-size: 11px; padding: 3px 9px; border-radius: 20px;
               background: rgba(255,255,255,.16); }
.plan__meta  { font-size: 13px; color: #c5d7e8; margin-top: 6px; }
.plan__bar   { height: 4px; border-radius: 2px; background: rgba(255,255,255,.18);
               margin-top: 12px; overflow: hidden; }
.plan__bar i { display: block; height: 100%; background: #fff; border-radius: 2px; }

/* ─── Кнопки ───────────────────────────────────────────────── */

.btn {
    display: block;
    width: 100%;
    padding: 14px 16px;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
.btn:active   { opacity: .78; }
.btn[disabled]{ opacity: .45; cursor: default; }
.btn--ghost   { background: var(--card); color: var(--text); font-weight: 500; }
.btn--danger  { background: var(--card); color: var(--red); font-weight: 500; }
.btn--sm      { padding: 9px 14px; font-size: 14px; width: auto; }
.btn-row      { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ─── Сегмент-контрол ──────────────────────────────────────── */

.seg {
    display: flex;
    gap: 2px;
    background: var(--card);
    border-radius: 10px;
    padding: 2px;
    margin-bottom: 12px;
}
.seg button {
    flex: 1;
    padding: 8px 6px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--hint);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.seg button.on { background: var(--bubble-out); color: #fff; }

/* ─── Карточка заказа ──────────────────────────────────────── */

.job {
    background: var(--card);
    border-radius: var(--radius);
    padding: 13px 14px;
    margin-bottom: 10px;
}
.job__top   { display: flex; align-items: flex-start; gap: 10px; }
.job__title { flex: 1; font-size: 15px; font-weight: 600; line-height: 1.32; }
.job__meta  { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.job__sum   { font-size: 13px; color: var(--hint); margin-top: 9px; line-height: 1.4; }
.job__risk  { font-size: 13px; color: #e8b4b0; margin-top: 8px; line-height: 1.4;
              background: rgba(245,95,86,.1); border-radius: 8px; padding: 8px 10px; }
.job__acts  { display: flex; gap: 8px; margin-top: 12px; }

.score {
    flex: none;
    min-width: 42px;
    text-align: center;
    padding: 4px 7px;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 700;
    background: rgba(77,203,95,.16);
    color: var(--green);
}
.score--mid { background: rgba(245,166,35,.16); color: var(--orange); }
.score--low { background: rgba(245,95,86,.14);  color: var(--red); }

.chip {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 20px;
    background: rgba(255,255,255,.07);
    color: var(--hint);
}
.chip--accent { background: rgba(46,166,255,.16); color: var(--accent); }
.chip--green  { background: rgba(77,203,95,.16);  color: var(--green); }
.chip--red    { background: rgba(245,95,86,.14);  color: var(--red); }
.chip--orange { background: rgba(245,166,35,.16); color: var(--orange); }
.chip--purple { background: rgba(169,134,236,.18);color: var(--purple); }

/* ─── Список чатов ─────────────────────────────────────────── */

.ava {
    width: 46px; height: 46px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 600; color: #fff;
    flex: none;
}
.ava--sm { width: 34px; height: 34px; font-size: 14px; }

.chatrow__head { display: flex; align-items: baseline; gap: 8px; }
.chatrow__name { flex: 1; font-size: 15px; font-weight: 600;
                 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chatrow__time { font-size: 12px; color: var(--hint); flex: none; }
.chatrow__last { font-size: 13px; color: var(--hint); margin-top: 3px;
                 display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
                 overflow: hidden; }
.chatrow__foot { display: flex; align-items: center; gap: 6px; margin-top: 5px; }

.badge {
    min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 10px; background: var(--accent); color: #fff;
    font-size: 12px; font-weight: 600; line-height: 20px; text-align: center;
    flex: none;
}

/* ─── Экран чата ───────────────────────────────────────────── */

.thread {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px calc(var(--tabbar-h) + 8px);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg { max-width: 84%; border-radius: 14px; padding: 8px 11px 6px; position: relative; }
.msg--in  { align-self: flex-start; background: var(--bubble-in);  border-bottom-left-radius: 5px; }
.msg--out { align-self: flex-end;   background: var(--bubble-out); border-bottom-right-radius: 5px; }
.msg--sys { align-self: center; max-width: 92%; background: rgba(255,255,255,.06);
            border-radius: 10px; text-align: center; color: var(--hint); font-size: 13px;
            padding: 7px 12px; }
.msg__who  { font-size: 12px; font-weight: 600; margin-bottom: 3px; color: var(--accent); }
.msg__who--ai { color: var(--purple); }
.msg__txt  { font-size: 15px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg__time { font-size: 11px; color: rgba(255,255,255,.45); text-align: right; margin-top: 3px; }

.att {
    display: flex; align-items: center; gap: 9px;
    margin-top: 7px; padding: 8px 10px;
    background: rgba(0,0,0,.22); border-radius: 10px;
    color: inherit;
}
.att__ic   { width: 34px; height: 34px; border-radius: 8px; flex: none;
             display: flex; align-items: center; justify-content: center;
             font-size: 10px; font-weight: 700; color: #fff; letter-spacing: .3px; }
.att__name { display: block; font-size: 13px;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att__size { display: block; font-size: 11px; color: var(--hint); margin-top: 1px; }
.att__img  { display: block; max-width: 100%; border-radius: 10px; margin-top: 7px; }

.invoice-card {
    margin-top: 7px; padding: 10px 12px;
    background: rgba(0,0,0,.22); border-radius: 10px;
    border-left: 3px solid var(--green);
}

.composer {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    border-top: 1px solid var(--sep);
}
.composer textarea {
    flex: 1;
    max-height: 110px;
    min-height: 38px;
    padding: 9px 12px;
    border: 0;
    border-radius: 18px;
    background: var(--card);
    color: var(--text);
    resize: none;
    outline: none;
}
.composer__btn {
    width: 38px; height: 38px; flex: none;
    border: 0; border-radius: 50%;
    background: none; color: var(--hint);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}
.composer__btn--send { background: var(--accent); color: #fff; }
.composer__btn svg { width: 22px; height: 22px; }

/* ─── Нижний лист (bottom sheet) ───────────────────────────── */

.sheet-bg {
    position: fixed; inset: 0; z-index: 90;
    background: rgba(0,0,0,.55);
    display: flex; align-items: flex-end; justify-content: center;
    animation: fade .15s ease;
}
.sheet {
    width: 100%; max-width: 620px;
    max-height: 88vh; overflow-y: auto;
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    padding: 8px 0 calc(14px + env(safe-area-inset-bottom, 0px));
    animation: rise .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }

.sheet__grip  { width: 36px; height: 4px; border-radius: 2px; background: var(--hint);
                opacity: .35; margin: 4px auto 10px; }
.sheet__title { font-size: 17px; font-weight: 600; text-align: center; padding: 0 16px 12px; }
.sheet__body  { padding: 0 12px; }

/* ─── Экран оплаты (по макету Telegram) ────────────────────── */

.pay-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: 18px 16px;
    text-align: center;
    margin-bottom: 14px;
}
.pay-card__logo  { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 10px;
                   background: linear-gradient(135deg, #2ea6ff, #2b5278);
                   display: flex; align-items: center; justify-content: center;
                   font-size: 24px; font-weight: 700; }
.pay-card__name  { font-size: 17px; font-weight: 600; }
.pay-card__desc  { font-size: 13px; color: var(--hint); margin-top: 4px; }
.pay-card__price { font-size: 30px; font-weight: 700; letter-spacing: -.6px; margin-top: 12px; }
.pay-card__per   { font-size: 13px; color: var(--hint); margin-top: 2px; }

.agree {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; margin: 14px 0;
    font-size: 13px; color: var(--hint); line-height: 1.4;
    cursor: pointer;
}
.agree input { display: none; }
.agree__box {
    width: 21px; height: 21px; border-radius: 50%; flex: none;
    border: 2px solid var(--hint);
    display: flex; align-items: center; justify-content: center;
    transition: .15s;
}
.agree input:checked + .agree__box { background: var(--accent); border-color: var(--accent); }
.agree input:checked + .agree__box::after {
    content: ""; width: 5px; height: 9px; margin-top: -2px;
    border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

/* ─── Мелочи ───────────────────────────────────────────────── */

.empty      { text-align: center; padding: 44px 24px; color: var(--hint); }
.empty__ic  { font-size: 40px; margin-bottom: 10px; opacity: .5; }
.empty__t   { font-size: 15px; color: var(--text); margin-bottom: 5px; }
.empty__s   { font-size: 13px; line-height: 1.45; }

.spinner {
    width: 22px; height: 22px; margin: 34px auto;
    border: 2px solid rgba(255,255,255,.18);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 14px);
    transform: translateX(-50%);
    z-index: 120;
    max-width: 90%;
    padding: 11px 16px;
    border-radius: 12px;
    background: rgba(20,28,36,.97);
    border: 1px solid var(--sep);
    font-size: 14px;
    animation: fade .18s ease;
}
.toast--err { border-color: rgba(245,95,86,.5); }

.field       { margin-bottom: 12px; }
.field__lab  { font-size: 13px; color: var(--hint); margin: 0 2px 6px; }
.field input, .field textarea, .field select {
    width: 100%;
    padding: 12px 13px;
    border: 0;
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    outline: none;
}
.field textarea { min-height: 92px; resize: vertical; line-height: 1.4; }
.field input:focus, .field textarea:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }

.switch  { width: 46px; height: 27px; border-radius: 14px; background: rgba(255,255,255,.15);
           position: relative; flex: none; transition: background .18s; }
.switch i{ position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
           border-radius: 50%; background: #fff; transition: transform .18s; }
.switch--on   { background: var(--green); }
.switch--on i { transform: translateX(19px); }
