/* DOUGH_FORMULATOR — clean, mobile-first styles */

:root {
    --bg-primary: #f5f5f5;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent: #2563eb;
    --accent-light: #3b82f6;
    --accent-bg: #eff6ff;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --slider-track: #e0e0e0;
    --toggle-bg: #d1d5db;
    --results-bg: #f8fafc;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #15803d;
    --success-bg: #ecfdf5;
    --warn: #b45309;
    --warn-bg: #fffbeb;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-card: #1a1a1a;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --accent: #3b82f6;
    --accent-light: #60a5fa;
    --accent-bg: #1e3a5f;
    --border: #2a2a2a;
    --border-light: #262626;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);
    --slider-track: #333333;
    --toggle-bg: #404040;
    --results-bg: #141414;
    --danger: #f87171;
    --danger-bg: #2d1f1f;
    --success: #4ade80;
    --success-bg: #14291c;
    --warn: #fbbf24;
    --warn-bg: #2d2412;
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* ---------- Layout ---------- */

.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 16px 8px;
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 100;
}

.app-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-card);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    transition: transform 0.15s;
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.calculator {
    flex: 1;
    padding: 8px 16px calc(96px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---------- Cards ---------- */

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.card-header.toggle-row {
    margin-bottom: 0;
    cursor: pointer;
}

.card-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.card-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: -4px 0 10px;
}

.card-detail {
    display: flex;
    justify-content: space-between;
    padding-top: 12px;
    margin-top: 12px;
    border-top: 1px solid var(--border-light);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.card-detail span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

.card-warning {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.4;
}

.card-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.negative {
    color: var(--danger) !important;
}

/* ---------- Value pills (tap to edit) ---------- */

.value-btn {
    font: inherit;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-bg);
    border: 1.5px solid transparent;
    border-radius: 999px;
    padding: 2px 14px;
    min-height: 40px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, transform 0.1s;
}

.value-btn:hover {
    border-color: var(--accent);
}

.value-btn:active {
    transform: scale(0.97);
}

.value-btn.small {
    font-size: 1.1rem;
    min-height: 34px;
    padding: 0 12px;
    min-width: 84px;
}

.value-input {
    width: 124px;
    font: inherit;
    font-size: 1.25rem;
    font-weight: 600;
    text-align: right;
    padding: 4px 10px;
    border: 2px solid var(--accent);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text-primary);
    outline: none;
    -moz-appearance: textfield;
    appearance: textfield;
}

.value-input::-webkit-outer-spin-button,
.value-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ---------- Recipe name & notes ---------- */

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

.recipe-name-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
}

.recipe-name-input::placeholder {
    color: var(--text-muted);
}

.recipe-status {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 4px 8px;
    background: var(--border-light);
    border-radius: 6px;
}

.recipe-status[data-state="saved"] {
    color: var(--success);
    background: var(--success-bg);
}

.recipe-status[data-state="modified"] {
    color: var(--warn);
    background: var(--warn-bg);
}

.notes-card {
    padding: 10px 16px;
}

.notes-input {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    resize: vertical;
    min-height: 44px;
    outline: none;
}

.notes-input::placeholder {
    color: var(--text-muted);
}

/* ---------- Sliders & steppers ---------- */

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider {
    flex: 1;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--slider-track);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    margin: 10px 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 26px;
    height: 26px;
    background: var(--accent);
    border: 3px solid var(--bg-card);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border: 3px solid var(--bg-card);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.adjust-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-primary);
    border-radius: 10px;
    font-size: 1.35rem;
    font-weight: 500;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: background 0.1s, transform 0.1s;
}

.adjust-btn:active,
.adjust-btn.pressed {
    background: var(--border);
    transform: scale(0.94);
}

.adjust-btn.small {
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
}

/* ---------- Toggles ---------- */

.toggle {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: 52px;
    height: 28px;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: var(--toggle-bg);
    border-radius: 28px;
    transition: background 0.25s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.25s;
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.toggle.small {
    width: 44px;
    height: 24px;
}

.toggle.small .toggle-slider::before {
    height: 18px;
    width: 18px;
}

.toggle.small input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.inline-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--text-secondary);
    cursor: pointer;
}

/* ---------- Flour split ---------- */

.flour-split {
    display: flex;
    justify-content: space-around;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

.flour-split-item {
    text-align: center;
}

.flour-split-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.flour-split-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent);
}

/* ---------- Results ---------- */

.results-card {
    background: var(--results-bg);
    border: 2px solid var(--accent);
}

.results-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.results-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.value-btn.results-total {
    font-size: 1.9rem;
    min-height: 48px;
}

.results-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 2px 0 12px;
}

.results-divider {
    height: 1px;
    background: var(--border);
    margin-bottom: 14px;
}

.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.result-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.result-label {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.result-value {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ---------- Baking ---------- */

.baking-row {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
}

.baking-item {
    flex: 1;
    min-width: 0;
}

.baking-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.baking-input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 4px;
}

.temp-unit-toggle {
    text-align: center;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}

.text-btn {
    background: none;
    border: none;
    color: var(--accent);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
}

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

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px;
    border: 1px solid transparent;
    border-radius: 10px;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s, background 0.15s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:active {
    background: var(--accent-light);
}

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

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

.btn-small {
    padding: 10px 16px;
    font-size: 0.85rem;
}

.actions-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-full {
    grid-column: 1 / -1;
}

/* ---------- Saved recipes ---------- */

.saved-recipes-list {
    margin-bottom: 14px;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
    font-size: 0.9rem;
}

.saved-recipe-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border: 1px solid transparent;
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
}

.saved-recipe-item:last-child {
    margin-bottom: 0;
}

.saved-recipe-item:active {
    background: var(--border-light);
}

.saved-recipe-item.open {
    border-color: var(--accent);
}

.saved-recipe-info {
    flex: 1;
    min-width: 0;
}

.saved-recipe-name {
    font-weight: 600;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-recipe-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.delete-btn {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.recipes-actions {
    display: flex;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

.recipes-actions .btn {
    flex: 1;
}

/* ---------- Summary bar ---------- */

.summary-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    display: flex;
    justify-content: center;
    padding: 0 12px calc(10px + var(--safe-bottom));
    pointer-events: none;
}

.summary-bar-inner {
    pointer-events: auto;
    width: 100%;
    max-width: 456px;
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 8px 6px;
}

.summary-item {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.summary-item + .summary-item {
    border-left: 1px solid var(--border-light);
}

.summary-label {
    display: block;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.summary-value {
    font-size: 0.95rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.summary-total .summary-value {
    color: var(--accent);
    font-size: 1.05rem;
}

/* ---------- Modal ---------- */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 1.2rem;
    margin-bottom: 14px;
}

.modal-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-bottom: 14px;
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
    min-width: 100px;
}

/* ---------- Footer & toast ---------- */

.app-footer {
    text-align: center;
    padding: 0 16px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.app-footer a {
    color: inherit;
}

.toast {
    position: fixed;
    bottom: calc(86px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.25s;
    pointer-events: none;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
}

/* ---------- Larger screens ---------- */

@media (min-width: 600px) {
    .app {
        max-width: 520px;
    }

    .summary-bar-inner {
        max-width: 496px;
    }

    .card {
        padding: 18px 20px;
    }
}

/* ---------- Accessibility ---------- */

.slider:focus-visible,
.btn:focus-visible,
.value-btn:focus-visible,
.adjust-btn:focus-visible,
.icon-btn:focus-visible,
.text-btn:focus-visible,
.saved-recipe-item:focus-visible,
.delete-btn:focus-visible,
.toggle input:focus-visible + .toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}
