/* ============================================================
   MG4O Mini App — стили
   Внутри Telegram используется тема клиента, вне Telegram —
   светлая/тёмная тема по системным настройкам.
   ============================================================ */

:root {
    --brand: #8B5CF6;
    --brand-strong: #7C3AED;
    --brand-soft: rgba(139, 92, 246, .12);

    --bg: #ffffff;
    --bg-soft: #f4f4f7;
    --text: #101114;
    --hint: #8b8f98;
    --line: rgba(128, 128, 128, .22);

    --radius: 18px;
    --radius-sm: 12px;
    --pad: 16px;

    --shadow: 0 1px 2px rgba(16, 17, 20, .06), 0 10px 28px -16px rgba(16, 17, 20, .35);

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #191a1f;
        --bg-soft: #232429;
        --text: #f1f2f4;
        --hint: #9aa0aa;
        --line: rgba(255, 255, 255, .12);
        --brand-soft: rgba(139, 92, 246, .18);
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px -18px rgba(0, 0, 0, .8);
    }
}

/* Внутри Telegram доверяем палитре клиента */
body.tg {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --bg-soft: var(--tg-theme-secondary-bg-color, #f4f4f7);
    --text: var(--tg-theme-text-color, #101114);
    --hint: var(--tg-theme-hint-color, #8b8f98);
    --line: var(--tg-theme-section-separator-color, rgba(128, 128, 128, .22));
    --brand: var(--tg-theme-button-color, #8B5CF6);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
}

body {
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

button, input, textarea { font: inherit; color: inherit; }

.app {
    max-width: 640px;
    margin: 0 auto;
    padding: calc(var(--pad) + env(safe-area-inset-top)) var(--pad) calc(28px + env(safe-area-inset-bottom));
    min-height: 100vh;
}

/* ---------------- Загрузка ---------------- */

.boot-loader {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    padding: 64px 0;
    color: var(--hint);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Шапка ---------------- */

.hero {
    text-align: center;
    padding: 12px 0 24px;
}

.brand-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    border-radius: 20px;
    background: linear-gradient(140deg, var(--brand), var(--brand-strong));
    display: grid;
    place-items: center;
    box-shadow: 0 14px 30px -14px rgba(124, 58, 237, .75);
}

.brand-logo svg { width: 34px; height: 34px; display: block; }

.hero h1 {
    margin: 0 0 6px;
    font-size: 26px;
    letter-spacing: -.4px;
}

.tagline {
    margin: 0;
    color: var(--hint);
    font-size: 15px;
}

.greeting {
    margin: 16px 0 0;
    font-size: 17px;
    font-weight: 600;
}

/* ---------------- Плашка «вне Telegram» ---------------- */

.notice {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-soft);
}

.notice-title { font-weight: 600; margin: 0 0 4px; font-size: 15px; }
.notice-text { margin: 0; color: var(--hint); font-size: 14px; }

/* ---------------- Плитки на главной ---------------- */

.tiles { display: grid; gap: 12px; }

.tile {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}

.tile:active { transform: scale(.985); }
.tile:hover { border-color: var(--brand); }

.tile--accent {
    border-color: transparent;
    background: linear-gradient(140deg, var(--brand), var(--brand-strong));
    color: #fff;
}

.tile-ic {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand);
}

.tile--accent .tile-ic { background: rgba(255, 255, 255, .18); color: #fff; }
.tile-ic svg { width: 22px; height: 22px; }

.tile-body { flex: 1 1 auto; min-width: 0; }
.tile-title { display: block; font-weight: 600; font-size: 16px; }
.tile-sub { display: block; color: var(--hint); font-size: 13.5px; margin-top: 2px; }
.tile--accent .tile-sub { color: rgba(255, 255, 255, .85); }

.tile-arrow { flex: 0 0 auto; color: var(--hint); }
.tile--accent .tile-arrow { color: rgba(255, 255, 255, .9); }

/* ---------------- Список ---------------- */

.section-head { padding: 4px 0 16px; }
.section-title { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.section-sub { margin: 6px 0 0; color: var(--hint); font-size: 14.5px; }

.cards { display: grid; gap: 12px; }

.card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 15px 16px;
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}

.card:active { transform: scale(.985); }
.card:hover { border-color: var(--brand); }

.card-ic {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand);
}

.card-ic svg { width: 21px; height: 21px; }

.card-main { flex: 1 1 auto; min-width: 0; }
.card-title { display: block; font-weight: 600; font-size: 15.5px; }
.card-sub { display: block; color: var(--hint); font-size: 13px; margin-top: 3px; }

.card-price { flex: 0 0 auto; text-align: right; white-space: nowrap; }
.price-new { font-weight: 700; font-size: 15.5px; }
.price-old {
    display: block;
    color: var(--hint);
    font-size: 12.5px;
    text-decoration: line-through;
}

.badge {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 11px;
    font-weight: 600;
}

/* ---------------- Детали позиции ---------------- */

.detail { padding: 4px 0 0; }
.detail-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 18px; }

.detail-ic {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand);
}

.detail-ic svg { width: 28px; height: 28px; }
.detail-title { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.detail-summary { margin: 6px 0 0; color: var(--hint); font-size: 14.5px; }

.price-box {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 16px;
    margin-bottom: 18px;
    border-radius: var(--radius);
    background: var(--bg-soft);
}

.price-box .price-new { font-size: 22px; }
.price-box .price-old { font-size: 14px; text-decoration: line-through; }

.block { margin-bottom: 20px; }
.block-title {
    margin: 0 0 10px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--hint);
}

.detail-desc { margin: 0; font-size: 15px; }

.features { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.features li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.features .tick { flex: 0 0 18px; margin-top: 2px; color: var(--brand); }
.features .tick svg { width: 18px; height: 18px; display: block; }

.delivery-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    font-size: 15px;
}

.delivery-row b { font-weight: 600; }

/* ---------------- Форма ---------------- */

.summary {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    margin-bottom: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-soft);
}

.summary-name { font-weight: 600; font-size: 15px; }
.summary-price { font-weight: 700; white-space: nowrap; }

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 8px; }

.field-label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--hint);
}

.field-label em { font-style: normal; text-transform: none; letter-spacing: 0; opacity: .8; }

.input, .textarea {
    width: 100%;
    padding: 13px 14px;
    background: var(--bg-soft);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .12s ease, background .12s ease;
}

.input:focus, .textarea:focus { border-color: var(--brand); background: var(--bg); }
.textarea { min-height: 104px; resize: vertical; line-height: 1.5; }

.segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.seg-btn {
    padding: 11px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg);
    cursor: pointer;
    font-size: 14.5px;
    transition: all .12s ease;
}

.seg-btn.is-active {
    border-color: transparent;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
}

.form-error {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, .12);
    color: #ef4444;
    font-size: 14.5px;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 15px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--bg-soft);
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: transform .12s ease, opacity .12s ease;
}

.btn:active { transform: scale(.985); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: default; transform: none; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }

.btn-row { display: grid; gap: 10px; margin-top: 4px; }

/* ---------------- Успех ---------------- */

.success { text-align: center; padding: 28px 0 8px; }

.success-ic {
    width: 78px;
    height: 78px;
    margin: 0 auto 20px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--brand-soft);
    color: var(--brand);
}

.success-ic svg { width: 40px; height: 40px; }
.success-title { margin: 0 0 8px; font-size: 23px; }
.success-text { margin: 0 auto 24px; max-width: 340px; color: var(--hint); font-size: 15px; }

/* ---------------- Мои заявки ---------------- */

.orders { display: grid; gap: 12px; }

.order {
    padding: 15px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}

.order-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.order-id { font-size: 13px; color: var(--hint); }
.order-title { margin: 8px 0 2px; font-weight: 600; font-size: 15.5px; }
.order-price { margin: 0; color: var(--hint); font-size: 14px; }
.order-comment {
    margin: 10px 0 0;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    color: var(--hint);
    font-size: 14px;
    white-space: pre-wrap;
}
.order-foot { margin-top: 12px; }

.status {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-new { background: var(--brand-soft); color: var(--brand); }
.status-work { background: rgba(245, 158, 11, .16); color: #d97706; }
.status-done { background: rgba(16, 185, 129, .16); color: #059669; }
.status-canceled { background: rgba(107, 114, 128, .16); color: var(--hint); }

.empty { text-align: center; padding: 40px 0; color: var(--hint); }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* ---------------- Ссылки в подвале ---------------- */

.footer-links {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.link {
    color: var(--brand);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

.link:hover { text-decoration: underline; }

.link-btn {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}
