/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #0f1117;
    color: #e8eaf0;
    min-height: 100vh;
}

/* ── Loading screen ──────────────────────────────────────── */
.app-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    font-size: 1.2rem;
    color: #888;
}

/* ── Blazor error UI ─────────────────────────────────────── */
#blazor-error-ui {
    background: #c0392b;
    color: #fff;
    padding: 0.75rem 1.5rem;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: none;
    z-index: 1000;
}
#blazor-error-ui .reload { color: #fff; font-weight: bold; margin-left: 1rem; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* ── App container ───────────────────────────────────────── */
.app-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* ── Header ──────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #2a2d3a;
}

.app-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #7eb8f7;
    letter-spacing: -0.3px;
}

.lang-selector {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.lang-selector label {
    font-size: 0.9rem;
    color: #aaa;
}

.lang-selector select,
select {
    background: #1e2130;
    color: #e8eaf0;
    border: 1px solid #3a3d50;
    border-radius: 8px;
    padding: 0.45rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}
select:hover, select:focus { border-color: #7eb8f7; }

/* ── Panels ──────────────────────────────────────────────── */
.panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.panel {
    background: #1a1d2e;
    border: 1px solid #2a2d3a;
    border-radius: 14px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.panel-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: #c8cfe8;
}

/* ── Language badge ──────────────────────────────────────── */
.lang-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    background: #253350;
    color: #7eb8f7;
    border: 1px solid #3a5080;
}

.lang-badge.detecting {
    background: #2a2510;
    color: #f0c060;
    border-color: #6a5020;
    animation: pulse-opacity 1.2s ease-in-out infinite;
}

.lang-badge.your-lang {
    background: #1e3525;
    color: #6fcf97;
    border-color: #2a5535;
}

/* ── Gender toggle ───────────────────────────────────────── */
.gender-toggle {
    display: flex;
    gap: 0;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid #3a4060;
    flex-shrink: 0;
}

.gender-btn {
    background: #1a1e30;
    color: #8090b0;
    border: none;
    padding: 0.22rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.gender-btn:hover {
    background: #252a40;
    color: #c0ccee;
}

.gender-btn.active {
    background: #253350;
    color: #7eb8f7;
}

/* ── Transcript box ──────────────────────────────────────── */
.transcript-box {
    background: #12141f;
    border: 1px solid #22253a;
    border-radius: 10px;
    padding: 1rem;
    min-height: 180px;
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

.placeholder {
    color: #444;
    font-size: 0.9rem;
    font-style: italic;
    margin: auto;
    text-align: center;
}

.interim {
    color: #666;
    font-size: 0.9rem;
    font-style: italic;
}

.transcript-entry {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #1e2130;
}
.transcript-entry:last-child { border-bottom: none; }

.original {
    font-size: 0.95rem;
    color: #b0b8d0;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.detected-lang-tag {
    font-size: 0.7rem;
    font-weight: 600;
    color: #7060a0;
    background: #1a1630;
    border: 1px solid #3a2860;
    border-radius: 10px;
    padding: 0.1rem 0.45rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.translated {
    font-size: 0.9rem;
    color: #7eb8f7;
}

.transcript-entry.reply .original { color: #6fcf97; }
.transcript-entry.reply .translated { color: #a8d8b8; }

/* ── Controls ────────────────────────────────────────────── */
.controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    padding: 0.55rem 1.2rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
    background: #3070d0;
    color: #fff;
}
.btn-primary:not(:disabled):hover { background: #4080e0; }

.btn-danger {
    background: #c0392b;
    color: #fff;
}
.btn-danger:not(:disabled):hover { background: #d44332; }

.btn-secondary {
    background: #2a3050;
    color: #c8cfe8;
    border: 1px solid #3a4060;
}
.btn-secondary:not(:disabled):hover { background: #354070; }

/* ── Status indicators ───────────────────────────────────── */
.indicator {
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
}

.indicator.listening {
    background: #1e2a40;
    color: #7eb8f7;
    animation: pulse-opacity 1.2s ease-in-out infinite;
}

.indicator.recording {
    background: #2a1e1e;
    color: #f07070;
    animation: pulse-opacity 1.2s ease-in-out infinite;
}

.indicator.speaking {
    background: #1e2a25;
    color: #6fcf97;
    animation: pulse-opacity 1.2s ease-in-out infinite;
}

.indicator.whisper {
    background: #25203a;
    color: #b07ef7;
    animation: pulse-opacity 1.2s ease-in-out infinite;
}

@keyframes pulse-opacity {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* ── Reply input ─────────────────────────────────────────── */
.reply-input {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.reply-input textarea {
    background: #12141f;
    color: #e8eaf0;
    border: 1px solid #2a2d3a;
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s;
}
.reply-input textarea:focus { border-color: #7eb8f7; }
.reply-input textarea:disabled { opacity: 0.5; }

/* ── Hint text ───────────────────────────────────────────── */
.hint {
    font-size: 0.8rem;
    color: #555;
    font-style: italic;
    text-align: center;
}

.whisper-hint { color: #7060a0; }
.whisper-note { color: #6050a0; font-size: 0.78rem; margin-top: 0.25rem; }
.whisper-note strong { color: #9070d0; }

.speaker-mode-select {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    max-width: 220px;
}

/* ── Error banner ────────────────────────────────────────── */
.error-banner {
    background: #2a1010;
    border: 1px solid #5a2020;
    color: #f08080;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
}

.error-banner button {
    background: none;
    border: none;
    color: #f08080;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.25rem;
}

/* ─── Layout wrapper & bottom nav ───────────────────────────── */
.layout-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.layout-main {
    flex: 1;
}

.bottom-nav {
    position: sticky;
    bottom: 0;
    display: flex;
    background: #13151f;
    border-top: 1px solid #22253a;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.6rem 0.5rem 0.45rem;
    color: #4a5470;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    border-top: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.nav-tab svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}
.nav-tab:hover   { color: #c0ccee; }
.nav-tab.active  { color: #7eb8f7; border-top-color: #7eb8f7; }

/* ─── Ask page ───────────────────────────────────────────────── */
.ask-container {
    max-width: 760px;
    margin: 0 auto;
    padding: 1.25rem 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

/* Intro / example prompts */
.ask-intro-title {
    font-size: 0.9rem;
    color: #6a7090;
    margin-bottom: 0.65rem;
    font-style: italic;
}

.ask-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ask-chip {
    background: #1e2235;
    color: #8090c0;
    border: 1px solid #2e3555;
    border-radius: 20px;
    padding: 0.35rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    touch-action: manipulation;
}
.ask-chip:hover {
    background: #253050;
    color: #b0c0e8;
    border-color: #4a6090;
}

/* Messages list */
.ask-messages {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    min-height: 40px;
    max-height: 55vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 0.25rem;
}

.ask-msg {
    display: flex;
}
.ask-msg--user { justify-content: flex-end; }
.ask-msg--bot  { justify-content: flex-start; }

.ask-bubble {
    max-width: min(76%, 560px);
    padding: 0.65rem 1rem;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.ask-msg--user .ask-bubble {
    background: #1e3a6a;
    color: #d0e4ff;
    border-bottom-right-radius: 4px;
}
.ask-msg--bot .ask-bubble {
    background: #1a1e30;
    color: #c0c8e0;
    border: 1px solid #272b3e;
    border-bottom-left-radius: 4px;
}

/* Thinking dots */
.ask-bubble--thinking {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0.7rem 1rem;
}
.ask-bubble--thinking span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #5a7ab0;
    animation: thinking-dot 1.2s ease-in-out infinite;
}
.ask-bubble--thinking span:nth-child(2) { animation-delay: 0.2s; }
.ask-bubble--thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-dot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
    40%            { transform: scale(1);   opacity: 1; }
}

/* Input row */
.ask-input-row {
    display: flex;
    gap: 0.65rem;
    align-items: flex-end;
}
.ask-input-row textarea {
    flex: 1;
    background: #12141f;
    color: #e8eaf0;
    border: 1px solid #2a2d3a;
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    max-height: 120px;
    overflow-y: auto;
}
.ask-input-row textarea:focus   { border-color: #7eb8f7; }
.ask-input-row textarea:disabled { opacity: 0.5; }

.ask-send {
    flex-shrink: 0;
    padding: 0.65rem 1.2rem;
    align-self: flex-end;
}

/* ─── Image Translate page ───────────────────────────────────── */
.imgt-container {
    max-width: 680px;
    margin: 0 auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Image picker / preview area */
.imgt-pick {
    position: relative;
    background: #12141f;
    border: 2px dashed #2e3255;
    border-radius: 14px;
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s;
    touch-action: manipulation;
}
.imgt-pick:hover,
.imgt-pick:focus-within { border-color: #5a7ab0; }

.imgt-pick--has-image { border-style: solid; border-color: #2a3050; }

.imgt-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 2rem 1.5rem;
    text-align: center;
    pointer-events: none;
}
.imgt-placeholder svg {
    width: 52px;
    height: 52px;
    color: #3a4570;
}
.imgt-placeholder p {
    font-size: 0.95rem;
    color: #7080a0;
    font-weight: 500;
}
.imgt-placeholder span {
    font-size: 0.78rem;
    color: #404870;
}

.imgt-preview {
    width: 100%;
    height: 100%;
    max-height: 420px;
    object-fit: contain;
    display: block;
}

.imgt-clear {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    background: rgba(0,0,0,0.65);
    color: #e0e4f0;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.imgt-clear:hover { background: rgba(180,50,50,0.8); }

/* Options row */
.imgt-options {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.imgt-options-label {
    font-size: 0.85rem;
    color: #8090b0;
    white-space: nowrap;
}

/* Action button */
.imgt-go {
    width: 100%;
    padding: 0.85rem;
    font-size: 1rem;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
}

/* Spinner inside button */
.imgt-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
.imgt-detected {
    font-size: 0.85rem;
    color: #7080a0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.imgt-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}

.imgt-card {
    background: #12141f;
    border: 1px solid #22253a;
    border-radius: 12px;
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.imgt-card--translated { border-color: #253560; background: #111828; }

.imgt-card-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #5a6585;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.3rem;
}
.imgt-card--translated .imgt-card-label { color: #4a6090; }

.imgt-card-text {
    font-size: 0.92rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: #b0bcd8;
}
.imgt-card--translated .imgt-card-text { color: #7eb8f7; }

/* Single-column cards on narrow screens */
@media (max-width: 500px) {
    .imgt-cards { grid-template-columns: 1fr; }
    .imgt-container { padding: 0.85rem 0.75rem; }
    .imgt-pick { min-height: 180px; }
    .imgt-options .speaker-mode-select { flex: 1; max-width: none; font-size: 16px; }
}

/* ─── Touch / PWA base ───────────────────────────────────────
   Prevent 300ms tap delay on all interactive elements.        */
.btn, select, textarea, .gender-btn {
    touch-action: manipulation;
}

/* Safe-area insets for notched phones (iPhone X+, Android cutouts).
   viewport-fit=cover in <meta viewport> enables env() values.  */
body {
    padding-top:    env(safe-area-inset-top,    0px);
    padding-right:  env(safe-area-inset-right,  0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left:   env(safe-area-inset-left,   0px);
}

/* ─── Single-column layout (≤ 680px) ────────────────────────  */
@media (max-width: 680px) {
    .panels { grid-template-columns: 1fr; }

    /* Tighter outer container */
    .app-container {
        padding: 0.75rem;
        gap: 0.8rem;
    }

    /* Compact header */
    .app-header { padding-bottom: 0.55rem; }
    .app-header h1 { font-size: 1.15rem; }

    /* Tighter panels */
    .panel {
        padding: 0.85rem;
        gap: 0.75rem;
        border-radius: 12px;
    }

    /* Panel header: h2 + badge/toggle on first row,
       select pushed to its own full-width row below  */
    .panel-header {
        flex-wrap: wrap;
        gap: 0.45rem 0.6rem;
    }
    .panel-header .speaker-mode-select {
        order: 10;          /* renders after h2 + badge/toggle */
        flex: 0 0 100%;     /* own full-width row */
        max-width: none;
        /* ≥ 16px prevents iOS auto-zoom on focus */
        font-size: 16px;
        padding: 0.5rem 0.7rem;
    }

    /* Transcript: shorter to leave room for controls */
    .transcript-box {
        min-height: 100px;
        max-height: 185px;
        -webkit-overflow-scrolling: touch;
    }

    /* Stacked, full-width buttons in .controls */
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .controls .btn {
        width: 100%;
        padding: 0.8rem 1rem;
        font-size: 0.95rem;
        min-height: 48px;   /* comfortable touch target */
    }
    .controls .indicator { text-align: center; }

    /* Full-width "Translate & Speak" */
    .reply-input .btn {
        width: 100%;
        padding: 0.8rem 1rem;
        font-size: 0.95rem;
        min-height: 48px;
    }

    /* Textarea: no resize handle, ≥ 16px to block iOS zoom */
    .reply-input textarea {
        resize: none;
        font-size: 16px;
        padding: 0.7rem 0.85rem;
    }

    /* Slightly larger gender-toggle tap area */
    .gender-btn {
        padding: 0.38rem 0.9rem;
        font-size: 0.8rem;
        min-height: 34px;
    }

    /* Ask page on mobile */
    .ask-container  { padding: 0.85rem 0.75rem 0.75rem; }
    .ask-messages   { max-height: 48vh; }
    .ask-input-row textarea { font-size: 16px; } /* prevent iOS zoom */
    .ask-chip       { font-size: 0.78rem; padding: 0.32rem 0.75rem; }
    .ask-send       { padding: 0.75rem 1rem; min-height: 48px; }
}

/* ─── Very small screens (≤ 380px) ──────────────────────────  */
@media (max-width: 380px) {
    .app-container  { padding: 0.5rem;  gap: 0.6rem; }
    .app-header h1  { font-size: 1rem; }
    .panel          { padding: 0.7rem;  gap: 0.6rem; }
    .transcript-box { min-height: 80px; max-height: 150px; }
}

/* ─── Landscape phone (short viewport) ──────────────────────  */
@media (max-height: 500px) and (orientation: landscape) {
    .app-container  { gap: 0.5rem; padding: 0.5rem; }
    .transcript-box { min-height: 60px; max-height: 110px; }
    .reply-input textarea { rows: 2; max-height: 56px; }
}
