/* ==========================================================================
   COREIDON.AI — Feedback MVP
   Mobile-first: base styles render at 360px; min-width breakpoints layer up.
   Design tokens copied verbatim from projex (frontend/styles.css).
   ========================================================================== */

/* --- Tokens: light theme --------------------------------------------------- */
:root {
    /* Brand surfaces — light */
    --bg-main: #FFFFFF;
    --bg-secondary: #F8F5F0;
    --bg-elevated: #FFFFFF;
    --subtle-bg: #F3F4F6;

    /* Text */
    --text-primary: #000000;
    --text-secondary: #2B303B;
    --text-muted: rgba(43, 48, 59, 0.6);

    /* Brand accents */
    --accent: #091C3A;          /* Navy — primary CTA */
    --accent-cyan: #0284C7;     /* Expressive accent — data, links, focus */
    --accent-glow: rgba(2, 132, 199, 0.18);

    /* Borders */
    --border-color: #E5E7EB;
    --border-subtle: #E5E7EB;
    --border-strong: #D1D5DB;

    /* Inputs */
    --input-bg: #FFFFFF;

    /* Interaction tints */
    --hover-bg: rgba(9, 28, 58, 0.04);
    --active-bg: rgba(2, 132, 199, 0.08);

    /* Semantic */
    --danger: #DC2626;
    --danger-soft: rgba(220, 38, 38, 0.10);
    --success: #16A34A;
    --warning: #F59E0B;

    /* Shadows */
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    --card-shadow-hover: 0 6px 16px rgba(9, 28, 58, 0.08);

    /* Motion */
    --ease-snappy: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --motion-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Radii */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 10px;
    --radius-pill: 999px;

    /* Fonts */
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-head: 'Space Grotesk', 'Inter', sans-serif;
}

/* --- Tokens: dark theme ---------------------------------------------------- */
body.dark-theme {
    --bg-main: #0A1220;
    --bg-secondary: #2B303B;
    --bg-elevated: #243447;
    --subtle-bg: #121B2A;

    --text-primary: #FFFFFF;
    --text-secondary: rgba(248, 245, 240, 0.75);
    --text-muted: rgba(248, 245, 240, 0.45);

    --accent: #091C3A;
    --accent-cyan: #38BDF8;
    --accent-glow: rgba(56, 189, 248, 0.22);

    --border-color: #2D3D52;
    --border-subtle: #1F2A3C;
    --border-strong: #2D3D52;

    --input-bg: #2B303B;

    --hover-bg: rgba(248, 245, 240, 0.04);
    --active-bg: rgba(56, 189, 248, 0.10);

    --danger: #FB7185;
    --danger-soft: rgba(251, 113, 133, 0.12);
    --success: #34D399;

    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.40);
    --card-shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.55);
}

/* --- Reset & base ---------------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.3s, color 0.3s;
    color-scheme: light;
}
body.dark-theme { color-scheme: dark; }

::selection { background: var(--accent-glow); }

::placeholder { color: var(--text-muted); opacity: 1; }

button { font-family: inherit; }

.hidden { display: none !important; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Typography ------------------------------------------------------------ */
h1, h2, h3, .logo-text, .app-name, .question-label, .field-label {
    font-family: var(--font-head);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

h1 {
    font-size: clamp(1.1rem, 2.4vw + 0.6rem, 1.6rem);
    text-transform: uppercase;
    letter-spacing: -0.01em;
}

.form-intro {
    color: var(--text-secondary);
    font-size: clamp(0.85rem, 0.5vw + 0.78rem, 0.95rem);
    line-height: 1.55;
}

/* --- Layout ---------------------------------------------------------------- */
.page {
    max-width: 680px;
    margin: 0 auto;
    padding: 16px;
    /* Final guard against sideways scroll. .page is a sibling of the sticky
       header (not its ancestor), so clipping here never affects stickiness. */
    overflow-x: hidden;
}

.glass-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px;
}
body.dark-theme .glass-panel { background: var(--subtle-bg); }

.form-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: var(--card-shadow);
    /* Long words / e-mails / URLs wrap instead of widening the layout. */
    overflow-wrap: break-word;
}

/* --- Header / top bar ------------------------------------------------------ */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-subtle);
    padding: 12px 16px;
    transition: background 0.3s, border-color 0.3s;
}

.top-bar-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    max-width: 1240px;
    margin: 0 auto;
}

.brand-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-identity .logo {
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-identity .logo svg { width: 100%; height: 100%; display: block; }

.logo-text {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-primary);
}

.app-name {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-cyan);
    padding-left: 10px;
    margin-left: 4px;
    border-left: 1px solid var(--border-strong);
    /* Hidden on the smallest screens to keep the header to one tidy row;
       revealed from sm (640px). */
    display: none;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Icon button (shared) -------------------------------------------------- */
.icon-btn {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    padding: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--ease-snappy);
}
.icon-btn:hover {
    background: var(--hover-bg);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}
.icon-btn:focus-visible {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.icon-btn svg { width: 20px; height: 20px; }

.icon-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* --- Language selector (dropdown) ------------------------------------------ */
.lang-selector { position: relative; }
.lang-toggle {
    /* inherits border/radius/hover/focus from .icon-btn; widen for label */
    width: auto;
    padding: 0 10px;
    gap: 6px;
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.lang-caret {
    width: 14px;
    height: 14px;
    transition: transform var(--motion-fast);
}
.lang-toggle[aria-expanded="true"] .lang-caret { transform: rotate(180deg); }

.lang-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 120px;
    list-style: none;
    margin: 0;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow-hover);
    z-index: 20;
}
.lang-menu li { list-style: none; }
.lang-option {
    width: 100%;
    display: flex;
    align-items: center;
    text-align: left;
    background: transparent;
    border: 0;
    padding: 0 10px;
    min-height: 40px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    transition: var(--ease-snappy);
}
.lang-option:hover { background: var(--hover-bg); color: var(--accent-cyan); }
.lang-option[aria-selected="true"] { background: var(--accent); color: #fff; }

/* --- Theme switcher (square icon button, matches the bell) ------------------ */
.theme-switcher { display: inline-flex; }
/* .theme-toggle-btn relies entirely on .icon-btn for its square shape,
   gray stroke, hover and focus styles. */

/* --- Form & question components -------------------------------------------- */
.question {
    border: 0;
    padding: 0;
    margin: 0;
    /* Safari/WebKit gives <fieldset> an implicit min-inline-size:min-content,
       so it refuses to shrink and can force horizontal page overflow.
       min-width:0 lets it shrink to its container like every other box. */
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.question-label,
.field-label {
    font-size: clamp(0.95rem, 0.6vw + 0.85rem, 1.1rem);
    color: var(--text-primary);
    padding: 0;
}

/* Required-field asterisk — small, raised like a superscript, brand red. */
.req {
    display: inline-block;
    width: 0.58em;
    height: 0.58em;
    margin-left: 4px;
    color: var(--danger);
    position: relative;
    top: -0.24em;
}
.req svg { width: 100%; height: 100%; display: block; }

label { font-size: 0.85rem; color: var(--text-secondary); }

/* --- Inputs / textarea ----------------------------------------------------- */
.glass-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 11px 12px;
    border-radius: var(--radius-md);
    outline: none;
    min-height: 44px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: border-color var(--motion-fast), box-shadow var(--motion-fast), background var(--motion-fast);
}
.glass-input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea.glass-input {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

/* --- Native radio group ---------------------------------------------------- */
.radio-group {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.radio-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 4px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--motion-fast);
}
.radio-row:hover { background: var(--hover-bg); }
.radio-row input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-cyan);
    cursor: pointer;
    flex-shrink: 0;
}
.radio-row span {
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* --- Rating scale (1–5 segmented) ------------------------------------------
   Rating sits in its own .rating block so it gets clear separation from the
   question above it, plus internal breathing room before the endpoint
   captions.                                                                  */
.rating {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.segmented {
    display: flex;
    gap: 8px;
}
.seg-opt {
    flex: 1;
    min-height: 54px;
    /* Low floor so 5 chips + gaps fit even a 320px iPhone; flex:1 still
       stretches them well past 44px on normal-width screens. */
    min-width: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    background: var(--input-bg);
    color: var(--text-secondary);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--motion-fast), background var(--motion-fast),
                border-color var(--motion-fast), color var(--motion-fast),
                box-shadow var(--motion-fast);
}
.seg-opt:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    transform: translateY(-2px);
    box-shadow: var(--card-shadow);
}
.seg-opt:active { transform: translateY(0); }
.seg-opt[aria-checked="true"] {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 6px 16px rgba(9, 28, 58, 0.20);
}
/* Navy on the navy-ink dark canvas has almost no contrast, so the selected
   chip switches to the bright cyan active-state colour in dark mode. */
body.dark-theme .seg-opt[aria-checked="true"] {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: #0A1220;
    box-shadow: 0 6px 18px var(--accent-glow);
}
.seg-opt:focus-visible {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.rating-captions {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 0 2px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}
.rating-captions span { max-width: 46%; }
.rating-captions span:last-child { text-align: right; }

/* --- Buttons --------------------------------------------------------------- */
.glass-btn {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 11px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--ease-snappy);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-transform: uppercase;
    font-family: var(--font-head);
}
.glass-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: var(--hover-bg);
}
.glass-btn:focus-visible {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.glass-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.glass-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.glass-btn.primary:hover {
    background: #102a55;
    border-color: #102a55;
    color: #fff;
}
body.dark-theme .glass-btn.primary {
    background: var(--accent);
    border-color: #1a2c50;
    color: #fff;
}
body.dark-theme .glass-btn.primary:hover {
    background: #122a52;
    border-color: var(--accent-cyan);
}
.glass-btn.primary[disabled] { opacity: 0.55; }

.submit-btn {
    width: 100%;
    min-height: 48px;
    margin-top: 4px;
}

/* --- Success modal --------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(9, 28, 58, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    animation: modal-fade 0.18s ease-out;
}
body.dark-theme .modal-overlay { background: rgba(0, 0, 0, 0.65); }

.modal-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 28px 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    box-shadow: 0 24px 60px rgba(9, 28, 58, 0.30);
    animation: modal-pop 0.2s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.modal-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-pill);
    background: var(--success);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.modal-icon svg { width: 30px; height: 30px; }

.modal-title {
    font-size: clamp(1.1rem, 1.5vw + 0.8rem, 1.4rem);
    color: var(--text-primary);
    text-transform: uppercase;
}
.modal-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.modal-btn {
    width: 100%;
    min-height: 48px;
    margin-top: 6px;
}

@keyframes modal-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes modal-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

/* --- Sections -------------------------------------------------------------- */
.form-required-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: -6px;
}

/* Vertical rhythm uses margins, NOT flex `gap`: iOS Safari can leave a stale
   "phantom" gap between flex items after a reflow (web-font swap, toolbar
   show/hide) until a forced repaint. Margins are laid out deterministically. */
.questions-root {
    display: flex;
    flex-direction: column;
}
.form-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
}
.form-section + .form-section {
    margin-top: 28px;
}
.form-section:first-child {
    padding-top: 0;
    border-top: 0;
}
.section-title {
    font-size: clamp(0.95rem, 0.8vw + 0.8rem, 1.15rem);
    color: var(--accent-cyan);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.section-intro {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-top: -4px;
}
.section-fields {
    display: flex;
    flex-direction: column;
}
.section-fields > * + * {
    margin-top: 30px;
}

/* --- Labelled text field --------------------------------------------------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* --- Checkbox group -------------------------------------------------------- */
.checkbox-group {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--motion-fast);
}
.checkbox-row:hover { background: var(--hover-bg); }
.checkbox-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 1px;
    accent-color: var(--accent-cyan);
    cursor: pointer;
    flex-shrink: 0;
}
.checkbox-row span {
    font-family: var(--font-body);
    font-size: 0.92rem;
    color: var(--text-primary);
    line-height: 1.4;
}
.other-input {
    margin: 4px 0 4px 42px;
    width: calc(100% - 42px);
}
.other-input:disabled { opacity: 0.5; }

/* --- GDPR consent ---------------------------------------------------------- */
.consent-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--subtle-bg);
    cursor: pointer;
}
.consent-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-top: 1px;
    accent-color: var(--accent-cyan);
    cursor: pointer;
    flex-shrink: 0;
}
.consent-row span {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.45;
}

/* --- Error states ---------------------------------------------------------- */
.has-error .glass-input,
.has-error .consent-row {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft);
}
.has-error .field-label,
.has-error .question-label { color: var(--danger); }

.form-error {
    background: var(--danger-soft);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 500;
}

/* ==========================================================================
   Responsive layers (min-width only)
   ========================================================================== */

/* sm — 640px: reveal secondary labels, let the submit button size to content */
@media (min-width: 640px) {
    .app-name { display: block; }

    .submit-btn {
        width: auto;
        align-self: flex-start;
        min-width: 220px;
    }
}

/* md — 768px: more breathing room */
@media (min-width: 768px) {
    .page { padding: 28px 24px; }
    .form-card { padding: 24px; gap: 22px; }
    .form-section + .form-section { margin-top: 26px; }
    .top-bar { padding: 14px 24px; }
}

/* lg — 1024px */
@media (min-width: 1024px) {
    .page { max-width: 720px; padding: 36px 24px; }
}

/* xl — 1280px */
@media (min-width: 1280px) {
    .page { max-width: 760px; }
}
