* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #f4f3f1;
    color: #222;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: #2b2118;
    color: #fff;
}

.topbar-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.link-button {
    background: none;
    border: none;
    color: #f4c17a;
    cursor: pointer;
    font-size: 0.95rem;
}

main {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

.hint {
    color: #888;
    font-size: 0.85rem;
    margin-top: -8px;
    margin-bottom: 16px;
}

.drag-handle {
    cursor: grab;
    color: #bbb;
    font-size: 1.1rem;
    padding: 0 2px;
    user-select: none;
}

.drag-handle:hover {
    color: #888;
}

.sortable-ghost {
    opacity: 0.35;
}

.sortable-chosen {
    background: #f8f0dc !important;
}

.flash {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.flash-ok {
    background: #e3f3e6;
    color: #1e7e34;
}

.flash-error {
    background: #fbe4e2;
    color: #c0392b;
}

.category {
    background: #fff;
    border-radius: 10px;
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.category-header,
.subcategory-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.input-category-name {
    font-size: 1.3rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 4px 8px;
    flex: 1;
    background: transparent;
}

.input-category-name:hover,
.input-category-name:focus,
.input-subcat-name:hover,
.input-subcat-name:focus,
.input-subcat-singular:hover,
.input-subcat-singular:focus {
    border-color: #ddd;
    background: #fff;
}

.subcategory {
    margin: 14px 0;
    padding: 8px 0 8px 12px;
    border-left: 3px solid #f0e4d0;
}

.input-subcat-name {
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 3px 6px;
    background: transparent;
}

.input-subcat-singular {
    font-size: 0.85rem;
    color: #888;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 3px 6px;
    background: transparent;
}

.rename-form {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.inline-form {
    display: inline;
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.item-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 6px;
}

.item-row:hover {
    background: #f8f5f0;
}

.item-edit-form,
.new-item-form {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.new-item-form,
.new-subcategory-form,
.new-category-form {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.new-category-form {
    background: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.input-name {
    flex: 1;
    min-width: 0;
}

.input-price {
    width: 80px;
}

.input-desc {
    flex: 1.4;
    min-width: 0;
    color: #777;
}

input[type="text"] {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
}

.btn-icon:hover {
    background: #eee;
}

.btn-danger:hover {
    background: #fbe4e2;
}

.btn-add {
    background: #f0e4d0;
    color: #6b4e23;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn-add:hover {
    background: #e8d6b8;
}

.item-inactive {
    opacity: 0.5;
}

.mod-group {
    background: #fff;
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.mod-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.mod-group-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    flex-wrap: wrap;
}

.mod-options-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
    padding-left: 12px;
    border-left: 3px solid #f0e4d0;
}

select {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
}

/* Логин */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-form {
    background: #fff;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 280px;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9rem;
    color: #444;
}

.login-form input {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
}

.login-form button {
    margin-top: 8px;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: #2b2118;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

.error {
    color: #c0392b;
    font-size: 0.9rem;
    margin: 0;
}

/* ---------- Кнопка "Сохранить всё" ---------- */

main {
    padding-bottom: 92px;
}

.save-all-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #e6dbc8;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
    z-index: 50;
}

.btn-save-all {
    background: #2b2118;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 30px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
}

.btn-save-all:disabled {
    opacity: 0.6;
    cursor: default;
}

.row-dirty {
    box-shadow: inset 3px 0 0 #d98c2b;
    background: #fffaf0;
    border-radius: 6px;
}

/* ---------- Мобильные экраны ---------- */

@media (max-width: 640px) {
    main {
        padding: 14px 12px 92px;
    }

    .topbar {
        padding: 10px 14px;
    }

    .category,
    .new-category-form,
    .mod-group {
        padding: 12px 14px;
    }

    /* На iOS поле с font-size меньше 16px при фокусе увеличивает всю страницу */
    input[type="text"],
    select {
        font-size: 16px;
    }

    .item-row,
    .category-header,
    .subcategory-header,
    .mod-group-header {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .item-edit-form,
    .new-item-form,
    .rename-form,
    .mod-group-form,
    .new-category-form,
    .new-subcategory-form {
        flex: 1 1 100%;
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .input-name,
    .input-desc,
    .input-category-name,
    .input-subcat-name,
    .input-subcat-singular,
    .new-category-form input[type="text"] {
        flex: 1 1 140px;
    }

    .input-price {
        flex: 0 1 90px;
        width: auto;
    }

    .mod-group-form select {
        flex: 1 1 130px;
    }

    .btn-icon {
        min-width: 40px;
        min-height: 40px;
        font-size: 1.2rem;
    }

    .drag-handle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 32px;
        min-height: 32px;
        font-size: 1.3rem;
    }

    .btn-add {
        min-height: 40px;
        padding: 8px 14px;
    }

    .login-body {
        padding: 16px;
    }

    .login-form {
        width: 100%;
        max-width: 280px;
    }
}
