/* ============================================================
   Apurei — style-layout.css
   Sistema de design + estrutura global

   Responsabilidades deste arquivo:
     - @import de fontes
     - Utilitários de visibilidade (.apurei-hidden / .apurei-visible)
     - Resets de contexto (button, img, input, box-sizing)
     - Tokens de design (CSS custom properties)
     - Alertas compartilhados
     - Shell: sidebar + área central (layout estrutural)
     - Componentes compartilhados: inputs, botões, dropzone, campos
     - Breakpoints responsivos (sidebar collapsa, cards empilham)

   Edite este arquivo para:
     - Mudar cores, tipografia ou espaçamentos globais
     - Ajustar o layout da sidebar ou da área principal
     - Modificar estilos de botões, inputs ou dropzone
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Garantia do atributo hidden ──────────────────────────── */
.apurei-root [hidden],
[hidden].apurei-root,
#apurei-zone-progress[hidden],
#apurei-zone-result[hidden],
#apurei-zone-form[hidden],
#apurei-post-upload[hidden],
#apurei-result-layer2[hidden] {
  display: none !important;
}

.apurei-hidden  { display: none !important; }
.apurei-visible { display: block !important; }

/* ── Neutraliza resets do tema SaaS Base ─────────────────── */
.apurei-root button {
  cursor: pointer;
  font-family: inherit;
  border: initial;
  background: initial;
}

.apurei-root img,
.apurei-root svg {
  display: inline-block;
  max-width: none;
}

.apurei-root .apurei-dropzone svg,
.apurei-root .apurei-dropzone-icon svg {
  display: block;
  max-width: 100%;
}

.apurei-root input,
.apurei-root textarea,
.apurei-root select {
  font-family: inherit;
  font-size: inherit;
}

/* Remove highlight azul do browser/tema em campos da caixa de chat */
.apurei-root .apurei-chat-field-input:focus,
.apurei-root .apurei-chat-field-input:focus-visible {
  outline: none !important;
  box-shadow: none !important;
}

/* ── Reset de contexto ────────────────────────────────────── */
.apurei-root *,
.apurei-root *::before,
.apurei-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Tokens ───────────────────────────────────────────────── */
.apurei-root {
  --c-bg:        #f5f5f3;
  --c-surface:   #ffffff;
  --c-ink:       #111111;
  --c-muted:     #666666;
  --c-border:    #e0ddd8;
  --c-accent:    #111111;
  --c-accent-fg: #ffffff;
  --c-ok:        #1a6b3c;
  --c-ok-bg:     #eaf4ee;
  --c-warn:      #7a4f00;
  --c-warn-bg:   #fef3dc;
  --c-error:     #7a1a1a;
  --c-error-bg:  #fdecea;
  --c-step-done: #1a6b3c;
  --c-step-pend: #cccccc;

  --radius: 3px;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.04);

  --font-serif: 'Lora', Georgia, serif;
  --font-mono:  'JetBrains Mono', 'Courier New', monospace;
  --font-sans:  -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  font-family: var(--font-sans);
  background:  var(--c-bg);
  color:       var(--c-ink);
  min-height:  100vh;
  line-height: 1.5;
}

/* ── Alerts ───────────────────────────────────────────────── */
.apurei-alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}
.apurei-alert-error {
  background: var(--c-error-bg);
  color: var(--c-error);
  border: 1px solid rgba(122,26,26,.15);
}

/* ============================================================
   SHELL — layout sidebar + área central
   ============================================================ */

.apurei-shell {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */

.apurei-sidebar {
  width: 232px;
  min-width: 232px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* Logo */
.apurei-sb-logo {
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.apurei-sb-logo-text {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  color: var(--c-ink);
  letter-spacing: -0.02em;
  display: block;
  line-height: 1;
}

.apurei-sb-logo-sub {
  display: block;
  font-size: 11px;
  color: var(--c-muted);
  margin-top: 3px;
}

/* Créditos */
.apurei-sb-credits {
  margin: 12px 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 11px;
  color: var(--c-muted);
  flex-shrink: 0;
}

.apurei-sb-credits-value {
  font-weight: 600;
  font-size: 12px;
  color: var(--c-ink);
}

/* Botão nova apuração */
.apurei-sb-nova {
  margin: 14px 14px 14px;
  width: calc(100% - 28px);
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--c-accent) !important;
  color: var(--c-accent-fg) !important;
  border: 1px solid var(--c-accent) !important;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
  flex-shrink: 0;
}

.apurei-sb-nova:hover {
  background: #333 !important;
  border-color: #333 !important;
}

.apurei-sb-nova-icon {
  width: 16px;
  height: 16px;
  border: 1.5px solid rgba(255,255,255,0.5);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Rodapé da sidebar ────────────────────────────────────── */

.apurei-sb-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--c-border);
  padding: 8px 8px 10px;
}

/* Bloco de usuário estilo Claude */
.apurei-sb-user {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px;
  border-radius: var(--radius);
  transition: background 0.12s;
}

.apurei-sb-user:hover {
  background: var(--c-bg);
}

.apurei-sb-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  padding: 3px 6px;
  border-radius: var(--radius);
}

.apurei-sb-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--c-ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
}

.apurei-sb-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.apurei-sb-user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.apurei-sb-user-plan {
  font-size: 10.5px;
  color: var(--c-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

/* Botão de histórico */
.apurei-sb-hist-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  border: none;
  background: none;
  color: var(--c-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  padding: 0;
}

.apurei-sb-hist-btn:hover {
  background: var(--c-border);
  color: var(--c-ink);
}

/* Label histórico */
.apurei-sb-hist-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-muted);
  padding: 0 14px 6px;
  flex-shrink: 0;
}

/* Lista de histórico */
.apurei-sb-hist {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}

/* Item de histórico — inserido pelo JS */
.apurei-sb-hist-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 8px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  margin-bottom: 2px;
  color: inherit;
  transition: background 0.1s;
}

.apurei-sb-hist-item:hover:not(.active) {
  background: var(--c-bg);
}

.apurei-sb-hist-item.active {
  background: var(--c-bg);
  border-color: var(--c-border);
}

/* Área clicável (nome + data) */
.apurei-sb-hist-item-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.apurei-sb-hist-name {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--c-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.apurei-sb-hist-date {
  display: block;
  font-size: 10px;
  color: var(--c-muted);
  margin-top: 1px;
}

/* Ícone de fixado */
.apurei-pin-icon {
  flex-shrink: 0;
  color: var(--c-brand, #6c63ff);
  opacity: 0.7;
}

/* Botão kebab (⋮) */
.apurei-sb-hist-kebab {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  color: var(--c-muted);
  opacity: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
  padding: 0;
}

.apurei-sb-hist-item:hover .apurei-sb-hist-kebab,
.apurei-sb-hist-item.active .apurei-sb-hist-kebab {
  opacity: 1;
}

.apurei-sb-hist-kebab:hover {
  background: var(--c-border);
  color: var(--c-ink);
}

/* Dropdown de opções */
.apurei-sb-hist-dropdown {
  position: absolute;
  background: var(--c-surface, #fff);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.13);
  z-index: 99999;
  overflow: hidden;
  padding: 4px 0;
}

.apurei-sb-hist-dd-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--c-ink);
  text-align: left;
  transition: background 0.1s;
  line-height: 1;
}

.apurei-sb-hist-dd-item:hover {
  background: var(--c-bg);
}

.apurei-sb-hist-dd-sep {
  height: 1px;
  background: var(--c-border);
  margin: 4px 0;
}

.apurei-sb-hist-dd-danger {
  color: #d94f4f;
}

.apurei-sb-hist-dd-danger:hover {
  background: #fff5f5;
}

/* Input de renomear inline */
.apurei-sb-hist-rename-input {
  display: block;
  width: 100%;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  color: var(--c-ink);
  background: var(--c-bg);
  border: 1px solid var(--c-brand, #6c63ff);
  border-radius: 4px;
  padding: 2px 6px;
  box-sizing: border-box;
  outline: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c-brand, #6c63ff) 20%, transparent);
}

/* ── ÁREA CENTRAL ─────────────────────────────────────────── */

.apurei-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--c-bg);
}

/* ============================================================
   COMPONENTES COMPARTILHADOS
   ============================================================ */

/* Inputs */
.apurei-input {
  width: 100%;
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--c-ink);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.apurei-input:focus       { border-color: var(--c-ink); }
.apurei-input::placeholder { color: var(--c-muted); }

/* Botões */
.apurei-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 24px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.apurei-btn-primary {
  background: var(--c-accent) !important;
  color:      var(--c-accent-fg) !important;
  border: 1px solid var(--c-accent) !important;
  text-decoration: none !important;
}

.apurei-btn-primary:hover {
  background: #333 !important;
  border-color: #333 !important;
  color: #fff !important;
}

.apurei-btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.apurei-btn-large {
  padding: 14px 32px;
  font-size: 15px;
  width: 100%;
}

.apurei-btn-ghost {
  background: none;
  border: none;
  color: var(--c-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  font-family: inherit;
}

.apurei-btn-ghost:hover { color: var(--c-ink); background: var(--c-border); }

/* Campos */
.apurei-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.apurei-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--c-ink);
}

.apurei-field-hint {
  font-size: 12px;
  color: var(--c-muted);
  line-height: 1.5;
}

/* Dropzone */
.apurei-dropzone {
  width: 100%;
  border: 1.5px dashed var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  padding: 36px 24px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
  overflow: hidden;
}

.apurei-dropzone:hover,
.apurei-dropzone:focus,
.apurei-dropzone.dragover {
  border-color: var(--c-ink);
  background: #fafaf8;
  outline: none;
}

.apurei-dropzone.dragover { background: #f0f0ec; }

.apurei-dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  pointer-events: none;
}

.apurei-dropzone-icon  { color: var(--c-muted); }
.apurei-dropzone-text  { font-size: 14px; color: var(--c-ink); }
.apurei-dropzone-hint  { font-size: 12px; color: var(--c-muted); line-height: 1.5; }

.apurei-link {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.apurei-file-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  font-size: 0;
  z-index: 2;
}

/* Pós-upload */
.apurei-post-upload {
  width: 100%;
  margin-top: 12px;
}

.apurei-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
}

.apurei-file-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apurei-remove-file {
  padding: 2px 6px;
  font-size: 14px;
}

/* ── Elementos exclusivos do mobile (invisíveis em desktop) ─── */

.apurei-mobile-topbar   { display: none; }
.apurei-sidebar-close   { display: none; }
.apurei-drawer-backdrop { display: none; pointer-events: none; }

/* ============================================================
   RESPONSIVIDADE
   ============================================================ */

@media (max-width: 768px) {

  /* ── Shell: coluna, dá espaço para a topbar fixa ──────────── */
  .apurei-shell {
    flex-direction: column;
  }

  .apurei-main {
    padding-top: 54px; /* altura da topbar fixa */
    width: 100%;
  }

  /* ── Barra superior fixa (mobile) ─────────────────────────── */
  .apurei-mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    padding: 0 16px;
    z-index: 150;
    gap: 12px;
  }

  .apurei-mobile-brand {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
  }

  .apurei-mobile-brand .apurei-sb-logo-text {
    font-family: var(--font-serif);
    font-size: 17px;
    font-weight: 500;
    color: var(--c-ink);
    letter-spacing: -0.02em;
  }

  .apurei-mobile-brand .apurei-sb-logo-sub {
    font-size: 10px;
    color: var(--c-muted);
  }

  /* ── Botão hamburguer ─────────────────────────────────────── */
  .apurei-hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    color: var(--c-ink);
    flex-shrink: 0;
    transition: background 0.12s;
  }

  .apurei-hamburger:hover { background: var(--c-bg); }

  /* ── Backdrop escurecido ──────────────────────────────────── */
  .apurei-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.38);
    z-index: 190;
    pointer-events: all;
    cursor: pointer;
  }

  .apurei-drawer-backdrop.active { display: block; }

  /* ── Sidebar → drawer deslizante ─────────────────────────── */
  .apurei-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 284px;
    min-width: 0;
    height: 100vh;
    z-index: 200;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow-y: auto;
    padding: 0;
    gap: 0;
    border-right: 1px solid var(--c-border);
    border-bottom: none;
    box-shadow: none;
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.28s ease;
  }

  .apurei-sidebar.open {
    left: 0;
    box-shadow: 6px 0 28px rgba(0, 0, 0, 0.14);
  }

  /* Botão de fechar (visível no drawer) */
  .apurei-sidebar-close {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 14px 16px 4px;
    flex-shrink: 0;
    color: var(--c-muted);
    transition: color 0.12s;
  }

  .apurei-sidebar-close:hover { color: var(--c-ink); }

  /* Restaura layout normal do logo dentro do drawer */
  .apurei-sb-logo {
    padding: 8px 16px 14px;
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
  }

  /* Botão "nova apuração" normal dentro do drawer */
  .apurei-sb-nova {
    margin: 10px 14px 14px;
    width: calc(100% - 28px);
    flex-shrink: 0;
  }

  /* Histórico visível dentro do drawer */
  .apurei-sb-hist-label { display: block; }
  .apurei-sb-hist       { display: block; flex: 1; }

  /* Footer da sidebar restaurado no drawer */
  .apurei-sb-footer {
    border-top: 1px solid var(--c-border);
    border-left: none;
    padding: 6px 8px 16px;
    flex-shrink: 0;
  }

  /* ── Conteúdo principal: posição e espaçamento ────────────── */
  .apurei-zone-form {
    padding: 16px 14px 20px;
    justify-content: flex-start;
    gap: 16px;
  }

  .apurei-greeting-title { font-size: 22px; }

  .apurei-chat-box { border-radius: 10px; }

  .apurei-form-card { padding: 24px 20px; }

  /* ── Resultado ────────────────────────────────────────────── */
  .apurei-result-body {
    padding: 16px;
  }

  .apurei-cards {
    grid-template-columns: 1fr;
  }

  .apurei-result-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .apurei-recalc-banner {
    white-space: normal;
    width: 100%;
  }
}

@media (max-width: 640px) {
  .apurei-login-card { padding: 28px 24px; }

  .apurei-card-main .apurei-card-value { font-size: 24px; }

  .apurei-result-actions { flex-direction: column; }

  .apurei-table { font-size: 12px; }
  .apurei-table th,
  .apurei-table td { padding: 10px 12px; }

  .apurei-totais-grid { gap: 6px; }
  .apurei-totais-item { min-width: 72px; padding: 8px 10px; }
  .apurei-totais-valor { font-size: 11px; }

  .apurei-flag-select { max-width: 100%; width: 100%; }
  .apurei-flag       { display: block; margin: 4px 0 0 0; }
}
