/* iPhone/iOS Safari optimized styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #f97316;
    --secondary: #6b7280;
    --success: #10b981;
    --danger: #ef4444;
    --light: #f9fafb;
    --light-gray: #f3f4f6;
    --border: #e5e7eb;
    --text: #111827;
    --text-light: #6b7280;
    --safe-top: max(env(safe-area-inset-top), 12px);
    --safe-bottom: max(env(safe-area-inset-bottom), 12px);
}

html, body {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
    background: white;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-user-select: none;
    user-select: none;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Header */
.app-header {
    background: white;
    border-bottom: 1px solid var(--border);
    padding-top: var(--safe-top);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.app-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    flex-grow: 1;
}

.app-nav {
    display: flex;
    gap: 8px;
}

.nav-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--light-gray);
    color: var(--text);
    transition: all 0.2s;
    -webkit-user-select: none;
    user-select: none;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.nav-btn:active {
    opacity: 0.7;
}

/* Main content */
.app-content {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--safe-bottom);
}

.dynamic-content {
    min-height: 100%;
}

/* Recipe List */
.recipe-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
}

.recipe-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.recipe-card:active {
    background: var(--light-gray);
}

.recipe-card-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, var(--light-gray), var(--border));
    object-fit: cover;
}

.recipe-card-image.no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    font-size: 48px;
}

.recipe-card-content {
    padding: 12px;
}

.recipe-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.recipe-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.recipe-difficulty {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    background: var(--light-gray);
    color: var(--text-light);
}

/* Difficulty levels: 1-3 easy, 4-6 medium, 7-10 hard */
.recipe-difficulty.easy,
.recipe-difficulty.level-1,
.recipe-difficulty.level-2,
.recipe-difficulty.level-3 {
    background: #d1fae5;
    color: #065f46;
}

.recipe-difficulty.medium,
.recipe-difficulty.level-4,
.recipe-difficulty.level-5,
.recipe-difficulty.level-6 {
    background: #fef3c7;
    color: #92400e;
}

.recipe-difficulty.hard,
.recipe-difficulty.level-7,
.recipe-difficulty.level-8,
.recipe-difficulty.level-9,
.recipe-difficulty.level-10 {
    background: #fee2e2;
    color: #991b1b;
}

.recipe-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    display: inline-block;
    padding: 4px 8px;
    background: var(--light-gray);
    border-radius: 12px;
    font-size: 11px;
    color: var(--secondary);
    font-weight: 500;
    -webkit-user-select: none;
    user-select: none;
}

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

/* Filters */
.filters-section {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--light);
}

.search-box {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 12px;
    font-family: inherit;
    color: var(--text);
    background: white;
    -webkit-appearance: none;
    appearance: none;
}

.search-box:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.tags-filter {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 0 8px 0;
}

.tag-filter-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    background: white;
    color: var(--secondary);
    cursor: pointer;
    transition: all 0.2s;
    -webkit-user-select: none;
    user-select: none;
    min-height: 36px;
    font-weight: 500;
}

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

/* Recipe Detail */
.recipe-detail {
    padding: 12px;
}

.recipe-header {
    margin-bottom: 16px;
}

.recipe-detail-image {
    width: 100%;
    height: 300px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 16px;
}

.recipe-detail-image.no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--light-gray);
    color: var(--text-light);
    font-size: 48px;
}

.recipe-detail-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text);
}

.recipe-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.info-item {
    background: var(--light-gray);
    padding: 12px;
    border-radius: 8px;
}

.info-label {
    font-size: 12px;
    color: var(--text-light);
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.info-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.recipe-section {
    margin-bottom: 16px;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.section-content {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

.video-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.video-link:active {
    opacity: 0.7;
}

.recipe-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-user-select: none;
    user-select: none;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

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

.btn-primary:active {
    opacity: 0.8;
}

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

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

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

.btn-danger:active {
    opacity: 0.8;
}

.btn-small {
    padding: 8px 12px;
    font-size: 14px;
    min-height: 36px;
    flex: auto;
}

/* Recipe Form */
.recipe-form {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.form-input, .form-textarea, .form-select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    background: white;
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
    font-family: inherit;
}

.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23111827' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 36px;
}

.difficulty-slider-container {
    display: flex;
    gap: 12px;
    align-items: center;
}

.form-range {
    flex: 1;
    height: 8px;
    border-radius: 5px;
    background: var(--light-gray);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.form-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.difficulty-value {
    min-width: 30px;
    text-align: center;
    font-weight: 600;
    color: var(--primary);
    font-size: 16px;
}

.tags-input {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
}

.tags-input input {
    flex: 1;
    min-width: 60px;
    border: none;
    outline: none;
    font-size: 14px;
    font-family: inherit;
}

.tag-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    font-size: 12px;
}

.tag-remove {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    display: flex;
    align-items: center;
}

/* Photo Upload */
.photo-upload {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 24px 12px;
    text-align: center;
    cursor: pointer;
    background: var(--light);
    transition: all 0.2s;
}

.photo-upload:active {
    background: var(--light-gray);
}

.photo-preview {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    margin-top: 12px;
}

.file-input {
    display: none;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    padding: 24px;
    text-align: center;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state-text {
    font-size: 14px;
    color: var(--text-light);
    margin-bottom: 16px;
}

/* Loading spinner */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--light-gray);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: var(--safe-bottom);
    left: 12px;
    right: 12px;
    padding: 12px 16px;
    background: var(--text);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1001;
    animation: slideUp 0.3s ease;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

.toast.hidden {
    display: none;
}

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

/* Utility classes */
.hidden {
    display: none;
}

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

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }

/* Back button */
.back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    -webkit-user-select: none;
    user-select: none;
    margin-bottom: 12px;
}

.back-btn:active {
    opacity: 0.7;
}

