/* ------------------------------------------------------------------ */
/*  Базовая тема                                                       */
/* ------------------------------------------------------------------ */

:root {
    --bg:            #0f1720;
    --bg-card:       #1a2430;
    --bg-row:        #202b38;
    --bg-accent:     #23344a;
    --text:          #eaf0f6;
    --text-dim:      #8fa3b8;
    --accent:        #4ea1ff;
    --ok:            #2ea043;
    --err:           #d13b3b;
    --warn:          #b08800;
    --line:          rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 16px 100px; /* снизу место под savebar */
}

h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }

/* ------------------------------------------------------------------ */
/*  Карточка статуса                                                   */
/* ------------------------------------------------------------------ */

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 4px 14px;
    margin-bottom: 14px;
}
.row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    gap: 12px;
}
.row:last-child { border-bottom: none; }

.badge {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 5px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-ok   { background: var(--ok);   color: #fff; }
.badge-err  { background: var(--err);  color: #fff; }
.badge-warn { background: var(--warn); color: #fff; }
.badge-wait { background: #33475c;     color: #cfdae7; }

/* ------------------------------------------------------------------ */
/*  Поиск                                                              */
/* ------------------------------------------------------------------ */

.search {
    display: block;
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 10px;
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid transparent;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
.search::placeholder { color: var(--text-dim); }
.search:focus { border-color: var(--accent); background: var(--bg-row); }

/* ------------------------------------------------------------------ */
/*  Тулбар                                                             */
/* ------------------------------------------------------------------ */

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 8px;
}
.toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}
.toggle input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.btn-ghost {
    padding: 6px 12px;
    font-size: 13px;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-dim); }

/* ------------------------------------------------------------------ */
/*  Дерево категорий                                                   */
/* ------------------------------------------------------------------ */

.tree { display: flex; flex-direction: column; gap: 8px; }

.cat {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
}
.cat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    cursor: pointer;
    list-style: none;
    font-size: 15px;
    font-weight: 600;
    user-select: none;
}
.cat-head::-webkit-details-marker { display: none; }
.cat-head::after {
    content: "▸";
    color: var(--text-dim);
    font-size: 12px;
    transition: transform 0.15s;
    margin-left: 4px;
}
.cat[open] > .cat-head::after { transform: rotate(90deg); }

.cat-name { flex: 1; }

.cat-count {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-dim);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.cat-count-active {
    background: rgba(78, 161, 255, 0.18);
    color: var(--accent);
}

.cat-body { padding: 0 8px 10px 8px; }

/* ------------------------------------------------------------------ */
/*  Строка типа (с чекбоксом)                                          */
/* ------------------------------------------------------------------ */

.sub {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px;
    border-radius: 7px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s;
}
.sub:hover { background: rgba(255, 255, 255, 0.03); }

.sub input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.sub-name { flex: 1; }
.sub-id {
    font-size: 11px;
    color: var(--text-dim);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.sub-selected {
    background: rgba(78, 161, 255, 0.10);
}
.sub-selected .sub-name { color: #d8ebff; }

.muted {
    color: var(--text-dim);
    font-size: 14px;
    padding: 24px 16px;
    text-align: center;
}

/* ------------------------------------------------------------------ */
/*  Нижняя панель сохранения                                           */
/* ------------------------------------------------------------------ */

.savebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 16px 14px;
    background: linear-gradient(to top, var(--bg) 60%, rgba(15,23,32,0));
    z-index: 10;
}
.savebar-inner {
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.savebar-info {
    font-size: 13px;
    color: var(--text-dim);
}
.savebar-info b { color: var(--text); }

.btn-primary {
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    font-family: inherit;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
/* ---------- Табы ---------- */

.tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    background: var(--bg-card);
    border-radius: 10px;
    padding: 4px;
}
.tab {
    flex: 1;
    padding: 10px 8px;
    background: transparent;
    color: var(--text-dim);
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active {
    background: var(--bg-accent);
    color: var(--text);
}

.panel { display: none; }
.panel.active { display: block; }

/* ---------- Слова ---------- */

.word-add {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}
.word-add .search { margin-bottom: 0; flex: 1; }
.word-add .btn-primary { white-space: nowrap; }

.hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 14px;
    line-height: 1.5;
}

.word-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.word-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 14px;
    background: var(--bg-card);
    border-radius: 10px;
}
.word-text {
    flex: 1;
    font-size: 14px;
    word-break: break-word;
}
.word-del {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 7px;
    background: rgba(209, 59, 59, 0.15);
    color: #ff8080;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.word-del:hover { background: rgba(209, 59, 59, 0.30); color: #fff; }

/* ---------- Фильтры ---------- */

.fgroup {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
}
.fgroup-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.frow-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.frow-2 .search { margin-bottom: 0; }

.frow-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 14px;
    cursor: pointer;
}
.frow-toggle input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.frow-input {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--text-dim);
}
.frow-input .search { margin-bottom: 0; }

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.chip {
    padding: 8px 12px;
    background: var(--bg-row);
    color: var(--text);
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.chip:hover { background: #263748; }
.chip.active {
    background: rgba(78, 161, 255, 0.18);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.filter-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}