/**
 * Генератор таблиц-копилок — MOBILE FIRST
 * Минимальная ширина touch-target: 44px
 */

/* Базовые стили — мобильный */
.ptg-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1a1a1a;
    max-width: 100%;
    padding: 0.75rem;
    box-sizing: border-box;
}

.ptg-presets-title {
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
}

.ptg-presets-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

/* Кнопки пресетов — минимум 44px высота для touch */
.ptg-preset-btn {
    display: inline-block;
    padding: 0.625rem 0.875rem;
    min-height: 44px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #2563eb;
    background: #eff6ff;
    border: 2px solid #93c5fd;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    white-space: nowrap;
    box-sizing: border-box;
}

.ptg-preset-btn:hover,
.ptg-preset-btn:focus,
.ptg-preset-btn:active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
    outline: none;
}

/* Форма */
.ptg-form {
    margin-bottom: 1.25rem;
}

.ptg-form-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.ptg-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.ptg-field label {
    font-weight: 500;
    font-size: 0.9rem;
}

.ptg-field input,
.ptg-field select {
    min-height: 48px;
    padding: 0.75rem 1rem;
    font-size: 16px; /* предотвращает zoom на iOS */
    border: 2px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
}

.ptg-field input:focus,
.ptg-field select:focus {
    border-color: #2563eb;
    outline: none;
}

.ptg-field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%234b5563' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

/* Кнопка "Создать" */
.ptg-submit {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: #059669;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ptg-submit:hover,
.ptg-submit:focus {
    background: #047857;
    outline: none;
}

.ptg-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Статистика */
.ptg-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: #f0fdf4;
    border-radius: 8px;
    border: 1px solid #bbf7d0;
}

.ptg-stat {
    margin: 0;
    font-size: 0.95rem;
}

.ptg-stat-label {
    opacity: 0.85;
}

/* Кнопки действий */
.ptg-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.ptg-action {
    flex: 1 1 auto;
    min-width: 120px;
    min-height: 48px;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ptg-action:hover,
.ptg-action:focus {
    background: #1d4ed8;
    outline: none;
}

.ptg-download-png { background: #7c3aed; }
.ptg-download-png:hover { background: #6d28d9; }
.ptg-print { background: #64748b; }
.ptg-print:hover { background: #475569; }

/* Предпросмотр таблицы — на всю ширину поста */
.ptg-preview-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0;
}

.ptg-preview {
    width: 100%;
    display: block;
    box-sizing: border-box;
    padding: 1rem;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Форматы: клетки */
.ptg-table-cells {
    display: grid;
    gap: 2px;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
}

.ptg-cell {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    border: 2px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    box-sizing: border-box;
}

.ptg-cell.ptg-checked {
    background: #dcfce7;
    border-color: #22c55e;
    color: #166534;
}

/* Форматы: список */
.ptg-table-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ptg-table-list .ptg-cell {
    width: 100%;
    min-width: 120px;
    height: 40px;
    justify-content: flex-start;
    padding-left: 0.75rem;
}

/* Форматы: кружочки */
.ptg-table-circles {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
}

.ptg-table-circles .ptg-cell {
    width: 44px;
    height: 44px;
    border-radius: 50%;
}

/* Заголовок таблицы */
.ptg-table-title {
    text-align: center;
    font-weight: 700;
    font-size: 1rem;
    margin: 0 0 1rem 0;
}

/* Desktop: чуть больше отступы и размеры */
@media (min-width: 640px) {
    .ptg-wrapper {
        padding: 1.25rem;
    }

    .ptg-form-grid {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .ptg-field {
        flex: 1 1 140px;
    }

    .ptg-submit {
        width: auto;
        min-width: 200px;
    }

    .ptg-cell {
        width: 52px;
        height: 52px;
        font-size: 0.8rem;
    }

    .ptg-table-cells {
        grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    }
}

/* Печать */
@media print {
    .ptg-presets, .ptg-form, .ptg-stats, .ptg-actions, .ptg-preview-wrap {
        display: none !important;
    }

    .ptg-preview {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    .ptg-wrapper {
        padding: 0;
    }

    .ptg-cell.ptg-checked {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
