/* ymos-qsr / RestaurantMind — soft-UI дашборд в стиле Sprut Hub.
   Светлая тёпло-серая база + тёмная тема. Иконочные плитки: приглушённые в
   выкл. состоянии, мягко подсвеченные в активном. Mobile-first. */

:root {
    --bg: #e8e8e5;              /* тёпло-серый фон (как Sprut) */
    --surface: #f6f6f4;         /* плитка в покое — светлее фона, плоская */
    --surface-active: #ffffff;  /* активная плитка — белая с тенью */
    --topbar: #f6f6f4;
    --text: #1d1d20;
    --text-soft: #6b6b73;
    --muted: #9a9aa2;
    --border: #dedede;
    --accent: #3b6ef5;          /* активное состояние — спокойный синий */
    --accent-soft: #e7eeff;
    --accent-ico: #2f5fe0;
    --warn: #e8940c;
    --warn-soft: #fdf1dd;
    --danger: #e0483a;
    --danger-soft: #fbe6e3;
    --online: #22b268;
    --icon-chip: #ececea;       /* фон иконки в покое */
    --topbar-h: 58px;
    --bottomnav-h: 62px;
    --radius: 20px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e0e12;
        --surface: #1a1a20;
        --surface-active: #24242d;
        --topbar: #16161b;
        --text: #ececf0;
        --text-soft: #a0a0ab;
        --muted: #6b6b76;
        --border: #2a2a33;
        --accent: #6d8bff;
        --accent-soft: #232b47;
        --accent-ico: #93a8ff;
        --warn: #f0a83a;
        --warn-soft: #33280f;
        --danger: #ef6b5e;
        --danger-soft: #3a1f1c;
        --online: #34c47c;
        --icon-chip: #26262e;
    }
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding-top: var(--topbar-h);
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    margin: 0;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ── Верхняя панель ── */
.app-topbar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
    background: var(--topbar); border-bottom: 1px solid var(--border); z-index: 1030;
}
.app-topbar-inner {
    max-width: 760px; margin: 0 auto; height: 100%;
    display: flex; align-items: center; gap: .5rem; padding: 0 .9rem;
}
.app-brand { display: flex; align-items: center; gap: .4rem; font-weight: 800; color: var(--accent); text-decoration: none; font-size: 1.02rem; min-width: 0; flex-shrink: 1; }
.app-brand i { font-size: 1.3rem; flex-shrink: 0; }
.app-brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-restaurant-select { margin-left: auto; min-width: 0; }
@media (max-width: 400px) { .app-brand span { display: none; } }  /* на узких — только логотип */
.app-restaurant-select .btn {
    background: var(--icon-chip); color: var(--text); border: none; border-radius: 999px;
    font-weight: 700; font-size: .9rem; padding: .35rem .9rem;
    max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.app-user-btn { color: var(--text-soft); font-size: 1.4rem; border: none; background: none; padding: 0 .2rem; }
.dropdown-menu { border-radius: 14px; border-color: var(--border); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 3px; vertical-align: middle; }
.status-dot.online { background: var(--online); }
.status-dot.offline { background: var(--muted); }

/* ── Контент ── */
.app-content { max-width: 760px; margin: 0 auto; padding: .9rem .9rem 0; }
.section-title { font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; margin: .4rem 0 .9rem; }
.section-sub { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 1.4rem 0 .6rem; }

/* ── Плитки-карточки (soft-UI, референс Sprut) ── */
.tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
@media (min-width: 560px) { .tile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.tile {
    background: var(--surface); border-radius: var(--radius); padding: .9rem;
    border: 1px solid transparent; transition: background .2s, box-shadow .2s, border-color .2s;
    position: relative; min-height: 116px; display: flex; flex-direction: column;
    min-width: 0;  /* критично: даёт grid-плитке сжиматься, иначе длинный ID распирает колонку */
    overflow: hidden;
}
.tile.active { background: var(--surface-active); box-shadow: 0 3px 14px rgba(0,0,0,.06); }
.tile.state-warn { background: var(--warn-soft); }
.tile.state-danger { background: var(--danger-soft); }
.tile.state-offline { opacity: .62; }
.tile.lp { user-select: none; -webkit-user-select: none; touch-action: manipulation; cursor: pointer; }
@media (prefers-color-scheme: dark) { .tile.active { box-shadow: 0 3px 14px rgba(0,0,0,.35); } }

/* верхняя строка плитки: иконка + переключатель/статус */
.tile-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: .7rem; }
.tile-ico {
    width: 42px; height: 42px; border-radius: 13px; background: var(--icon-chip);
    display: flex; align-items: center; justify-content: center; font-size: 1.35rem; color: var(--text-soft);
    transition: background .2s, color .2s;
}
.tile.active .tile-ico { background: var(--accent-soft); color: var(--accent-ico); }
.tile.state-warn .tile-ico { background: #fff6e6; color: var(--warn); }
.tile.state-danger .tile-ico { background: #fdeae7; color: var(--danger); }
@media (prefers-color-scheme: dark) {
    .tile.state-warn .tile-ico, .tile.state-danger .tile-ico { background: var(--icon-chip); }
}

.tile-name { font-weight: 700; font-size: .98rem; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere; }
.tile-sub { font-size: .75rem; color: var(--text-soft); margin-top: .1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-tech { font-size: .64rem; color: var(--muted); font-family: ui-monospace, monospace; margin-top: .35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-metric { font-size: 1.7rem; font-weight: 800; letter-spacing: -.03em; margin-top: auto; }
.tile-metric small { font-size: .85rem; font-weight: 600; color: var(--text-soft); }
.tile-foot { margin-top: auto; }

.unverified {
    display: inline-block; margin-left: 4px; width: 15px; height: 15px; line-height: 15px;
    text-align: center; border-radius: 50%; background: var(--warn); color: #fff; font-size: .62rem; font-weight: 800; vertical-align: middle;
}

/* iOS-подобный переключатель */
.sw { width: 46px; height: 28px; border-radius: 999px; background: var(--icon-chip); border: none; position: relative; transition: background .2s; flex-shrink: 0; cursor: pointer; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.sw.on { background: var(--accent); }
.sw.on::after { transform: translateX(18px); }
.sw:disabled { opacity: .5; cursor: not-allowed; }
.sw.pending { background: var(--warn); }
.sw.pending::after { animation: sw-pulse .8s ease-in-out infinite; }
@keyframes sw-pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

.mode-badge { font-size: .72rem; color: var(--text-soft); margin-top: .5rem; display: flex; align-items: center; gap: .3rem; }
.mode-badge.warn { color: var(--warn); }

.status-badge { display: inline-block; font-size: .72rem; font-weight: 600; color: var(--text-soft); padding: .15rem .5rem; background: var(--icon-chip); border-radius: 999px; }

/* Компактный чип offline вместо простыни */
.offline-chip {
    display: inline-flex; align-items: center; gap: .4rem; background: var(--warn-soft); color: var(--warn);
    border-radius: 999px; padding: .35rem .8rem; font-size: .82rem; font-weight: 600; border: none; margin-bottom: .3rem; cursor: pointer;
}
.offline-list { font-size: .8rem; color: var(--text-soft); margin: .3rem 0 .2rem; line-height: 1.5; }

.placeholder-screen { text-align: center; color: var(--muted); padding:3rem 1rem; }
.placeholder-screen i { font-size: 2.6rem; opacity: .5; }

.hint-row { color: var(--muted); font-size: .78rem; text-align: center; margin: 1rem 0 .3rem; }

/* ── Заголовки групп (категории плиток) ── */
.group-head {
    font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
    font-weight: 700; margin: 1.3rem 0 .55rem; display: flex; align-items: center; gap: .5rem;
}
.group-head:first-of-type { margin-top: .6rem; }
.group-count { background: var(--icon-chip); color: var(--text-soft); border-radius: 999px; padding: 0 .5rem; font-size: .7rem; }
.group-head.group-offline { color: var(--warn); }

/* Офлайн-плитка (тап → детали) */
.offline-tile { opacity: .78; }
.offline-tile .status-badge.off { color: var(--warn); background: var(--warn-soft); display: inline-flex; align-items: center; gap: .25rem; }
.offline-tile .tile-sub { color: var(--warn); font-weight: 600; }

/* Баннер офлайна в шторке */
.sheet-offline { background: var(--warn-soft); border-radius: 12px; padding: .7rem .8rem; margin-top: .7rem; }
.sheet-offline .off-line { color: var(--warn); font-size: .92rem; }
.sheet-offline .off-cause { color: var(--text-soft); font-size: .82rem; margin-top: .35rem; }

/* «?»-подсказка у показаний */
.hint-q { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px;
    border-radius: 50%; background: var(--icon-chip); color: var(--text-soft); font-size: .66rem; font-weight: 700;
    cursor: help; vertical-align: middle; margin-left: 3px; }

/* ── Тумблер: кольцо-прогресс удержания 3 сек ── */
@property --hold { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
.sw.holding { --hold: 0%; animation: sw-hold 3s linear forwards; }
@keyframes sw-hold { to { --hold: 100%; } }
.sw.holding::before {
    content: ''; position: absolute; inset: -5px; border-radius: 999px; pointer-events: none;
    background: conic-gradient(var(--accent) var(--hold), transparent 0);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}
.sw.holding::after { background: var(--accent-soft); }

/* ── Чипы диапазона (шторка/график) ── */
.range-chips { display: flex; gap: .3rem; flex-wrap: wrap; }
.range-chips button {
    background: var(--icon-chip); color: var(--text-soft); border: none; border-radius: 999px;
    padding: .28rem .7rem; font-size: .75rem; font-weight: 600; cursor: pointer;
}
.range-chips button.active { background: var(--accent); color: #fff; }

/* ── Нижняя навигация ── */
.app-bottomnav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--topbar); border-top: 1px solid var(--border); display: flex; z-index: 1030;
    max-width: 760px; margin: 0 auto;
}
.app-bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); text-decoration: none; font-size: .66rem; font-weight: 600; }
.app-bottomnav a i { font-size: 1.35rem; }
.app-bottomnav a.active { color: var(--accent); }
.nav-ico-wrap { position: relative; display: inline-flex; }
.nav-badge {
    position: absolute; top: -6px; right: -10px; min-width: 16px; height: 16px; padding: 0 4px;
    background: var(--danger); color: #fff; border-radius: 999px; font-size: .62rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center; line-height: 1;
}

/* ── Центр алертов ── */
.alert-ok {
    display: flex; align-items: center; gap: .5rem; justify-content: center;
    background: var(--surface); border-radius: var(--radius); padding: 1.4rem; color: var(--online);
    font-weight: 600;
}
.alert-ok i { font-size: 1.3rem; }
.alert-card {
    background: var(--surface-active); border-radius: 16px; padding: .9rem; margin-bottom: .7rem;
    border-left: 4px solid var(--muted);
}
.alert-card.sev-danger { border-left-color: var(--danger); }
.alert-card.sev-warn { border-left-color: var(--warn); }
.alert-card.resolved { opacity: .6; border-left-color: var(--online); background: var(--surface); }
.alert-card-top { display: flex; gap: .7rem; align-items: flex-start; }
.alert-ico { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; background: var(--icon-chip); }
.sev-danger .alert-ico { background: var(--danger-soft); color: var(--danger); }
.sev-warn .alert-ico { background: var(--warn-soft); color: var(--warn); }
.resolved .alert-ico { color: var(--online); }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 700; font-size: .95rem; }
.alert-detail { font-size: .82rem; color: var(--text-soft); margin-top: .1rem; }
.alert-loc { font-size: .82rem; margin-top: .4rem; color: var(--text); font-weight: 600; }
.alert-loc i { color: var(--danger); }
.alert-action { font-size: .8rem; margin-top: .3rem; color: var(--text-soft); background: var(--surface); border-radius: 9px; padding: .4rem .55rem; }
.alert-time { font-size: .7rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.alert-card-foot { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; margin-top: .6rem; }
.btn-resolve { background: var(--icon-chip); color: var(--text); border: none; border-radius: 999px; padding: .35rem .8rem; font-size: .8rem; font-weight: 600; cursor: pointer; }
.btn-resolve:hover { background: var(--online); color: #fff; }

/* ── Вход ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: var(--surface-active); border-radius: 24px; padding: 2.2rem 1.6rem; width: 100%; max-width: 390px; box-shadow: 0 10px 40px rgba(0,0,0,.1); }
.login-brand { text-align: center; color: var(--accent); font-weight: 800; font-size: 1.5rem; margin-bottom: .3rem; }
.login-sub { text-align: center; color: var(--text-soft); font-size: .88rem; margin-bottom: 1.6rem; }
.form-control, .form-select { background: var(--surface); border-color: var(--border); color: var(--text); border-radius: 12px; }
.form-control:focus, .form-select:focus { background: var(--surface); color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent); border-radius: 12px; font-weight: 700; }
.btn-primary:hover { filter: brightness(.95); background: var(--accent); border-color: var(--accent); }

/* ── Bottom sheet ── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1040; }
.device-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1050; background: var(--surface-active);
    border-radius: 24px 24px 0 0; padding: .75rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
    max-height: 82vh; overflow-y: auto; max-width: 760px; margin: 0 auto;
    transform: translateY(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1); box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
.device-sheet.open { transform: translateY(0); }
.sheet-grip { width: 42px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto .7rem; }
.sheet-header { display: flex; align-items: center; gap: .7rem; }
.sheet-ico { width: 46px; height: 46px; border-radius: 13px; background: var(--accent-soft); color: var(--accent-ico); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.sheet-title { font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; }
.min-w-0 { min-width: 0; }
.sheet-section-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 1rem 0 .5rem; }
.sheet-states { display: flex; flex-direction: column; }
.sheet-state-row { display: flex; justify-content: space-between; align-items: center; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.sheet-state-row:last-child { border-bottom: none; }
.ss-label { color: var(--text-soft); font-size: .9rem; }
.ss-value { font-weight: 700; font-size: 1.05rem; }
.ss-value em { font-style: normal; font-size: .78rem; font-weight: 600; color: var(--muted); margin-left: 2px; }
.mini-badge { background: var(--warn-soft); color: var(--warn); border-radius: 999px; padding: .05rem .45rem; font-size: .68rem; font-weight: 700; margin-left: .3rem; }
.sheet-chart-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.sheet-chart-empty { text-align: center; color: var(--muted); padding: 2rem 0; font-size: .85rem; }
.sheet-actions { margin-top: 1rem; }
.btn-sheet { width: 100%; background: var(--accent-soft); color: var(--accent-ico); border: none; border-radius: 12px; padding: .7rem; font-weight: 700; font-size: .9rem; cursor: pointer; }
.btn-sheet:hover { filter: brightness(.97); }

/* ── Тост ── */
.app-toast {
    position: fixed; bottom: calc(var(--bottomnav-h) + 14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
    z-index: 1060; background: var(--text); color: var(--bg); padding: .55rem 1.1rem; border-radius: 999px; font-size: .86rem;
    font-weight: 600; white-space: nowrap; box-shadow: 0 6px 20px rgba(0,0,0,.28);
}
.app-toast.warn { background: var(--danger); color: #fff; }

/* ── Rule builder / сценарии (soft) ── */
.rb-block-label { font-weight: 800; font-size: .95rem; margin-bottom: .5rem; display: flex; align-items: center; gap: .4rem; }
.rb-block-label i { color: var(--accent); }
.rb-seg { display: flex; background: var(--surface); border-radius: 12px; padding: 3px; margin-bottom: .7rem; }
.rb-seg button { flex: 1; border: none; background: none; color: var(--text-soft); border-radius: 9px; padding: .5rem; font-weight: 600; font-size: .82rem; cursor: pointer; }
.rb-seg button.active { background: var(--accent); color: #fff; }
.rb-card { background: var(--surface); border-radius: 14px; padding: .75rem; margin-bottom: .6rem; }
.rb-card-head { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.rb-card-head .form-select { flex: 1; }
.rb-del { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: .2rem .4rem; border-radius: 8px; flex-shrink: 0; }
.rb-del:hover { color: var(--danger); background: var(--danger-soft); }
.rb-fields { }
.rb-inline { display: flex; align-items: center; gap: .5rem; }
.rb-cap { color: var(--muted); font-size: .82rem; }
.rb-days { display: flex; gap: .3rem; flex-wrap: wrap; }
.rb-day-chip { position: relative; cursor: pointer; }
.rb-day-chip input { position: absolute; opacity: 0; }
.rb-day-chip span { display: inline-block; padding: .3rem .6rem; border-radius: 999px; background: var(--icon-chip); color: var(--text-soft); font-size: .8rem; font-weight: 600; }
.rb-day-chip input:checked + span { background: var(--accent); color: #fff; }
.rb-add { width: 100%; background: none; border: 1.5px dashed var(--border); color: var(--accent); border-radius: 12px; padding: .6rem; font-weight: 600; font-size: .85rem; cursor: pointer; }
.rb-add:hover { background: var(--accent-soft); border-color: var(--accent); }
.rb-toggle-choice { display: flex; gap: .5rem; }
.rb-choice { flex: 1; cursor: pointer; }
.rb-choice input { position: absolute; opacity: 0; }
.rb-choice span { display: block; text-align: center; padding: .5rem; border-radius: 10px; background: var(--icon-chip); color: var(--text-soft); font-weight: 600; font-size: .85rem; }
.rb-choice input:checked + span { background: var(--accent); color: #fff; }
.flow-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.flow-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .5rem .8rem; font-size: .85rem; }
.flow-box .flow-label { font-size: .66rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; font-weight: 700; }
.flow-box.flow-trigger { border-color: var(--accent); background: var(--accent-soft); }
.flow-arrow { color: var(--muted); font-size: 1.1rem; }

.badge-warn-mode { background: var(--warn); color: #fff; }
.list-group-item { background: var(--surface); border-color: var(--border); color: var(--text); border-radius: 12px !important; margin-bottom: .4rem; }
.list-group-item-warning { background: var(--warn-soft); }
.table { color: var(--text); }
.alert { border-radius: 12px; }
