:root {
    --bg: #f5f6fb;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #e7e3ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 0%, #dff4ff 0%, transparent 55%);
    --surface: rgba(255, 255, 255, .78);
    --surface-solid: #fff;
    --surface-2: #f0f1f8;
    --border: rgba(20, 22, 50, .09);
    --text: #15172b;
    --muted: #6b6f8a;
    --accent: #6d5dfc;
    --accent-2: #22b8f0;
    --accent-soft: rgba(109, 93, 252, .12);
    --ok: #16a34a;
    --ok-soft: rgba(22, 163, 74, .12);
    --warn: #d97706;
    --warn-soft: rgba(217, 119, 6, .12);
    --err: #e11d48;
    --err-soft: rgba(225, 29, 72, .1);
    --shadow: 0 1px 2px rgba(20, 22, 50, .05), 0 8px 24px rgba(20, 22, 50, .06);
    --shadow-lg: 0 24px 64px rgba(20, 22, 50, .18);
    --radius: 18px;
    --font: "Segoe UI Variable", "Segoe UI", Inter, system-ui, -apple-system, Roboto, sans-serif;
    --mono: "Cascadia Code", Consolas, ui-monospace, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0d0e18;
        --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(109, 93, 252, .22) 0%, transparent 60%), radial-gradient(900px 500px at 110% 0%, rgba(34, 184, 240, .14) 0%, transparent 55%);
        --surface: rgba(24, 26, 42, .72);
        --surface-solid: #181a2a;
        --surface-2: #20233a;
        --border: rgba(255, 255, 255, .08);
        --text: #eceefb;
        --muted: #9599b8;
        --accent-soft: rgba(109, 93, 252, .2);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0d0e18;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, rgba(109, 93, 252, .22) 0%, transparent 60%), radial-gradient(900px 500px at 110% 0%, rgba(34, 184, 240, .14) 0%, transparent 55%);
    --surface: rgba(24, 26, 42, .72);
    --surface-solid: #181a2a;
    --surface-2: #20233a;
    --border: rgba(255, 255, 255, .08);
    --text: #eceefb;
    --muted: #9599b8;
    --accent-soft: rgba(109, 93, 252, .2);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font: 15px/1.5 var(--font);
    color: var(--text);
    background: var(--bg-grad), var(--bg);
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
code { font: 13px var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); margin: 0; }

/* Шапка */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 24px;
    padding: 14px 32px;
    background: var(--surface);
    backdrop-filter: saturate(160%) blur(18px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.brand > div:last-child { min-width: 0; }
.brand-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 6px 18px rgba(109, 93, 252, .35);
}
.logo svg { width: 22px; height: 22px; stroke-width: 2.4; }
.brand-title { font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); flex: none; }
.tab {
    border: 0; background: transparent; color: var(--muted); font: 600 14px var(--font);
    padding: 8px 16px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 0 rgba(22, 163, 74, .5); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .5); } 70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); } }
.top-right { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; justify-content: flex-end; }

/* Переключатель языка */
.lang-switch { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.lang-switch button { border: 0; background: transparent; color: var(--muted); font: 600 12px var(--font); padding: 4px 9px; border-radius: 7px; cursor: pointer; }
.lang-switch button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }

/* Общие элементы */
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.btn {
    display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface-solid);
    color: var(--text); font: 600 14px var(--font); padding: 9px 16px; border-radius: 12px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: none; }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: none; }
.btn.primary { border: 0; color: #fff; background: linear-gradient(135deg, var(--accent), #8b5cf6); box-shadow: 0 6px 18px rgba(109, 93, 252, .3); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
a.btn { text-decoration: none; }
.icon-btn { border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.card { background: var(--surface); backdrop-filter: blur(12px); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Разделы */
main { max-width: 1240px; margin: 0 auto; padding: 32px; }
.view { display: none; animation: rise .25s ease; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
/* описание раздела в одну строку на широком экране (было 640px — переносило посреди фразы) */
.view-head p { max-width: 960px; }
.view-head label.check { flex: none; }

/* Устройства */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; }
.device { padding: 20px; display: flex; flex-direction: column; gap: 14px; transition: .2s; }
.device:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.device.off { opacity: .6; }
.device-top { display: flex; gap: 14px; align-items: flex-start; }
.device-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); flex: none; }
.device-icon.terminal { color: #0ea5e9; background: rgba(14, 165, 233, .12); }
.device-icon.scanner { color: #f59e0b; background: rgba(245, 158, 11, .14); }
.device-icon svg { width: 24px; height: 24px; }
.device-name { font-weight: 700; font-size: 16px; }
.device-type { font-size: 13px; color: var(--muted); }
.device-num { margin-left: auto; font: 600 12px var(--font); color: var(--muted); background: var(--surface-2); padding: 3px 8px; border-radius: 8px; }
.device-status { font-size: 13px; line-height: 20px; color: var(--muted); min-height: 20px; display: flex; gap: 8px; align-items: baseline; }
.device-status .pill { flex: none; }
/* статус и кнопки прижаты к низу карточки: у соседних карточек они на одном уровне, даже если тип устройства в две строки */
.device-status { margin-top: auto; }
.device-actions { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--border); padding-top: 14px; }
.device-actions .spacer { flex: 1; }
.add-card {
    border: 2px dashed var(--border); border-radius: var(--radius); display: grid; place-items: center; text-align: center;
    min-height: 196px; color: var(--muted); cursor: pointer; transition: .2s; background: transparent; font: inherit;
}
.add-card:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-card svg { width: 30px; height: 30px; margin-bottom: 6px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 48px; color: var(--muted); }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: .2s; }
.switch input:checked + span { background: var(--ok); border-color: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }

/* Списки */
.list { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font: 12px var(--mono); padding: 2px 8px; border-radius: 7px; background: var(--surface-2); color: var(--muted); }
.roles { padding: 18px 20px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 18px; }

/* Рабочее место */
.workplace { padding: 20px 22px; max-width: 860px; }
.wp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.wp-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 20px; }
.wp-foot .result { margin-right: auto; font-size: 13px; }
.workplace + .workplace { margin-top: 16px; }
textarea.short { min-height: 0; }
#acPort { margin-top: 16px; font-size: 12.5px; color: var(--muted); }
#accessForm .field > label + input + label, #accessForm .field input + label { margin-top: 10px; }

/* Журнал */
.op { padding: 12px 18px; cursor: pointer; }
.op-line { display: flex; align-items: center; gap: 12px; }
.op-type { font-weight: 600; min-width: 150px; }
.op-text { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-time { font: 12px var(--mono); color: var(--muted); }
.op pre.json { margin: 12px 0 0; padding: 12px; border-radius: 12px; background: var(--surface-2); font: 12px/1.5 var(--mono); max-height: 360px; overflow: auto; display: none; white-space: pre-wrap; }
.op.open pre.json { display: block; }
/* лента чека: бумажная, моноширинная, 42 символа */
.op pre.tape { display: none; width: max-content; max-width: 100%; margin: 12px 0 0; padding: 14px 16px; overflow-x: auto; cursor: text;
    font: 12px/1.45 var(--mono); white-space: pre; color: #1d1d1f; background: #fffdf7; border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .18), 0 8px 24px rgba(0, 0, 0, .08); }
.op.show-tape pre.tape { display: block; }
.tape-btn { flex: none; color: var(--accent); border-color: var(--accent); }
.tape-btn .tape-hide, .op.show-tape .tape-btn .tape-show { display: none; }
.op.show-tape .tape-btn .tape-hide { display: inline; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.op.fresh { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--accent-soft); } }

/* Отчёты */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); margin-bottom: 18px; transition: .2s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Боковая панель */
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 30, .35); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: .25s; z-index: 20; }
.scrim.show { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 21;
    background: var(--surface-solid); box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
    transform: translateX(105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1);
}
.drawer.show { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin-right: auto; }
.drawer-back[hidden] { display: none; }
.drawer-body { flex: 1; overflow: auto; padding: 24px; }
.drawer-foot { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.drawer-foot .result { margin-right: auto; font-size: 13px; }
.group-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 10px; }
.group-title:first-child { margin-top: 0; }
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type {
    text-align: left; border: 1px solid var(--border); background: var(--surface-solid); color: var(--text); border-radius: 14px;
    padding: 14px; cursor: pointer; font: inherit; transition: .15s; display: flex; flex-direction: column; gap: 4px;
}
.type:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.type b { font-size: 15px; }
.type span { font-size: 12px; color: var(--muted); }
.form { display: flex; flex-direction: column; gap: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field-row { display: flex; gap: 8px; }
.field-row > :first-child { flex: 1; }
input[type=text], input[type=number], input[type=password], select, textarea {
    width: 100%; font: 14px var(--font); color: var(--text); background: var(--surface-2); border: 1px solid transparent;
    border-radius: 11px; padding: 10px 12px; outline: none; transition: .15s;
}
textarea { font: 13px/1.5 var(--mono); min-height: 220px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: var(--surface-solid); box-shadow: 0 0 0 4px var(--accent-soft); }
.two { display: grid; grid-template-columns: 110px 1fr; gap: 12px; }
.type-badge { display: flex; gap: 12px; align-items: center; padding: 14px; border-radius: 14px; background: var(--accent-soft); margin-bottom: 4px; }
.type-badge .device-icon { width: 40px; height: 40px; background: var(--surface-solid); }
.type-badge p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.actions-grid .btn { justify-content: center; white-space: normal; text-align: center; }
.field-row .btn { flex: none; }
.slip { margin: 0; padding: 14px; border-radius: 12px; background: var(--surface-2); font: 12px/1.45 var(--mono); white-space: pre-wrap; }

/* Уведомления */
.qr-card { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 25; width: 340px;
    background: var(--surface-solid); border: 1px solid var(--border); border-radius: 16px; padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25); text-align: center; display: flex; flex-direction: column; gap: 10px; }
.qr-card[hidden] { display: none; }
.qr-card img { width: 100%; aspect-ratio: 1; background: #fff; border-radius: 8px; }
.qr-title { font-weight: 600; }
.qr-amount { font-size: 28px; font-weight: 700; }
.toasts { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 30; }
.toast {
    display: flex; gap: 10px; align-items: flex-start; max-width: 420px; padding: 12px 16px; border-radius: 14px;
    background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 14px; animation: rise .25s ease;
}
.toast.ok svg { color: var(--ok); }
.toast.err svg { color: var(--err); }

/* Пять вкладок не помещаются в одну строку с названием и статусом: переносим их на свою строку */
@media (max-width: 1200px) {
    .topbar { flex-wrap: wrap; row-gap: 12px; }
    .tabs { order: 3; width: 100%; overflow: auto; }
}

@media (max-width: 900px) {
    .topbar { flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
    .brand, .top-right { min-width: 0; }
    .tabs { order: 3; width: 100%; overflow: auto; }
    main { padding: 20px 16px; }
    .view-head { flex-direction: column; align-items: stretch; }
    .types { grid-template-columns: 1fr; }
}
