/* ========================================
   Список покупок — Мобильные стили
   ======================================== */

:root {
    --primary-color: #4CAF50;
    --primary-dark: #388E3C;
    --secondary-color: #2196F3;
    --danger-color: #f44336;
    --warning-color: #FF9800;
    --text-color: #333;
    --text-light: #666;
    --bg-color: #f5f5f5;
    --card-bg: #fff;
    --border-color: #e0e0e0;
    --success-bg: #E8F5E9;
    --error-bg: #FFEBEE;
    --overdue-color: #f44336;
    --today-color: #FF9800;
    --soon-color: #2196F3;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

/* ========================================
   Header
   ======================================== */
.header {
    background: var(--primary-color);
    color: white;
    padding: 6px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-with-fab h1 {
    display: flex;
    align-items: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

#online-indicator {
    font-size: 22px;
    cursor: default;
    transition: color 0.2s;
    padding: 2px 4px;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.fab-add-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s;
    flex-shrink: 0;
}

.fab-add-small:hover {
    background: rgba(255,255,255,0.3);
    transform: scale(1.05);
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header h1 .back-link {
    color: white;
    text-decoration: none;
    font-size: 22px;
    margin-right: 6px;
}

.nav {
    display: flex;
    gap: 4px;
    align-items: center;
}

.nav-link {
    color: white;
    text-decoration: none;
    font-size: 22px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.nav-link:hover {
    background: rgba(255,255,255,0.2);
}

/* ========================================
   Container
   ======================================== */
.container {
    padding: 16px;
    padding-bottom: 80px;  /* complete-bar */
    max-width: 480px;
    margin: 0 auto;
}

/* ========================================
   Sections
   ======================================== */
.section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.section h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-soon {
    border-left: 4px solid var(--warning-color);
}

/* ========================================
   Quick Add List
   ======================================== */
.quick-add-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-add-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-color);
    border-radius: 8px;
    border-left: 3px solid var(--border-color);
}

.quick-add-item[data-status="overdue"] {
    border-left-color: var(--overdue-color);
    background: #FFEBEE;
}

.quick-add-item[data-status="today"] {
    border-left-color: var(--today-color);
    background: #FFF3E0;
}

.quick-add-item[data-status="soon"] {
    border-left-color: var(--soon-color);
    background: #E3F2FD;
}

.btn-add-quick {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: white;
    color: var(--primary-color);
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.btn-add-quick:hover {
    background: var(--primary-color);
    color: white;
}

.quick-add-info {
    flex: 1;
    min-width: 0;
}

.quick-add-info .product-name {
    display: block;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quick-add-info .product-shops {
    display: block;
    font-size: 13px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================
   Badges
   ======================================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-overdue {
    background: var(--overdue-color);
    color: white;
}

.badge-today {
    background: var(--today-color);
    color: white;
}

.badge-soon {
    background: var(--soon-color);
    color: white;
}

.badge-ok {
    background: var(--primary-color);
    color: white;
}

.badge-favorite {
    background: var(--warning-color);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
}

.badge-manual {
    background: #E3F2FD;
    color: #1976D2;
    font-size: 11px;
    padding: 2px 6px;
    margin-left: 6px;
}

.badge-inactive {
    background: var(--text-light);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
}

/* ========================================
   Shopping List
   ======================================== */
.shopping-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.shop-group {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.shop-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-color);
    cursor: pointer;
    user-select: none;
}

.shop-icon {
    font-size: 12px;
    transition: transform 0.2s;
}

.shop-header.collapsed .shop-icon {
    transform: rotate(-90deg);
}

.shop-name {
    font-weight: 600;
    flex: 1;
    font-size: 14px;
}

.shop-count {
    color: var(--text-light);
    font-size: 13px;
}

.shop-items {
    display: flex;
    flex-direction: column;
}

.shop-header.collapsed + .shop-items {
    display: none;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    transition: background 0.2s;
}

.shopping-item:hover {
    background: var(--bg-color);
}

.shopping-item.checked {
    background: var(--success-bg);
}

.shopping-item.checked .item-name {
    text-decoration: line-through;
    color: var(--text-light);
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    padding-left: 20px;
    user-select: none;
    margin: 0;
    flex-shrink: 0;
}

.checkbox-label input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    height: 18px;
    width: 18px;
    background-color: white;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s;
    transform: translateY(-50%);
}

.checkbox-label:hover .checkmark {
    border-color: var(--primary-color);
}

.checkbox-label input:checked ~ .checkmark {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 50%;
    margin-top: -5px;
    width: 4px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-label input:checked ~ .checkmark:after {
    display: block;
}

.item-name {
    flex: 1;
    font-size: 14px;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.6;
    transition: all 0.2s;
}

.btn-remove:hover {
    color: var(--danger-color);
    opacity: 1;
}

/* ========================================
   Complete Bar
   ======================================== */
.complete-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    padding: 10px 14px;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    z-index: 1000;
}

.complete-info {
    font-size: 13px;
    color: var(--text-light);
}

.complete-info strong {
    color: var(--primary-color);
    font-size: 14px;
}

/* Переключатель в нижней панели */
.switch-label-center {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.switch-label-center input {
    display: none;
}

.switch-label-center .switch {
    position: relative;
    width: 36px;
    height: 18px;
    background: #ccc;
    border-radius: 18px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.switch-label-center .switch:after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.switch-label-center input:checked + .switch {
    background: var(--primary-color);
}

.switch-label-center input:checked + .switch:after {
    transform: translateX(18px);
}

.catalog-buttons {
    display: flex;
    gap: 8px;
}

.catalog-buttons .btn {
    padding: 8px 14px;
    font-size: 13px;
    white-space: nowrap;
}

/* Кнопка в complete-bar (список покупок) */
.complete-bar .btn {
    padding: 8px 14px;
    font-size: 13px;
    white-space: nowrap;
}

/* ========================================
   Filter Tabs
   ======================================== */
.filter-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

/* Неактивные продукты */
.product-row.inactive {
    opacity: 0.6;
    background: #f9f9f9;
}

.product-row.inactive .product-name-small {
    color: #999;
}

.filter-tab {
    flex: 0 0 auto;
    padding: 8px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
}

.filter-tab.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ========================================
   Search Box
   ======================================== */
.search-box {
    margin-bottom: 16px;
}

.search-box input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    background: var(--card-bg);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* ========================================
   Catalog - Compact Product Row
   ======================================== */
.product-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    border: 1px solid var(--border-color);
    line-height: 1;
}

.product-row:hover {
    background: #fafafa;
}

.checkbox-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    padding-left: 20px;
    user-select: none;
    flex-shrink: 0;
    margin: 0;
}

.checkbox-small input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkmark-small {
    position: absolute;
    top: 50%;
    left: 0;
    height: 16px;
    width: 16px;
    background-color: white;
    border: 2px solid var(--border-color);
    border-radius: 3px;
    transition: all 0.2s;
    transform: translateY(-50%);
}

.checkbox-small:hover .checkmark-small {
    border-color: var(--primary-color);
}

.checkbox-small input:checked ~ .checkmark-small {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.checkmark-small:after {
    content: "";
    position: absolute;
    display: none;
    left: 5px;
    top: 50%;
    margin-top: -4px;
    width: 3px;
    height: 7px;
    border: solid white;
    border-width: 0 1px 1px 0;
    transform: rotate(45deg);
}

.checkbox-small input:checked ~ .checkmark-small:after {
    display: block;
}

.product-date-small {
    font-size: 13px;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    min-width: 75px;
}

.product-date-small.overdue {
    color: var(--overdue-color);
    font-weight: 600;
}

.product-date-small.today {
    color: var(--today-color);
    font-weight: 600;
}

.product-date-small.soon {
    color: var(--soon-color);
    font-weight: 600;
}

.badge-manual-small {
    font-size: 11px;
    cursor: pointer;
}

.product-name-small {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-buttons {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-edit-small {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    background: transparent;
    color: #666;
}

.btn-edit-small:hover {
    background: #f0f0f0;
}

.btn-add-small {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--primary-color);
    color: white;
}

.btn-add-small:hover {
    background: var(--primary-dark);
}

.btn-add-small.btn-added {
    background: var(--success-bg);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    cursor: default;
}

/* ========================================
   Catalog (old styles)
   ======================================== */
.products-list {
    display: flex;
    flex-direction: column;
}

/* ========================================
   Forms
   ======================================== */
.form {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    background: var(--card-bg);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group .hint {
    display: block;
    font-size: 13px;
    color: var(--text-light);
    margin-top: 4px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.radio-label input[type="radio"] {
    width: 18px;
    height: 18px;
}

.shops-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.shops-list .checkbox-label {
    padding-left: 32px;
}

.form-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 24px;
}

.inline-form {
    display: flex;
    gap: 8px;
}

.inline-form input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

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

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
}

.btn-block {
    width: 100%;
}

/* ========================================
   Alerts
   ======================================== */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-error {
    background: var(--error-bg);
    color: var(--danger-color);
    border: 1px solid #ffcdd2;
}

.alert-success {
    background: var(--success-bg);
    color: var(--primary-color);
    border: 1px solid #c8e6c9;
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.empty-state p {
    margin-bottom: 8px;
}

.empty-state .hint {
    font-size: 14px;
    opacity: 0.8;
}

/* ========================================
   Login Page
   ======================================== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.login-card h1 {
    text-align: center;
    margin-bottom: 8px;
    color: var(--text-color);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 24px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-form .form-group {
    margin-bottom: 0;
}

.login-form .form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-color);
    font-size: 14px;
}

.login-form .form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    background: var(--card-bg);
    color: var(--text-color);
    box-sizing: border-box;
}

.login-form .form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.login-hint {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 14px;
    color: var(--text-light);
}

.login-hint code {
    display: block;
    margin-top: 4px;
    padding: 8px;
    background: var(--bg-color);
    border-radius: 4px;
    font-family: monospace;
}

/* ========================================
   Shops Page
   ======================================== */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.shops-list-full {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shop-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.shop-card.inactive {
    opacity: 0.6;
}

.shop-card-form {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 8px;
}

.shop-card-info {
    flex: 1;
}

.shop-card-name {
    font-weight: 500;
}

.shop-card-actions {
    display: flex;
    gap: 4px;
}

.shop-card-actions .btn-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
    border: none;
    background: #f5f5f5;
    border-radius: 6px;
}

.shop-card-actions .btn-icon:hover {
    background: #e0e0e0;
}

.shop-card-actions .btn-icon.btn-danger:hover {
    background: #FFEBEE;
}

/* ========================================
   Modal
   ======================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-bottom: 16px;
}

/* ========================================
   Modal (Confirm Dialog)
   ======================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-confirm {
    text-align: center;
}

.modal-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.modal-message {
    font-size: 16px;
    color: var(--text-color);
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-buttons .btn {
    flex: 1;
    max-width: 120px;
}

/* ========================================
   Toast
   ======================================== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.3s;
    z-index: 1000;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   Responsive
   ======================================== */
@media (min-width: 481px) {
    .container {
        padding: 24px;
    }

    .header {
        padding: 8px 16px;
    }

    .header h1 {
        font-size: 22px;
    }
}

/* ========================================
   Animations
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(20px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

.section {
    animation: slideUp 0.3s ease-out;
}

.product-card {
    animation: fadeIn 0.2s ease-out;
}
