/**
 * Neatbase Forms — Stylesheet
 *
 * Clean, minimal, mobile-first design. No framework dependencies.
 * System font stack for native feel across platforms.
 */

/*
 * --form-theme-color drives the "brand action" surfaces on the form:
 * submit button, selected tag pills, and the success page's submit-another
 * link.
 *
 * Default is Apple blue (light) / Apple blue dark (dark). When a form has a
 * custom button_color, templates/form.php and templates/success.php override
 * --form-theme-color via an inline <style> block on :root, which wins by
 * source order regardless of media query.
 *
 * Universal-semantic colors (toggle ON green, star gold, percent bar in-progress
 * + complete, destructive red) are NOT themable. Focus borders + glow on inputs
 * also stay Apple blue intentionally — "this is the active input" is a system
 * semantic, not a brand one. The percent bar's fill stays Apple blue too — a
 * progress indicator should read as a system control.
 */
:root {
    --form-theme-color: #007aff;
}

@media (prefers-color-scheme: dark) {
    :root {
        --form-theme-color: #0a84ff;
    }
}

/* Reset & Base */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif, "Apple Color Emoji",
                 "Segoe UI Emoji";
    color: #1a1a1a;
    background: #f5f5f5;
    line-height: 1.5;
    min-height: 100vh;
}

/* Layout */

.form-container {
    max-width: 560px;
    margin: 0 auto;
    padding: 40px 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.form-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    flex: 1 0 auto;
}

/* Header */

.form-header {
    padding: 36px 28px 24px;
    text-align: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.form-logo {
    max-width: 72px;
    max-height: 72px;
    border-radius: 16px;
    margin-bottom: 16px;
    object-fit: contain;
}

.form-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: #111;
}

.form-description {
    margin-top: 8px;
    color: #1a1a1a;
    font-size: 0.938rem;
    line-height: 1.6;
}

/*
 * Compact form layout.
 *
 * Auto-applied by templates/form.php when the form has 1–4 input fields AND
 * the description is empty OR ≤ 60 characters. The header switches from a
 * vertical, centered stack to a horizontal row (logo + title/subtitle), and
 * inputs are spaced more tightly. Description is single-line with ellipsis
 * as a safety net for borderline descriptions.
 */

.form-card--compact .form-header {
    display: flex;
    align-items: center;
    gap: 16px;
    text-align: left;
    padding: 24px 28px 20px;
}

.form-card--compact .form-logo {
    margin-bottom: 0;
    max-width: 46px;
    max-height: 46px;
    border-radius: 10px;
    flex-shrink: 0;
}

.form-card--compact .form-header-text {
    flex: 1;
    min-width: 0;
}

.form-card--compact .form-title {
    font-size: 1.25rem;
    line-height: 1.2;
}

.form-card--compact .form-description {
    margin-top: 0;
    font-size: 0.875rem;
    line-height: 1.3;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.form-card--compact .form-body {
    padding: 20px 28px 24px;
}

.form-card--compact .form-field,
.form-card--compact .form-field--toggle {
    margin-bottom: 14px;
}

/* Error state */

.form-error {
    padding: 28px;
    text-align: center;
    color: #666;
    font-size: 0.938rem;
}

/* Form body */

.form-body {
    padding: 28px 28px 32px;
}

/* Form fields */

.form-field {
    margin-bottom: 22px;
}

.form-field label {
    display: block;
    font-size: 0.813rem;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.form-field input[type="text"],
.form-field input[type="email"],
.form-field input[type="tel"],
.form-field input[type="url"],
.form-field input[type="number"],
.form-field input[type="date"],
.form-field input[type="datetime-local"],
.form-field textarea,
.form-field .form-select {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.938rem;
    font-family: inherit;
    border: 1px solid #d5d5d5;
    border-radius: 10px;
    background: #fff;
    color: #1a1a1a;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-field .form-select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%23888' d='M2 4l4 4 4-4z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
    cursor: pointer;
}

/* Focus state stays Apple blue regardless of the form's theme color —
   "this is the active input" is a system semantic, not a brand one. */
.form-field input:focus,
.form-field textarea:focus,
.form-field .form-select:focus {
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.form-field textarea {
    resize: vertical;
    min-height: 80px;
}

.form-field input::placeholder,
.form-field textarea::placeholder {
    color: #b0b0b0;
}

/* Currency input with prefix */

.input-with-prefix {
    display: flex;
    align-items: stretch;
}

.input-prefix {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 0.938rem;
    font-weight: 600;
    color: #888;
    background: #f5f5f5;
    border: 1px solid #d5d5d5;
    border-right: none;
    border-radius: 10px 0 0 10px;
}

.input-with-prefix input {
    border-radius: 0 10px 10px 0 !important;
    flex: 1;
}

/* Star rating */

.star-rating {
    display: flex;
    gap: 4px;
}

.star-rating .star {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: #d5d5d5;
    transition: color 0.1s, transform 0.1s;
    border-radius: 4px;
}

.star-rating .star:hover,
.star-rating .star.active {
    color: #f5a623;
}

.star-rating .star:active {
    transform: scale(0.9);
}

.star-rating .star svg {
    display: block;
    fill: currentColor;
}

/* Toggle switch */

.form-field--toggle {
    margin-bottom: 22px;
}

.toggle-label {
    display: flex !important;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-weight: 500 !important;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}

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

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #d5d5d5;
    border-radius: 26px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #34c759;
}

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

.toggle-switch input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.25);
}

/* Tags */

.tag-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-option {
    cursor: pointer;
}

.tag-option input {
    display: none;
}

.tag-chip {
    display: inline-block;
    padding: 5px 12px;
    font-size: 0.813rem;
    border: 1px solid #d5d5d5;
    border-radius: 980px;
    color: #555;
    background: #fff;
    transition: all 0.15s;
    user-select: none;
}

/*
 * Selected tag chip — Apple system blue default when no explicit
 * `.tag-color-*` class is applied. Matches the iOS app's `Color.accentColor`
 * fallback for tags without `:color` in availableTags. Per-color classes
 * below override via higher specificity.
 */
.tag-option input:checked + .tag-chip {
    background: #007AFF;
    border-color: #007AFF;
    color: #fff;
}

/*
 * Per-tag colors. Each tag chip gets a `.tag-color-<name>` class server-side
 * via parseTagOptions() in field_renderer.php WHEN an explicit color is set.
 * The hex values here MUST match Swift's TagColor.color so the iOS app and
 * the web form render identical pixels. Selected state fills with the tag's
 * color; unselected stays neutral so a long option list isn't a rainbow.
 */
.tag-option input:checked + .tag-chip.tag-color-red    { background: #FF3B30; border-color: #FF3B30; color: #fff; }
.tag-option input:checked + .tag-chip.tag-color-orange { background: #FF9500; border-color: #FF9500; color: #fff; }
.tag-option input:checked + .tag-chip.tag-color-yellow { background: #FFCC00; border-color: #FFCC00; color: #fff; }
.tag-option input:checked + .tag-chip.tag-color-green  { background: #34C759; border-color: #34C759; color: #fff; }
.tag-option input:checked + .tag-chip.tag-color-blue   { background: #007AFF; border-color: #007AFF; color: #fff; }
.tag-option input:checked + .tag-chip.tag-color-purple { background: #AF52DE; border-color: #AF52DE; color: #fff; }
.tag-option input:checked + .tag-chip.tag-color-pink   { background: #FF2D55; border-color: #FF2D55; color: #fff; }

.tag-chip:hover {
    border-color: #b0b0b0;
}

/* Image upload */

.image-upload input[type="file"] {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.875rem;
    font-family: inherit;
    border: 1.5px dashed #d5d5d5;
    border-radius: 10px;
    background: #fafafa;
    cursor: pointer;
}

.image-upload input[type="file"]:hover {
    border-color: #b0b0b0;
}

.image-preview {
    margin-top: 10px;
    position: relative;
    display: inline-block;
}

.image-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 10px;
    object-fit: contain;
}

.remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: #ff3b30;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Section divider & description */

.section-divider {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    margin: 28px 0;
}

.section-description {
    color: #1a1a1a;
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 16px;
    padding: 0 2px;
}

.section-heading {
    color: #1a1a1a;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.4;
    /* Closer to the field below than to the field above — reads as a group label */
    margin-top: 24px;
    margin-bottom: 4px;
    padding: 0 2px;
}

/* Submit button */

.submit-button {
    display: block;
    width: 100%;
    padding: 14px;
    margin-top: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: var(--form-theme-color);
    border: none;
    border-radius: 980px;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}

.submit-button:hover {
    opacity: 0.88;
}

.submit-button:active {
    transform: scale(0.98);
}

/* Success page */

.success-card {
    text-align: center;
    padding: 48px 28px;
}

.success-icon {
    color: #34c759;
    margin-bottom: 20px;
}

.success-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.success-card p {
    color: #666;
    font-size: 0.938rem;
    margin-bottom: 24px;
}

.submit-another-link {
    display: inline-block;
    color: var(--form-theme-color);
    text-decoration: none;
    font-size: 0.938rem;
    font-weight: 500;
}

.submit-another-link:hover {
    text-decoration: underline;
}

/* Honeypot (anti-spam) */

.form-field-hp {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
}

/* Footer */

.form-footer {
    text-align: center;
    padding: 20px 0 8px;
    flex-shrink: 0;
}

.form-footer a {
    color: #777;
    text-decoration: none;
    font-size: 0.813rem;
}

.form-footer a:hover {
    color: #555;
}

/* Dark mode */

@media (prefers-color-scheme: dark) {
    body {
        color: #e5e5e5;
        background: #1b1b1b;
    }

    .form-card {
        background: #212121;
        box-shadow: none;
        border: 1px solid rgba(255, 255, 255, 0.06);
    }

    .form-header {
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .form-title {
        color: #f5f5f5;
    }

    .form-description {
        color: #e5e5e5;
    }

    .form-card--compact .form-description {
        color: #aaa;
    }

    .form-error {
        color: #888;
    }

    .form-field label {
        color: #e5e5e5;
    }

    .form-field input[type="text"],
    .form-field input[type="email"],
    .form-field input[type="tel"],
    .form-field input[type="url"],
    .form-field input[type="number"],
    .form-field input[type="date"],
    .form-field input[type="datetime-local"],
    .form-field textarea,
    .form-field .form-select {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.05);
        color: #e5e5e5;
    }

    .form-field .form-select {
        background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%23aaa' d='M2 4l4 4 4-4z'/></svg>");
        background-repeat: no-repeat;
        background-position: right 12px center;
    }

    .form-field input:focus,
    .form-field textarea:focus,
    .form-field .form-select:focus {
        border-color: #0a84ff;
        box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
        background: rgba(255, 255, 255, 0.08);
    }

    .form-field input::placeholder,
    .form-field textarea::placeholder {
        color: #484848;
    }

    .input-prefix {
        color: #888;
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.12);
    }

    .star-rating .star {
        color: #3a3a3a;
    }

    .toggle-slider {
        background: #3a3a3a;
    }

    .tag-chip {
        border-color: rgba(255, 255, 255, 0.12);
        color: #888;
        background: rgba(255, 255, 255, 0.05);
    }

    /* Apple dark-mode system blue fallback for tags without an explicit
       `.tag-color-*` class. */
    .tag-option input:checked + .tag-chip {
        background: #0A84FF;
        border-color: #0A84FF;
        color: #fff;
    }

    /* Dark-mode tag colors — slightly brighter Apple sRGB values. Must match
       Swift's dark-mode plan if/when we add dark-aware tag colors there. */
    .tag-option input:checked + .tag-chip.tag-color-red    { background: #FF453A; border-color: #FF453A; color: #fff; }
    .tag-option input:checked + .tag-chip.tag-color-orange { background: #FF9F0A; border-color: #FF9F0A; color: #fff; }
    .tag-option input:checked + .tag-chip.tag-color-yellow { background: #FFD60A; border-color: #FFD60A; color: #fff; }
    .tag-option input:checked + .tag-chip.tag-color-green  { background: #30D158; border-color: #30D158; color: #fff; }
    .tag-option input:checked + .tag-chip.tag-color-blue   { background: #0A84FF; border-color: #0A84FF; color: #fff; }
    .tag-option input:checked + .tag-chip.tag-color-purple { background: #BF5AF2; border-color: #BF5AF2; color: #fff; }
    .tag-option input:checked + .tag-chip.tag-color-pink   { background: #FF375F; border-color: #FF375F; color: #fff; }

    .tag-chip:hover {
        border-color: rgba(255, 255, 255, 0.2);
    }

    .image-upload input[type="file"] {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.05);
        color: #e5e5e5;
    }

    .image-upload input[type="file"]:hover {
        border-color: rgba(255, 255, 255, 0.2);
    }

    .section-divider {
        border-top-color: rgba(255, 255, 255, 0.08);
    }

    .section-description {
        color: #e5e5e5;
    }

    .section-heading {
        color: #f5f5f5;
    }

    /* .submit-button background comes from var(--form-theme-color), see :root */

    .success-card p {
        color: #888;
    }

    /* .submit-another-link color comes from var(--form-theme-color), see :root */

    .form-footer a {
        color: #777;
    }

    .form-footer a:hover {
        color: #999;
    }
}

/* Duration input */

.duration-parts {
    display: flex;
    gap: 8px;
}

.duration-part {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}

.duration-part input {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    font-size: 0.938rem;
    border: 1px solid #d5d5d5;
    border-radius: 10px;
    background: #fff;
    text-align: center;
}

.duration-part input:focus {
    border-color: #007aff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.duration-part span {
    font-size: 0.875rem;
    color: #888;
    font-weight: 500;
    flex-shrink: 0;
}

/* Percent input */

.input-with-suffix {
    display: flex;
    align-items: stretch;
}

.input-with-suffix input {
    border-radius: 10px 0 0 10px !important;
    flex: 1;
}

.input-suffix {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 0.938rem;
    font-weight: 600;
    color: #888;
    background: #f5f5f5;
    border: 1px solid #d5d5d5;
    border-left: none;
    border-radius: 0 10px 10px 0;
}

.percent-bar {
    height: 4px;
    background: #eee;
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.percent-bar-fill {
    height: 100%;
    width: 0%;
    background: #007aff;
    border-radius: 2px;
    transition: width 0.2s ease, background-color 0.2s ease;
}

.percent-bar-fill.complete {
    background: #34c759;
}

/* Color input */

.color-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-input .color-picker {
    width: 44px;
    height: 44px;
    padding: 2px;
    border: 1px solid #d5d5d5;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

.color-input input[type="text"] {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    .duration-part input {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.05);
        color: #e5e5e5;
    }

    .duration-part input:focus {
        border-color: #0a84ff;
        box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
        background: rgba(255, 255, 255, 0.08);
    }

    .duration-part span {
        color: #888;
    }

    .input-suffix {
        color: #888;
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.12);
    }

    .percent-bar {
        background: rgba(255, 255, 255, 0.08);
    }

    .percent-bar-fill {
        background: #0a84ff;
    }

    .percent-bar-fill.complete {
        background: #30d158;
    }

    .color-input .color-picker {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.05);
    }
}

/* Responsive */

@media (max-width: 600px) {
    .form-container {
        padding: 16px 12px;
    }

    .form-header {
        padding: 24px 20px 20px;
    }

    .form-body {
        padding: 20px;
    }

    .form-title {
        font-size: 1.25rem;
    }

    .form-card--compact .form-header {
        padding: 18px 18px 16px;
        gap: 12px;
    }

    .form-card--compact .form-body {
        padding: 16px 18px 18px;
    }

    .form-card--compact .form-title {
        font-size: 1.125rem;
    }

    .form-card--compact .form-logo {
        max-width: 36px;
        max-height: 36px;
    }

    .success-card {
        padding: 36px 20px;
    }
}
