/* CrossFlow — design tokens + base
   Sistema: ink/teal (estructura y confianza) + ember (acción — grabar,
   CTA primario, "en vivo"). Tipografía: sans del sistema para texto humano
   (perfiles, notas), monoespaciada del sistema para todo dato extraído por
   la IA (timer, fechas, montos, badges) — sin fuentes externas: un CRM de
   campo con conectividad irregular no puede depender de un webfont. */

:root {
    /* Acento de acción: grabar, CTA primario, focus, "en vivo" */
    --primary: #D97706;
    --primary-dark: #B45309;
    --primary-ink: #7C2D12;

    /* Estructura / confianza — usado en la tarjeta de "estrategia" y en
       acentos secundarios */
    --teal: #0F6B63;
    --teal-dark: #0B534C;

    /* Neutrales, con leve tinte frío hacia --gray-900 (ink) */
    --gray-50: #F5F6F8;
    --gray-100: #EDEFF3;
    --gray-200: #E3E6EC;
    --gray-300: #D2D6E0;
    --gray-400: #97A0B2;
    --gray-600: #5B6472;
    --gray-700: #3A4250;
    --gray-900: #101A2E;

    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', 'Roboto Mono', 'Cascadia Mono', Consolas, monospace;

    --header-height: 56px;
    --tab-bar-height: 60px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

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

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 1.5rem 1rem calc(2rem + var(--tab-bar-height) + var(--safe-bottom));
}

@media (min-width: 768px) {
    .container {
        padding: 2rem 1rem 3rem;
    }
}

/* --- Login / register: centered hero, no tab bar (unauthenticated) --- */

body.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
}

.auth-container {
    max-width: 400px;
    padding-bottom: 2rem;
}

.auth-logo {
    display: block;
    text-align: center;
    font-size: 1.4rem;
    margin-bottom: 1.5rem;
}

/* --- App header: logo + (desktop) inline nav + auth bar. On mobile the
   primary navigation lives in .tab-bar instead (see below) — this stays
   slim, one row, never wraps. --- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.app-logo {
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    color: var(--gray-900);
    text-decoration: none;
    flex-shrink: 0;
}

.app-nav-links {
    display: none;
    gap: 0.25rem;
}

@media (min-width: 768px) {
    .app-nav-links {
        display: flex;
    }
}

.app-nav-link {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-600);
    text-decoration: none;
    transition: all 0.15s ease;
}

.app-nav-link:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.app-nav-link.is-active {
    background: var(--gray-900);
    color: white;
}

.auth-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.8rem;
    color: var(--gray-600);
    flex-shrink: 0;
}

.auth-bar-usage {
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--gray-100);
    color: var(--gray-700);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.auth-bar-email {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .auth-bar-email {
        display: none;
    }
}

.auth-bar-logout {
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    color: var(--gray-700);
    cursor: pointer;
    font-family: inherit;
}

.auth-bar-logout:hover {
    background: var(--gray-100);
}

/* --- Bottom tab bar: primary navigation on mobile, thumb-reachable.
   Hidden at desktop widths in favor of .app-nav-links above. Fixed, with
   iOS safe-area padding so it never sits under the home indicator. --- */

.tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    background: white;
    border-top: 1px solid var(--gray-200);
    padding-bottom: var(--safe-bottom);
    box-shadow: 0 -2px 12px rgba(16, 26, 46, 0.06);
}

@media (min-width: 768px) {
    .tab-bar {
        display: none;
    }
}

.tab-bar-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    height: var(--tab-bar-height);
    text-decoration: none;
    color: var(--gray-400);
    font-size: 0.68rem;
    font-weight: 600;
}

.tab-bar-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.tab-bar-link.is-active {
    color: var(--primary-dark);
}

/* --- Progress stepper --- */

.stepper {
    display: flex;
    align-items: center;
    margin-bottom: 2rem;
}

.stepper-step {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--gray-400);
}

.stepper-index {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--gray-400);
    transition: all 0.2s ease;
}

.stepper-label {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
}

.stepper-connector {
    flex: 1;
    height: 2px;
    background: var(--gray-200);
    margin: 0 0.75rem;
    transition: background-color 0.2s ease;
}

.stepper-step.is-active .stepper-index {
    border-color: var(--primary);
    color: var(--primary-dark);
    box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.14);
}

.stepper-step.is-active .stepper-label {
    color: var(--gray-900);
}

.stepper-step.is-done .stepper-index {
    border-color: var(--teal);
    background: var(--teal);
    color: white;
}

.stepper-step.is-done .stepper-label {
    color: var(--gray-700);
}

.stepper-step.is-done + .stepper-connector {
    background: var(--teal);
}

.section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--gray-100);
}

@media (min-width: 640px) {
    .section {
        padding: 2rem;
    }
}

.section-title {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 1.5rem;
    color: var(--gray-900);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    font-family: inherit;
}

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

.button-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.button-primary:active {
    transform: translateY(0);
}

.button-secondary {
    background: var(--gray-100);
    color: var(--gray-900);
    border: 1px solid var(--gray-200);
}

.button-secondary:hover {
    background: var(--gray-200);
}

input[type="radio"]:disabled {
    cursor: not-allowed;
}

label:has(input[type="radio"]:disabled) {
    opacity: 0.5;
    cursor: not-allowed;
}

.button-small {
    min-height: 38px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.button-danger {
    background: #EF4444;
    color: white;
}

.button-danger:hover {
    background: #DC2626;
}

.input-group {
    margin-bottom: 1rem;
}

.input-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.input-field {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 16px; /* nunca menor a 16px: evita el auto-zoom de iOS al enfocar */
    font-family: inherit;
    background: white;
    color: var(--gray-900);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.14);
}

textarea.input-field {
    resize: vertical;
    min-height: 100px;
}

.draft-box {
    background: var(--gray-50);
    border-left: 4px solid var(--primary);
    padding: 1rem;
    margin: 1.5rem 0;
    border-radius: 4px;
}

/* Two independent draft forms (retroactivo + estrategia) stacked below the
   shared client section, each visually distinct via its own accent color and
   a clear gap/border so it reads as a separate, separately-savable unit. */
.draft-flow-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    padding: 1.25rem;
    margin-top: 1.5rem;
}

@media (min-width: 640px) {
    .draft-flow-card {
        padding: 1.5rem;
    }
}

.draft-flow-card--strategy {
    border-left-color: var(--teal);
}

.draft-flow-card-header {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--primary-dark);
}

.draft-flow-card--strategy .draft-flow-card-header {
    color: var(--teal-dark);
}

/* One card per date the "estrategia" recording mentions — a single
   recording can describe several distinct follow-ups, each with its own
   products, so these need to read as clearly separate, easy-to-scan
   blocks. Each block's own header carries its number + an inline compact
   date picker, instead of repeating a full "Fecha programada" field below
   — trims a lot of vertical space when there are several dates. */
.strategy-blocks {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.strategy-block {
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 1rem 1.1rem;
    background: var(--gray-50);
}

.strategy-block-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.strategy-block-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.strategy-block-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--teal);
    color: white;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 700;
}

.strategy-block-title {
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--teal-dark);
}

/* Wrapping <label> around the date input: tapping anywhere in the pill
   (not just the tiny native input) focuses it and opens the picker. */
.strategy-block-date-field {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    padding: 0.4rem 0.65rem;
    cursor: text;
}

.strategy-block-date-field span {
    font-size: 0.85rem;
}

.strategy-block-date {
    border: none;
    background: transparent;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-900);
    padding: 0;
    width: 128px;
}

.strategy-block-date:focus {
    outline: none;
}

.strategy-block-remove {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border-radius: 50%;
    border: none;
    background: var(--gray-200);
    color: var(--gray-600);
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
}

.strategy-block-remove:hover {
    background: #FEE2E2;
    color: #DC2626;
}

.strategy-field-group {
    margin-top: 1rem;
}

.strategy-field-group:first-child {
    margin-top: 0;
}

.strategy-field-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.6rem;
}

.strategy-field-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--gray-200);
    color: var(--gray-700);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: normal;
}

.strategy-block-description {
    min-height: 60px;
}

.strategy-product-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.strategy-product-row {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 0.75rem;
}

.strategy-product-row-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.strategy-product-select {
    flex: 1;
    min-width: 0;
}

.strategy-product-remove {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    color: var(--gray-600);
    cursor: pointer;
    font-size: 0.72rem;
    line-height: 1;
}

.strategy-product-remove:hover {
    background: #FEE2E2;
    color: #DC2626;
}

.strategy-product-tag {
    margin-top: 0.5rem;
    display: inline-block;
    font-size: 0.72rem;
    color: var(--gray-600);
    background: var(--gray-100);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
}

.strategy-product-help {
    margin-top: 0.5rem;
    font-size: 0.82rem;
    color: var(--gray-600);
}

.strategy-product-new-wrap {
    margin-top: 0.6rem;
}

.strategy-product-new-hint {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: #B45309;
}

/* Dashed "ghost" style for both add actions — deliberately different from
   button-secondary (used for real actions like Guardar/Descartar) so they
   read as "add a new row/block", not as another equally-weighted action. */
.strategy-add-product-btn,
.strategy-add-block-btn {
    width: 100%;
    min-height: 44px;
    margin-top: 0.75rem;
    padding: 0.6rem;
    border: 1px dashed var(--gray-300);
    border-radius: 8px;
    background: transparent;
    color: var(--gray-600);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.strategy-add-product-btn:hover,
.strategy-add-block-btn:hover {
    border-color: var(--teal);
    color: var(--teal-dark);
    background: rgba(15, 107, 99, 0.05);
}

.strategy-add-block-btn {
    margin-top: 0;
}

@media (max-width: 480px) {
    .strategy-block-date-field {
        width: 100%;
        margin-left: 0;
    }

    .strategy-block-date {
        width: 100%;
    }
}

.draft-flow-card.is-locked {
    opacity: 0.6;
}

.draft-flow-card-status {
    margin-top: 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-600);
}

.draft-flow-card.is-locked .draft-flow-card-status {
    color: var(--teal);
}

.draft-item {
    margin-bottom: 1rem;
}

.draft-label {
    font-weight: 700;
    color: var(--gray-700);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.draft-value {
    margin-top: 0.3rem;
    color: var(--gray-600);
}

.product-match-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.product-match-item {
    padding: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    background: white;
}

.product-match-item .input-label {
    margin-top: 0.75rem;
}

.product-match-item .input-label:first-of-type {
    margin-top: 0;
}

.product-match-detected {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-bottom: 0.75rem;
}


.actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.actions .button {
    flex: 1;
    min-width: 140px;
}

.loader {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.alert-error {
    background: #FEE2E2;
    border: 1px solid #FECACA;
    color: #DC2626;
}

.alert-success {
    background: #E4F3EE;
    border: 1px solid #BEE3D8;
    color: var(--teal-dark);
}

.alert-info {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
}

.hidden {
    display: none;
}

/* --- Recording hero: the single most characteristic moment of the app.
   Mic button in ink by default; the moment it starts recording it switches
   to the ember pulse — the one signature motion reused (more subtly) by the
   active stepper step and the active processing-log row. --- */

#record-controls {
    padding: 0.5rem 0 1rem;
}

.record-btn {
    display: block;
    width: clamp(96px, 28vw, 128px);
    height: clamp(96px, 28vw, 128px);
    margin: 0 auto;
    border-radius: 50%;
    border: none;
    background: var(--gray-900);
    color: white;
    font-size: clamp(2rem, 8vw, 2.75rem);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    box-shadow: 0 8px 24px rgba(16, 26, 46, 0.18);
}

.record-btn:hover {
    transform: translateY(-2px);
}

.record-btn:active {
    transform: translateY(0);
}

.record-btn.is-recording {
    background: var(--primary);
    animation: record-pulse 1.6s ease-in-out infinite;
}

@keyframes record-pulse {
    0%, 100% { box-shadow: 0 8px 24px rgba(16, 26, 46, 0.18), 0 0 0 0 rgba(217, 119, 6, 0.35); }
    50% { box-shadow: 0 8px 24px rgba(16, 26, 46, 0.18), 0 0 0 14px rgba(217, 119, 6, 0); }
}

.timer {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 1.35rem;
    letter-spacing: 0.02em;
}

.waveform-wrap {
    display: none;
    margin: 0 auto 1rem;
}

.waveform-canvas {
    width: 100%;
    height: 64px;
    display: block;
    background: var(--gray-50);
    border-radius: 8px;
}

.vu-meter {
    display: none;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    height: 32px;
    margin: 0 auto 1rem;
}

.vu-segment {
    width: 8px;
    height: 100%;
    border-radius: 2px;
    background: var(--gray-200);
    opacity: 0.5;
    transition: background-color 0.05s linear, opacity 0.05s linear;
}

.vu-segment[data-zone="low"].is-lit {
    background: var(--teal);
    opacity: 1;
}

.vu-segment[data-zone="mid"].is-lit {
    background: #EAB308;
    opacity: 1;
}

.vu-segment[data-zone="high"].is-lit {
    background: var(--primary);
    opacity: 1;
}

.recording-review {
    display: none;
}

.recording-review-meta {
    text-align: center;
    color: var(--gray-600);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}

.recording-review audio {
    width: 100%;
    margin-bottom: 1rem;
}

.process-log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    margin-bottom: 1.5rem;
}

.process-log-header:has(+ .step-list[data-collapsed="true"]) {
    margin-bottom: 0;
}

.process-log-chevron {
    color: var(--gray-400);
    transition: transform 0.2s ease;
    font-size: 0.8rem;
}

.step-list[data-collapsed="true"] {
    display: none;
}

.step-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.step-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    opacity: 0.45;
    transition: opacity 0.2s ease;
}

.step-item.is-active,
.step-item.is-done,
.step-item.is-error {
    opacity: 1;
}

.step-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 0.05rem;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    line-height: 1;
    color: white;
    transition: all 0.2s ease;
}

.step-item.is-active .step-icon {
    border-color: var(--primary);
    animation: step-pulse 1.1s ease-in-out infinite;
}

.step-item.is-done .step-icon {
    border-color: var(--teal);
    background: var(--teal);
}

.step-item.is-error .step-icon {
    border-color: #DC2626;
    background: #DC2626;
}

.step-text {
    font-size: 0.9rem;
    color: var(--gray-600);
    padding-top: 0.05rem;
}

.step-item.is-active .step-text {
    color: var(--primary-dark);
    font-weight: 500;
}

.step-item.is-done .step-text {
    color: var(--gray-900);
}

.step-item.is-error .step-text {
    color: #DC2626;
    font-weight: 500;
}

@keyframes step-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.35); }
    50% { box-shadow: 0 0 0 5px rgba(217, 119, 6, 0.12); }
}

@media (prefers-reduced-motion: reduce) {
    .record-btn.is-recording,
    .step-item.is-active .step-icon {
        animation: none;
    }
}

/* Focus visibility everywhere, not just inputs */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (max-width: 640px) {
    .actions .button {
        width: 100%;
    }
}
