/* ===========================================================
   Casa — app.css  ·  identidade inspirada no Planner
   Preto & branco · DM Sans + Lora · acento periwinkle (#6470e6)
   =========================================================== */

:root {
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Lora', Georgia, 'Times New Roman', serif;

  --bg: #faf9fb;
  --surface: #ffffff;
  --surface-2: #f4f3f5;
  --surface-3: #ebe9ed;
  --border: #ebe9ed;
  --border-strong: #ddd9e0;

  --text: #1c1a1d;
  --text-soft: #76727a;
  --text-faint: #a8a4ab;

  --accent: #181818;
  --accent-hover: #000000;
  --accent-soft: #eceaee;

  --peri: #6470e6;
  --peri-soft: #ecebfb;

  --danger: #e5484d;
  --danger-soft: #fdecec;
  --warning: #c77d1a;
  --warning-soft: #fbf1e1;
  --success: #2f9e5e;
  --success-soft: #e6f4ec;

  --shadow-sm: 0 1px 2px rgba(24,24,24,.05);
  --shadow-md: 0 4px 14px rgba(24,24,24,.08);
  --shadow-lg: 0 16px 40px rgba(24,24,24,.16);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;

  --sidebar-w: 230px;
  --topbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }
h1, h2, h3, p { margin: 0; }
a { color: var(--peri); }

/* -------- Botões -------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 15px; font-size: 14px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
  transition: background .12s, border-color .12s, transform .04s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.link { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 14px; padding: 2px; }
.link:hover { text-decoration: underline; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: transparent; color: var(--text-soft);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* -------- Loading / boot -------- */
#loading-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 1000;
  background: linear-gradient(90deg, var(--accent), var(--peri));
  transition: width .25s ease, opacity .3s ease; opacity: 0;
}
#loading-bar.active { opacity: 1; }
.boot {
  position: fixed; inset: 0; z-index: 2000; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: var(--bg);
}
.boot.hide { opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.boot-spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   AUTENTICAÇÃO
   ========================================================= */
.auth-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 24px;
  background: radial-gradient(120% 80% at 50% -10%, var(--accent-soft), transparent 60%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 26px 22px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand h1 { font-family: var(--font-serif); font-size: 22px; font-weight: 600; }
.auth-brand p { font-size: 13px; color: var(--text-soft); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.auth-error { color: var(--danger); font-size: 13px; margin: -4px 0 0; }
.auth-error:empty { display: none; }
.auth-switch { margin-top: 16px; font-size: 14px; color: var(--text-soft); display: flex; gap: 6px; justify-content: center; }
.auth-forgot { display: block; margin: 10px auto 0; }
.auth-footer { font-size: 12px; color: var(--text-faint); }

/* =========================================================
   SHELL (sidebar + main + bottomnav)
   ========================================================= */
.app { min-height: 100dvh; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand strong { font-family: var(--font-serif); font-size: 19px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; border: none; background: transparent; border-radius: var(--radius-sm);
  color: var(--text-soft); font-size: 14.5px; font-weight: 600; text-align: left;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { flex-shrink: 0; }

.main { margin-left: var(--sidebar-w); min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 18px; background: rgba(250,249,251,.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: flex; align-items: center; gap: 9px; }
.topbar-brand img { display: none; }
.topbar-brand strong { font-family: var(--font-serif); font-size: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.view { flex: 1; padding: 20px 18px 40px; max-width: 1000px; width: 100%; margin: 0 auto; }

.bottomnav { display: none; }

/* =========================================================
   COMPONENTES
   ========================================================= */
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.view-h1 { font-family: var(--font-serif); font-size: 22px; font-weight: 600; }
.view-sub { color: var(--text-soft); font-size: 13.5px; margin-top: 2px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.card-k { font-size: 12.5px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .03em; }
.card-v { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.card-v.sm { font-size: 19px; }
.card-foot { font-size: 12.5px; color: var(--text-soft); margin-top: 4px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-head h3 { font-size: 15px; font-weight: 700; }
.panel-body { padding: 6px 6px; }

/* Linhas de lista */
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px;
  border-radius: var(--radius-sm); cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row + .row { border-top: 1px solid var(--border); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }
.row-amount { font-weight: 700; font-size: 14.5px; white-space: nowrap; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge-pago { background: var(--success-soft); color: var(--success); }
.badge-pendente { background: var(--surface-3); color: var(--text-soft); }
.badge-atrasado { background: var(--danger-soft); color: var(--danger); }
.badge-peri { background: var(--peri-soft); color: var(--peri); }
.badge-ia { background: var(--peri-soft); color: var(--peri); }

/* Barra de progresso */
.bar { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.over > i { background: var(--danger); }

/* Tabela */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-soft); }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }

/* Estado vazio */
.empty { text-align: center; padding: 40px 20px; color: var(--text-soft); }
.empty svg { opacity: .35; margin-bottom: 10px; }
.empty p { margin-bottom: 14px; }

/* Busca */
.searchbar { position: relative; margin-bottom: 14px; }
.searchbar input {
  width: 100%; padding: 11px 13px 11px 38px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface);
}
.searchbar svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }

/* Chips de filtro */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft);
  border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 600;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* =========================================================
   MODAL
   ========================================================= */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(24,24,24,.4);
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 560px; max-height: 92dvh; background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-family: var(--font-serif); font-size: 19px; font-weight: 600; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-body .field + .field, .modal-body .field-row + .field, .modal-body .field + .field-row { margin-top: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
.modal-foot { display: flex; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); }
.modal-foot .btn { flex: 1; }

/* Visualizador de PDF/imagem */
.viewer { display: grid; grid-template-columns: 1fr; gap: 0; height: 80dvh; }
.viewer-doc { position: relative; overflow: auto; background: var(--surface-2); touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
.viewer-media { width: 100%; height: 100%; transform-origin: top left; }
.viewer-media > iframe { width: 100%; height: 100%; border: 0; display: block; }
.viewer-media > img { width: 100%; height: 100%; object-fit: contain; display: block; }
.viewer-zoom { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; background: rgba(24,24,24,.85); color: #fff; border-radius: 999px; padding: 5px 8px; z-index: 6; box-shadow: var(--shadow-md); }
.viewer-zoom button { background: transparent; border: 0; color: #fff; width: 30px; height: 30px; border-radius: 50%; font-size: 19px; line-height: 1; }
.viewer-zoom button:hover { background: rgba(255,255,255,.16); }
.viewer-zoom .zl { font-size: 12.5px; min-width: 42px; text-align: center; }
.viewer-zoom .zf { width: auto; padding: 0 10px; font-size: 12.5px; }
.viewer-chat { display: flex; flex-direction: column; border-top: 1px solid var(--border); min-height: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 88%; padding: 9px 12px; border-radius: var(--radius); font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.ia { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.chat-msg.ia.loading { color: var(--text-soft); font-style: italic; }
.chat-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 999px; }

/* Toast */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 300; pointer-events: none; }
.toast { background: var(--accent); color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-md); animation: toastin .2s ease; }
.toast.danger { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }

.muted { color: var(--text-soft); }
.right { text-align: right; }
.spinner-sm { display: inline-block; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }

/* Mini gráfico de barras (gasto mês a mês) */
.barchart { display: flex; align-items: flex-end; gap: 10px; height: 170px; overflow-x: auto; padding-bottom: 2px; }
.barcol { flex: 1 0 40px; min-width: 40px; height: 100%; display: flex; flex-direction: column; align-items: center; }
.barcol .v { font-size: 11px; color: var(--text-soft); margin-bottom: 4px; }
.barcol .b { width: 60%; max-width: 36px; min-height: 4px; background: var(--accent); border-radius: 6px 6px 0 0; margin-top: auto; }
.barcol .l { font-size: 11px; color: var(--text-soft); margin-top: 7px; white-space: nowrap; }
/* Barra dividida (construtora × direto) */
.splitbar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.splitbar i { display: block; height: 100%; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* =========================================================
   RESPONSIVO — mobile
   ========================================================= */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding-bottom: calc(64px + var(--safe-bottom)); }
  .topbar-brand img { display: block; }
  .view { padding: 16px 14px 28px; }

  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + var(--safe-bottom)); justify-content: space-around;
  }
  .bottomnav .nav-item {
    flex-direction: column; gap: 3px; padding: 4px 6px; font-size: 11px; font-weight: 600;
    border-radius: var(--radius-sm); color: var(--text-soft); width: auto; min-width: 56px; text-align: center;
  }
  .bottomnav .nav-item span { font-size: 11px; }
  .bottomnav .nav-item.active { background: transparent; color: var(--accent); }
  .bottomnav .nav-item.active svg { color: var(--peri); }

  .modal-overlay { align-items: flex-end; }
  .field-row { flex-direction: column; gap: 14px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card { padding: 13px 14px; }
  .card-v { font-size: 20px; }
  .card-v.sm { font-size: 17px; }
  .view-h1 { font-size: 20px; }
  .view-head { gap: 8px; }
  .panel-head { padding: 13px 14px; }
}

@media (min-width: 861px) {
  .modal-overlay { align-items: center; padding: 24px; }
  .modal { border-radius: var(--radius-lg); }
}
