/* ═══════════════════════════════════════════
   MATEMATICANDO — Estilos principais
   ═══════════════════════════════════════════ */

:root {
    --primary:   #6c63ff;
    --primary-d: #574fd6;
    --success:   #48bb78;
    --success-d: #38a169;
    --danger:    #fc8181;
    --danger-d:  #e53e3e;
    --warning:   #f6ad55;
    --bg:        #f0f4ff;
    --card:      #ffffff;
    --text:      #2d3748;
    --muted:     #718096;
    --border:    #e2e8f0;
    --radius:    16px;
    --shadow:    0 4px 24px rgba(108,99,255,.12);
}

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

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--text);
    display: flex;
    flex-direction: column;
}

/* ── HEADER ─────────────────────────────── */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, #a78bfa 100%);
    color: white;
    padding: 16px 24px;
    box-shadow: 0 2px 16px rgba(108,99,255,.3);
}
.header-inner { max-width: 1200px; margin: 0 auto; }
.logo { display: flex; align-items: center; gap: 14px; }
.logo-icon { font-size: 2.4rem; }
.logo-text h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.5px; }
.logo-text p  { font-size: .85rem; opacity: .85; }

/* ── MAIN ────────────────────────────────── */
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 24px auto;
    padding: 0 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

/* ── PANELS ──────────────────────────────── */
.panel {
    background: var(--card);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}
.panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── TOOLBAR ─────────────────────────────── */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: 10px;
    background: #edf2ff;
    color: var(--primary);
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, transform .15s, box-shadow .2s;
}
.tool-btn:hover:not(:disabled) {
    background: #dde6ff;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(108,99,255,.2);
}
.tool-btn:disabled { opacity: .45; cursor: not-allowed; }
.tool-btn.primary { background: var(--primary); color: white; }
.tool-btn.primary:hover:not(:disabled) { background: var(--primary-d); }
.tool-btn.danger  { background: #fff0f0; color: var(--danger-d); }
.tool-btn.danger:hover:not(:disabled)  { background: #ffe4e4; }
.tool-btn.full-width { width: 100%; justify-content: center; margin-top: 16px; }

/* ── RECOGNITION STATUS ──────────────────── */
/* Altura fixa — nunca empurra o canvas */
.recognition-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: 10px;
    height: 40px;           /* fixa — sem saltos */
    transition: background .3s, color .3s;
}
.recognition-status.idle      { background: #f7fafc; color: var(--muted); }
.recognition-status.drawing   { background: #ebf8ff; color: #2b6cb0; }
.recognition-status.done      { background: #f0fff4; color: #276749; }
.recognition-status.thinking  { background: #ebf8ff; color: #2b6cb0; }
.recognition-status.connecting{ background: #f7fafc; color: var(--muted); }
.recognition-status.error-rec { background: #fff5f5; color: #c53030; }

/* ── LATEX PREVIEW ───────────────────────── */
/* Altura fixa reservada — visibilidade controlada por visibility, não display */
.latex-preview {
    background: #f7f3ff;
    border: 1px solid #d6ccff;
    border-radius: 10px;
    padding: 8px 16px;
    margin-bottom: 12px;
    display: flex !important;   /* sempre ocupa espaço */
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    height: 44px;
    overflow: hidden;
    visibility: hidden;         /* oculto sem remover espaço */
    transition: visibility .2s;
}
.latex-preview.visible {
    visibility: visible;
}
.preview-label { font-size: .8rem; color: var(--primary); font-weight: 600; white-space: nowrap; }
.latex-math    { font-size: 1.1rem; color: var(--text); flex: 1; }
.latex-math.large { font-size: 1.4rem; }

/* ── EDITOR WRAPPER (iink-ts) ────────────── */
.editor-wrapper {
    position: relative;
    border: 2.5px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    background: white;
    height: 420px;          /* fixo — não tremula */
    cursor: crosshair;
    transition: border-color .2s;
    flex-shrink: 0;
}
.editor-wrapper:focus-within { border-color: var(--primary); }

#editor {
    width: 100%;
    height: 420px;          /* igual ao wrapper */
    touch-action: none;
    display: block;
}

/* iink-ts injeta canvas interno — força ocupar 100% */
#editor > * { width: 100% !important; height: 100% !important; }

.canvas-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #cbd5e0;
    font-size: 1rem;
    pointer-events: none;
    transition: opacity .3s;
    user-select: none;
}
.canvas-hint.hidden { opacity: 0; }

/* ── TIPS ────────────────────────────────── */
.tips {
    margin-top: 14px;
    background: #fffbeb;
    border-left: 4px solid var(--warning);
    border-radius: 0 10px 10px 0;
    padding: 10px 14px;
    font-size: .82rem;
    color: #744210;
    line-height: 1.5;
}

/* ── EMPTY STATE ─────────────────────────── */
.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
}
.empty-icon { font-size: 3.5rem; margin-bottom: 16px; }
.empty-state p { font-size: .95rem; line-height: 1.6; }

/* ── LOADING ─────────────────────────────── */
.loading-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--muted);
}
.spinner {
    width: 48px; height: 48px;
    border: 5px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RESULT ──────────────────────────────── */
.result-state { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; } }

.result-equation {
    background: #f7f3ff;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.result-label { font-size: .82rem; font-weight: 700; color: var(--primary); white-space: nowrap; }

.solution-content {
    line-height: 1.7;
    color: var(--text);
    font-size: .93rem;
}
/* Estilos para o HTML que o DeepSeek retorna */
.solution-content .step {
    background: #f7fafc;
    border-left: 4px solid var(--primary);
    border-radius: 0 10px 10px 0;
    padding: 10px 14px;
    margin: 10px 0;
}
.solution-content .highlight {
    background: #fefcbf;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    color: #744210;
}
.solution-content p { margin: 8px 0; }
.solution-content strong { color: var(--primary-d); }

/* ── ERROR ───────────────────────────────── */
.error-state { text-align: center; padding: 40px 20px; }
.error-icon  { font-size: 3rem; margin-bottom: 14px; }
.error-state p { color: var(--muted); margin-bottom: 16px; font-size: .92rem; }

/* ── FOOTER ──────────────────────────────── */
.app-footer {
    text-align: center;
    padding: 14px;
    font-size: .78rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
    background: white;
}

/* ── RESPONSIVE ──────────────────────────── */
@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
        margin: 12px auto;
    }
    .logo-text h1 { font-size: 1.3rem; }
    .editor-wrapper,
    #editor { height: 320px; }
}
