* { 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;
}

.topbar-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.link-button {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 999px;
    color: #f4c17a;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    text-decoration: none;
    padding: 8px 16px;
    white-space: nowrap;
    transition: background-color 0.15s ease;
}

.link-button:hover {
    background: rgba(255, 255, 255, 0.16);
}

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;
}

/* ---------- Статистика ---------- */

a.btn-add {
    display: inline-block;
    text-decoration: none;
}

.btn-add-active {
    background: #2b2118;
    color: #fff;
}

.btn-add-active:hover {
    background: #2b2118;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.stats-header h1 {
    margin: 0;
}

.stats-period-toggle {
    display: flex;
    gap: 8px;
}

.stats-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 16px 0 20px;
}

.stats-nav a.btn-icon {
    text-decoration: none;
    font-size: 1.2rem;
}

.stats-nav-disabled {
    opacity: 0.3;
    cursor: default;
}

.stats-range {
    font-size: 0.95rem;
    color: #666;
    min-width: 180px;
    text-align: center;
}

.stats-range-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 16px 0 20px;
}

.stats-range-form label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
    color: #666;
}

.stats-range-form input.js-date-input {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
    width: 110px;
}

.date-field {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.date-field .js-date-native {
    position: absolute;
    width: 0;
    height: 0;
    padding: 0;
    border: none;
    opacity: 0;
    pointer-events: none;
}

.js-date-picker-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 4px;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

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

.stats-card-label {
    font-size: 0.8rem;
    color: #888;
    margin: 0 0 4px;
}

.stats-card-value {
    font-size: 1.4rem;
    font-weight: 600;
    margin: 0;
}

.stats-comparison {
    font-size: 0.9rem;
    margin: 0 0 20px;
}

.stats-comparison-up {
    color: #1e7e34;
}

.stats-comparison-down {
    color: #c0392b;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    margin-bottom: 28px;
}

.stats-table th,
.stats-table td {
    text-align: left;
    padding: 8px 14px;
    font-size: 0.9rem;
    border-bottom: 1px solid #f0ece3;
}

.stats-table th {
    color: #888;
    font-weight: 600;
    font-size: 0.8rem;
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-users-title {
    font-size: 1.1rem;
    margin: 0 0 12px;
}

.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;
}

/* ---------- Часы работы ---------- */

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

.hours-day-label {
    font-weight: 600;
    min-width: 32px;
}

.hours-dash {
    color: #999;
}

.hours-form input:disabled {
    background: #f0f0f0;
    color: #aaa;
}

/* ---------- Клиенты ---------- */

.muted {
    color: #888;
    font-weight: 400;
}

.customers-search {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 12px 0;
}

.customers-sort {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.table-scroll {
    overflow-x: auto;
}

.customers-table {
    min-width: 480px;
}

.customers-table td a {
    color: #6b4e23;
    font-weight: 600;
    text-decoration: none;
}

.customers-table td a:hover {
    text-decoration: underline;
}

.customers-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
}

.customer-order {
    margin-bottom: 14px;
}

.customer-order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.95rem;
}

.customer-order-items {
    margin: 8px 0 0;
    padding-left: 18px;
    font-size: 0.9rem;
}

.customer-order-items li {
    margin: 4px 0;
}

/* Логин */

.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;
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .link-button {
        padding: 7px 12px;
        font-size: 0.85rem;
    }

    .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;
    }
}
