* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    min-height: 100vh;
}

header {
    background: #2c3e50;
    color: white;
    padding: 1.5rem;
}

header h1 {
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

nav {
    display: flex;
    gap: 1rem;
}

.nav-btn {
    background: #34495e;
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.3s;
}

.nav-btn:hover {
    background: #4a6278;
}

.nav-btn.active {
    background: #1a252f;
    font-weight: 600;
}

/* Desktop nav dropdown (Справочники) */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #2c3e50;
    border: 1px solid #4a6278;
    border-radius: 6px;
    padding: 0.4rem;
    z-index: 200;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 170px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    margin-top: 4px;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: flex;
}

.nav-dropdown-item {
    background: none;
    border: none;
    padding: 0.55rem 0.9rem;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
    color: white;
    font-size: 0.95rem;
    width: 100%;
}

.nav-dropdown-item:hover {
    background: #34495e;
}

/* Pagination controls */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 1rem 0;
    padding: 0.5rem;
}

.pagination button {
    padding: 0.4rem 1rem;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    color: #333;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.pagination button:hover:not(:disabled) {
    background: #f0f0f0;
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination span {
    font-size: 0.9rem;
    color: #666;
    min-width: 60px;
    text-align: center;
}

main {
    padding: 2rem;
}

.view {
    display: block;
}

.view.hidden {
    display: none;
}

.filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.tab-btn {
    background: #ecf0f1;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
}

.tab-btn:hover {
    background: #d5dbdb;
}

.tab-btn.active {
    background: #3498db;
    color: white;
}

.list-container {
    display: grid;
    gap: 1rem;
}

.card {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1.5rem;
    cursor: pointer;
    transition: box-shadow 0.3s, transform 0.2s;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

.card h3 {
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.card p {
    color: #7f8c8d;
    margin-bottom: 0.3rem;
}

.badge {
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-right: 0.5rem;
}

.badge.base {
    background: #3498db;
    color: white;
}

.badge.custom {
    background: #9b59b6;
    color: white;
}

.badge.draft, .badge.DRAFT {
    background: #95a5a6;
    color: white;
}

.badge.in_progress, .badge.IN_PROGRESS {
    background: #f39c12;
    color: white;
}

.badge.completed, .badge.COMPLETED {
    background: #27ae60;
    color: white;
}

.badge.CANCELLED {
    background: #e74c3c;
    color: white;
}

.badge.DEFECTIVE {
    background: #c0392b;
    color: white;
}

.form {
    max-width: 600px;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #2c3e50;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.btn-primary {
    background: #3498db;
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-back {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 1rem;
}

.btn-back:hover {
    background: #7f8c8d;
}

.info-panel {
    background: #ecf0f1;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.info-panel p {
    margin-bottom: 0.5rem;
}

.steps-container {
    display: grid;
    gap: 1rem;
}

.step-card {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 1.5rem;
    background: white;
}

.step-card.active {
    border-color: #3498db;
    background: #f8fbfd;
}

.step-card.completed {
    border-color: #27ae60;
    background: #f1f8f4;
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.step-title {
    font-size: 1.2rem;
    color: #2c3e50;
    font-weight: 600;
}

.step-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-step {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: opacity 0.3s;
}

.btn-start {
    background: #3498db;
    color: white;
}

.btn-complete {
    background: #27ae60;
    color: white;
}

.btn-step:hover {
    opacity: 0.8;
}

.step-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.step-field {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
}

.step-field label {
    display: block;
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 0.3rem;
}

.step-field input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
}

.step-field .value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.step-field .target {
    font-size: 0.9rem;
    color: #27ae60;
}

.step-notes {
    margin-top: 1rem;
}

.step-notes textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    min-height: 80px;
}

h2 {
    margin-bottom: 1.5rem;
    color: #2c3e50;
}

h3 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: #2c3e50;
    font-size: 1.3rem;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: #7f8c8d;
}

/* Recipe detail and edit */
.recipe-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.recipe-actions {
    display: flex;
    gap: 1rem;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.steps-edit-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.step-edit-card {
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 1.5rem;
    transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}
.step-edit-card.dragging {
    opacity: 0.4;
    cursor: grabbing;
}
.step-edit-card.drag-over {
    border-color: #3498db;
    background: #eaf4fb;
}
.step-drag-handle {
    cursor: grab;
    font-size: 1.3rem;
    color: #c0c6cc;
    padding: 0 0.4rem 0 0;
    user-select: none;
    flex-shrink: 0;
    line-height: 1;
    touch-action: none;
}
.step-drag-handle:hover { color: #7f8c8d; }
.step-drag-handle:active { cursor: grabbing; }
.step-header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}
.step-move-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.step-move-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.75rem;
    line-height: 1.4;
    cursor: pointer;
    color: #7f8c8d;
}
.step-move-btn:hover:not(:disabled) { background: #e9ecef; color: #2c3e50; }
.step-move-btn:disabled { opacity: 0.25; cursor: default; }
.step-delete-btn {
    background: none;
    border: 1px solid #e0a0a0;
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 0.8rem;
    cursor: pointer;
    color: #c0392b;
    line-height: 1.4;
}
.step-delete-btn:hover { background: #fdecea; }
.step-add-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1rem;
}
.step-add-select {
    flex: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
}

.step-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #ddd;
    gap: 0.5rem;
}

.step-edit-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.step-edit-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.step-edit-field {
    display: flex;
    flex-direction: column;
}

.step-edit-field label {
    font-size: 0.9rem;
    color: #7f8c8d;
    margin-bottom: 0.3rem;
}

.step-edit-field input,
.step-edit-field textarea {
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
}

.step-edit-field input:focus,
.step-edit-field textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid #ecf0f1;
}

.recipe-step-view {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.recipe-step-view h4 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.step-params {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.step-param {
    background: #f8f9fa;
    padding: 0.8rem;
    border-radius: 4px;
}

.step-param-label {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-bottom: 0.3rem;
}

.step-param-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #27ae60;
}

/* Стили для диапазонов значений в редактировании рецепта */
.range-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

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

.range-inputs span {
    color: #666;
    font-weight: bold;
}

/* Чекбокс пропуска этапа */
.skip-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #e67e22;
    cursor: pointer;
}

.skip-checkbox input[type="checkbox"] {
    cursor: pointer;
}

.step-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Стили для справочников */
.reference-card {
    position: relative;
    padding-bottom: 3rem;
}

.card-actions {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
}

/* Панель фильтров справочников */
.ref-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.ref-search-input {
    flex: 1;
    min-width: 150px;
    padding: 0.4rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}
.ref-filter-select {
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.85rem;
    background: white;
    color: #333;
    cursor: pointer;
    max-width: 180px;
}

/* Индикатор неполноты карточки */
.ref-incomplete-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #f39c12;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    z-index: 1;
}

/* Плиточный грид для справочников */
.ref-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 0.75rem;
}

/* ── Теги сыра ─────────────────────────────────────────────────────────────── */
.cheese-tag-chip {
    display: inline-block;
    background: #eaf4fb;
    color: #2980b9;
    border: 1px solid #aed6f1;
    border-radius: 12px;
    padding: 1px 8px;
    font-size: 0.75rem;
    margin: 1px 2px;
    white-space: nowrap;
}
.recipe-tags-editor {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.25rem;
}
.cheese-tag-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 14px;
    padding: 3px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    color: #555;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.cheese-tag-btn:hover { background: #e0eaf5; border-color: #aed6f1; }
.cheese-tag-btn.active {
    background: #2980b9;
    border-color: #2980b9;
    color: white;
}

.ref-tile {
    position: relative;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s;
}

.ref-tile:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.ref-tile-img {
    width: 100%;
    height: 120px;
    background: #e8ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.ref-tile-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ref-tile-placeholder {
    font-size: 2.5rem;
    color: #bbb;
}

.ref-tile-body {
    padding: 0.5rem 0.6rem;
    flex-grow: 1;
    flex-basis: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 60px;
}

.ref-tile-name {
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #222;
}

.ref-tile-meta {
    font-size: 0.75rem;
    color: #666;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ref-tile-actions {
    display: flex;
    gap: 0.3rem;
    margin-top: auto;
    padding-top: 0.3rem;
}

.btn-icon {
    background: #ecf0f1;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.25rem 0.4rem;
    font-size: 0.9rem;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s;
}

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

.btn-icon-danger {
    background: #fde8e8;
    border-color: #e74c3c;
    color: #c0392b;
}

.btn-icon-danger:hover {
    background: #e74c3c;
    color: white;
}

.ref-view-desc {
    margin-top: 0.75rem;
    line-height: 1.6;
}

.ref-view-desc h1, .ref-view-desc h2, .ref-view-desc h3 {
    margin: 0.75rem 0 0.4rem;
    font-size: 1rem;
}

.ref-view-desc p {
    margin-bottom: 0.5rem;
}

.ref-view-desc ul, .ref-view-desc ol {
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
}

.ref-view-desc a {
    color: #2980b9;
}

.ref-view-desc code {
    background: #f0f0f0;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.9em;
}

.ref-view-desc pre {
    background: #f0f0f0;
    padding: 0.75rem;
    border-radius: 4px;
    overflow-x: auto;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Tag selector (заменяет multi-select) */
.tag-selector {
    position: relative;
    width: 100%;
}
.tag-input-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.5rem;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    min-height: 2.5rem;
    cursor: text;
    background: #fff;
    transition: border-color 0.15s;
}
.tag-input-wrap:focus-within {
    border-color: #2980b9;
    box-shadow: 0 0 0 2px rgba(41, 128, 185, 0.15);
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: #dbeafe;
    color: #1d4ed8;
    border-radius: 4px;
    padding: 0.15rem 0.45rem;
    font-size: 0.82rem;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tag-chip-x {
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    color: #60a5fa;
    margin-left: 0.1rem;
    flex-shrink: 0;
}
.tag-chip-x:hover { color: #e53e3e; }
.tag-search-input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 100px;
    font-size: 0.9rem;
    background: transparent;
    padding: 0.1rem 0;
}
.tag-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    max-height: 220px;
    overflow-y: auto;
    z-index: 300;
    display: none;
}
.tag-dropdown.open { display: block; }
.tag-dropdown-item {
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    font-size: 0.88rem;
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}
.tag-dropdown-item:hover { background: #f0f7ff; }
.tag-dropdown-meta {
    color: #999;
    font-size: 0.78rem;
}
.tag-dropdown-empty {
    padding: 0.5rem 0.75rem;
    color: #aaa;
    font-size: 0.85rem;
    font-style: italic;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Улучшенное отображение информационных панелей */
.info-panel ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.info-panel li {
    margin-bottom: 0.3rem;
}

/* Ингредиенты рецепта на форме партии */
.batch-recipe-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}
.batch-recipe-name {
    font-weight: 600;
    font-size: 1rem;
}
.batch-recipe-open {
    font-size: 0.82rem;
    color: #2980b9;
    text-decoration: none;
    border: 1px solid #2980b9;
    border-radius: 4px;
    padding: 0.15rem 0.5rem;
    white-space: nowrap;
    cursor: pointer;
    background: none;
}
.batch-recipe-open:hover { background: #ebf5fb; }
.batch-ing-section {
    background: #fff;
    border: 1px solid #dde3ea;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}
.batch-ing-section-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.5rem;
}
.batch-ing-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.batch-ing-chip {
    background: #f0f4ff;
    border: 1px solid #c7d7f5;
    border-radius: 5px;
    padding: 0.25rem 0.6rem;
    font-size: 0.85rem;
    color: #1a3a6b;
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
}
.batch-ing-chip-meta {
    font-size: 0.72rem;
    color: #888;
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal:not(.hidden) {
    display: flex;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    color: #2c3e50;
}

/* ===== Шапка рецепта в чат-режиме ===== */
.chat-batch-info {
    border: 1px solid #dde3ea;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    background: #f8faff;
    overflow: hidden;
}
.chat-batch-info-summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.92rem;
    list-style: none;
    user-select: none;
}
.chat-batch-info-summary::-webkit-details-marker { display: none; }
.chat-batch-info-summary::before {
    content: '▶';
    font-size: 0.65rem;
    color: #888;
    transition: transform 0.15s;
    flex-shrink: 0;
}
.chat-batch-info[open] .chat-batch-info-summary::before {
    transform: rotate(90deg);
}
.chat-batch-info-summary .batch-recipe-open {
    margin-left: auto;
}
#chat-batch-ing {
    padding: 0 0.85rem 0.75rem;
}
#chat-batch-ing .batch-ing-section {
    margin-bottom: 0.5rem;
}

/* ===== Чат-бот ===== */

.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.chat-header h2 {
    flex: 1;
    margin: 0;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 8px;
    min-height: 300px;
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.chat-msg {
    max-width: 85%;
    padding: 0.7rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.chat-msg.user {
    align-self: flex-end;
    background: #3498db;
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.bot {
    align-self: flex-start;
    background: white;
    border: 1px solid #ddd;
    border-bottom-left-radius: 4px;
}

.chat-msg.step_announce {
    background: #2c3e50;
    color: white;
    font-weight: 600;
    font-size: 1.05rem;
    max-width: 100%;
    border-radius: 8px;
}

.chat-msg.instruction {
    background: #ecf0f1;
    color: #2c3e50;
    font-style: italic;
    max-width: 100%;
    border-radius: 8px;
}

.chat-msg.confirmation {
    background: #d5f5e3;
    color: #1e8449;
    border: 1px solid #a9dfbf;
}

.chat-msg.error {
    background: #fdedec;
    color: #c0392b;
    border: 1px solid #f5b7b1;
}

.chat-msg.completion {
    background: #27ae60;
    color: white;
    font-weight: 600;
    max-width: 100%;
    text-align: center;
    border-radius: 8px;
}

.chat-msg.help {
    background: #fef9e7;
    color: #7d6608;
    border: 1px solid #f9e79f;
    max-width: 100%;
    font-family: monospace;
    font-size: 0.9rem;
}

.chat-msg.summary {
    background: #d6eaf8;
    color: #1b4f72;
    border: 1px solid #aed6f1;
    max-width: 100%;
}

.chat-msg.status {
    background: #e8daef;
    color: #6c3483;
    border: 1px solid #d2b4de;
}

.chat-msg.greeting {
    background: #d5f5e3;
    color: #1e8449;
    border: 1px solid #a9dfbf;
    max-width: 100%;
}

.chat-msg.ai_response {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-badge {
    display: inline-block;
    font-size: 0.65rem;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 4px;
    padding: 1px 5px;
    margin-right: 6px;
    font-weight: 600;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

.badge-beta {
    display: inline-block;
    font-size: 0.6rem;
    background: #764ba2;
    color: white;
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
    vertical-align: middle;
}

.chat-msg .msg-time {
    display: block;
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 0.3rem;
}

.chat-input-area {
    position: sticky;
    bottom: 0;
    background: white;
    padding-top: 0.5rem;
}

.chat-quick-commands {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.cmd-btn {
    background: #ecf0f1;
    border: 1px solid #bdc3c7;
    padding: 0.4rem 0.7rem;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: monospace;
    transition: background 0.2s;
}

.cmd-btn:hover {
    background: #d5dbdb;
}

.cmd-btn--danger {
    border-color: #e74c3c;
    color: #c0392b;
}

.cmd-btn--danger:hover {
    background: #fdecea;
}

.chat-form {
    display: flex;
    gap: 0.5rem;
}

.chat-form input {
    flex: 1;
    padding: 0.8rem 1rem;
    border: 2px solid #ddd;
    border-radius: 24px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.chat-form input:focus {
    border-color: #3498db;
}

.btn-send {
    background: #3498db;
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: #2980b9;
}

.btn-send:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* ===== Auth ===== */

#auth-section {
    display: block;
}

#auth-section.hidden {
    display: none;
}

.auth-container {
    max-width: 400px;
    margin: 80px auto;
    padding: 2.5rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

.auth-logo {
    text-align: center;
    font-size: 2.5rem;
    color: #2c3e50;
    margin-bottom: 0.3rem;
}

.auth-subtitle {
    text-align: center;
    color: #7f8c8d;
    margin-bottom: 2rem;
    font-size: 1.05rem;
}

.auth-hint {
    text-align: center;
    color: #7f8c8d;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.auth-form .form-group {
    margin-bottom: 1.2rem;
}

.auth-form .form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9rem;
}

.auth-form .form-group input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-form .form-group input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.verify-code-input {
    text-align: center;
    font-size: 1.8rem !important;
    letter-spacing: 0.5rem;
    font-weight: 600;
}

.btn-block {
    width: 100%;
    display: block;
}

.auth-link {
    text-align: center;
    margin-top: 1.5rem;
    color: #7f8c8d;
    font-size: 0.9rem;
}

.auth-link a {
    color: #3498db;
    text-decoration: none;
    font-weight: 600;
}

.auth-link a:hover {
    text-decoration: underline;
}

/* ===== Header user/logout ===== */

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.header-top h1 {
    margin-bottom: 0;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 0.9rem;
}

#user-info {
    opacity: 0.8;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.4rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ===== Toast notifications ===== */

.toast {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    padding: 0.9rem 1.5rem;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    font-size: 0.95rem;
    z-index: 9999;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s, transform 0.3s;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: #27ae60;
}

.toast-error {
    background: #e74c3c;
}

.toast-info {
    background: #3498db;
}


/* ===== Timer widget ===== */

.timer-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #2c3e50;
    color: white;
    border-radius: 14px;
    padding: 1rem 1.5rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
    z-index: 1000;
    text-align: center;
    min-width: 160px;
    user-select: none;
}

.timer-label {
    font-size: 0.78rem;
    opacity: 0.65;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.timer-display {
    font-size: 2.8rem;
    font-weight: 700;
    font-family: monospace;
    letter-spacing: 3px;
    line-height: 1;
}

.timer-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}

.timer-controls button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s;
}

.timer-controls button:hover {
    background: rgba(255, 255, 255, 0.28);
}

.timer-widget.expired {
    animation: timer-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes timer-pulse {
    from { background: #c0392b; transform: scale(1); box-shadow: 0 4px 24px rgba(192, 57, 43, 0.4); }
    to   { background: #e74c3c; transform: scale(1.05); box-shadow: 0 0 28px rgba(231, 76, 60, 0.7); }
}

/* Timer button in step card */
.btn-timer {
    background: #8e44ad;
    color: white;
}

.btn-timer:hover {
    opacity: 0.85;
}

/* Replay button inside chat messages */
.timer-replay-btn {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.3rem 0.9rem;
    background: #8e44ad;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: opacity 0.15s;
}

.timer-replay-btn:hover {
    opacity: 0.85;
}

/* Timer input dialog */
.timer-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.timer-dialog {
    background: white;
    border-radius: 12px;
    padding: 1.75rem 2rem;
    min-width: 280px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.timer-dialog h3 {
    margin: 0 0 0.5rem;
    color: #2c3e50;
    font-size: 1.1rem;
}

.timer-dialog p {
    color: #7f8c8d;
    font-size: 0.85rem;
    margin: 0 0 0.75rem;
}

.timer-dialog input[type="number"] {
    width: 100%;
    padding: 0.65rem;
    font-size: 1.6rem;
    text-align: center;
    border: 2px solid #3498db;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-sizing: border-box;
}

.timer-dialog-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

/* ===== ФОТО В ЧАТЕ ===== */
.chat-photo {
    max-width: 240px;
    max-height: 200px;
    border-radius: 8px;
    cursor: zoom-in;
    display: block;
    margin-top: 0.4rem;
}

/* ===== МИНИАТЮРЫ ФОТО В ЭТАПАХ ===== */
.step-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
    align-items: flex-start;
}

.step-photo-wrap {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

.step-photo-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    cursor: zoom-in;
    display: block;
    border: 2px solid transparent;
    transition: border-color 0.15s;
}

.step-photo-thumb:hover {
    border-color: #3498db;
}

.photo-delete-btn {
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-size: 0.7rem;
    cursor: pointer;
    width: 100%;
}

.photo-delete-btn:hover {
    background: #c0392b;
}

.btn-photo {
    background: #2980b9;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-photo:hover {
    background: #2471a3;
}

/* ===== LIGHTBOX ===== */
.photo-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    cursor: zoom-out;
}

.photo-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.photo-lightbox.hidden {
    display: none;
}

/* ─── Dashboard ─────────────────────────────────────────────── */

.dashboard-title {
    margin-bottom: 1.25rem;
    font-size: 1.5rem;
    color: #2c3e50;
}

/* Summary cards row */
.dashboard-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.dash-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 1.25rem 1rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.dash-card--accent {
    border-color: #e67e22;
    background: #fff8f2;
}

.dash-card__value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1.1;
}

.dash-card--accent .dash-card__value {
    color: #e67e22;
}

.dash-card__label {
    font-size: 0.78rem;
    color: #7f8c8d;
    margin-top: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Charts grid */
.dashboard-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.chart-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.chart-card h3 {
    font-size: 0.95rem;
    color: #555;
    margin-bottom: 1rem;
    font-weight: 600;
}

.chart-card--pie {
    grid-column: 1 / -1;
    max-width: 480px;
    justify-self: center;
    width: 100%;
}

.chart-empty {
    text-align: center;
    color: #aaa;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}


/* ===== Профиль пользователя ===== */
.profile-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    max-width: 860px;
}

.profile-avatar-section {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.profile-img-preview {
    min-width: 120px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-logo-preview {
    min-width: 200px;
    min-height: 60px;
    border: 1px dashed var(--color-border);
    border-radius: 6px;
    padding: 0.5rem;
}

.profile-right {
    flex: 1;
    min-width: 0;
}

.profile-form {
    width: 100%;
}

.profile-logo-section {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
}

.btn-small {
    padding: 0.3rem 0.75rem;
    font-size: 0.85rem;
}


.password-change-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e0e0e0;
}

.password-change-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: #333;
}

.hint-text {
    font-size: 0.875rem;
    color: #666;
    margin: 0 0 0.75rem;
}

/* ============================================================
   МОБИЛЬНАЯ АДАПТИВНОСТЬ (≤ 640px)
   ============================================================ */

/* Bottom nav — скрыт на десктопе */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 640px) {

    /* Контейнер */
    .container {
        min-height: 100dvh;
    }

    /* Хедер: компактный, прилипает к верху */
    header {
        padding: 0.6rem 1rem;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .header-top {
        flex-direction: row;
        align-items: center;
    }

    header h1 {
        font-size: 1.1rem;
        flex: 1;
    }

    .btn-logout {
        font-size: 0.8rem;
        padding: 0.3rem 0.6rem;
    }

    /* Горизонтальная nav — скрыть, остаётся только mobile-bottom-nav */
    nav:not(.mobile-bottom-nav) {
        display: none;
    }

    /* Main — отступ снизу для bottom bar */
    main {
        padding: 1rem;
        padding-bottom: calc(64px + env(safe-area-inset-bottom));
    }

    /* Формы — на всю ширину */
    .form {
        max-width: 100%;
        padding: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    /* Модалки — снизу экрана */
    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100%;
        width: 100%;
        margin: 0;
        border-radius: 16px 16px 0 0;
        position: relative;
        max-height: 90dvh;
        overflow-y: auto;
    }

    /* Дашборд */
    .dashboard-summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-charts {
        grid-template-columns: 1fr;
    }

    .chart-card--pie {
        max-width: 100%;
    }

    /* Профиль */
    .profile-layout {
        flex-direction: column;
    }

    .profile-avatar-section {
        width: 100%;
    }

    /* Справочники */
    .ref-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    /* Чат */
    .chat-messages {
        max-height: 50vh;
    }

    .chat-msg {
        max-width: 92%;
    }

    .chat-quick-commands {
        gap: 0.3rem;
    }

    .cmd-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }

    .chat-header h2 {
        font-size: 1.1rem;
    }

    /* Toast — выше bottom bar */
    .toast {
        left: 1rem;
        right: 1rem;
        max-width: none;
        top: auto;
        bottom: calc(72px + env(safe-area-inset-bottom));
    }

    /* Таймер — выше bottom bar */
    .timer-widget {
        bottom: calc(72px + env(safe-area-inset-bottom));
        right: 1rem;
    }

    /* Auth */
    .auth-container {
        margin: 40px auto;
        padding: 1.5rem;
    }

    .auth-logo {
        font-size: 2rem;
    }

    /* Bottom nav — показать */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(56px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: #2c3e50;
        border-top: 1px solid #3d5166;
        z-index: 500;
    }
}

/* ===== Mobile Tab Bar ===== */
.mob-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: rgba(255,255,255,0.55);
    gap: 0.1rem;
    cursor: pointer;
    padding: 0.3rem 0;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.mob-tab.active {
    color: #d4a017;
}

.mob-tab-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.mob-tab-label {
    font-size: 0.58rem;
    letter-spacing: 0.01em;
}

/* ===== Refs Bottom Sheet ===== */
.refs-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 300;
}

.refs-sheet {
    position: fixed;
    bottom: calc(56px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 0.75rem 1rem 1rem;
    z-index: 400;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
}

.refs-sheet-handle {
    width: 36px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin: 0 auto 1rem;
}

.refs-sheet-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.refs-sheet-item {
    display: block;
    width: 100%;
    padding: 0.85rem 1rem;
    background: none;
    border: none;
    border-radius: 8px;
    text-align: left;
    font-size: 1rem;
    color: #333;
    cursor: pointer;
    transition: background 0.15s;
}

.refs-sheet-item:hover,
.refs-sheet-item:active {
    background: #f5f5f5;
}

/* ===== Панель администратора ===== */
.table-container { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th,
.admin-table td { padding: 0.6rem 0.8rem; border-bottom: 1px solid #eee; text-align: left; font-size: 0.9rem; }
.admin-table th { background: #f8f8f8; font-weight: 600; }
.row-inactive { opacity: 0.5; }
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; }
.badge-active { background: #d4edda; color: #155724; }
.badge-inactive { background: #f8d7da; color: #721c24; }
.badge-admin { background: #d4a017; color: #fff; }
.admin-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.btn-sm { padding: 0.25rem 0.6rem !important; font-size: 0.8rem !important; }
