:root {
  --vinho: #8c1d2f;
  --vinho-escuro: #6d1524;
  --vinho-claro: #fdf0f2;
  --fundo: #f7f6f4;
  --card: #ffffff;
  --texto: #1f1b16;
  --muted: #8a8177;
  --borda: #eae6e0;
  --erro: #b3261e;
  --ok: #2e7d32;
  --ok-claro: #e8f3e9;
  --aviso: #b26a00;
  --aviso-claro: #fff4e0;
  --sombra: 0 1px 3px rgba(30, 20, 15, 0.06);
  --sombra-hover: 0 6px 20px rgba(30, 20, 15, 0.12);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--fundo); color: var(--texto); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.erro { color: var(--erro); }
h1 { font-family: Georgia, 'Times New Roman', serif; font-weight: 700; margin: 0; font-size: 1.7rem; }

/* ---- login (split, padrão G.Geller) ---- */
#login-view { min-height: 100vh; }
.login-split { display: grid; grid-template-columns: 42% 1fr; min-height: 100vh; }
.login-painel { background: linear-gradient(170deg, var(--vinho) 0%, var(--vinho-escuro) 100%); color: #fff; display: flex; align-items: center; justify-content: center; padding: 3rem; }
.lp-conteudo { text-align: center; max-width: 340px; }
.lp-marca { font-family: Georgia, 'Times New Roman', serif; font-size: 3rem; font-weight: 700; letter-spacing: 0.5px; }
.lp-linha { width: 110px; height: 2px; background: rgba(255,255,255,0.7); margin: 0.9rem auto; }
.lp-sub { letter-spacing: 4px; font-size: 0.78rem; color: #e6cdd2; }
.lp-tagline { margin-top: 2.2rem; color: #e9b9c1; font-size: 1.05rem; line-height: 1.55; }
.login-form { display: flex; align-items: center; justify-content: center; background: #fff; padding: 2rem; }
.lf-caixa { width: 100%; max-width: 380px; }
.lf-titulo { font-family: Georgia, 'Times New Roman', serif; font-size: 2rem; margin: 0 0 0.3rem; color: var(--texto); }
.lf-sub { color: var(--muted); margin: 0 0 1.6rem; }
#google-btn { display: flex; }
#dev-login { margin-top: 1.2rem; display: flex; gap: 0.5rem; }
#dev-login input { flex: 1; }
@media (max-width: 760px) {
  .login-split { grid-template-columns: 1fr; }
  .login-painel { min-height: 34vh; padding: 2rem; }
  .lp-tagline { margin-top: 1.2rem; }
}

/* ---- header ---- */
header { display: flex; align-items: center; gap: 1.6rem; padding: 0.55rem 1.4rem; background: #fff; border-bottom: 1px solid var(--borda); flex-wrap: wrap; position: sticky; top: 0; z-index: 50; }
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand-nome { font-family: Georgia, serif; font-weight: 700; font-size: 1.25rem; color: var(--vinho); }
.brand-sub { font-size: 0.6rem; letter-spacing: 2.5px; color: var(--muted); }
nav { display: flex; gap: 0.35rem; flex: 1; flex-wrap: wrap; }
nav button { display: inline-flex; align-items: center; gap: 0.45rem; background: none; border: none; color: #5f574e; padding: 0.55rem 1rem; cursor: pointer; border-radius: 10px; font-size: 0.93rem; font-weight: 500; }
nav button svg { width: 17px; height: 17px; }
nav button.ativo { background: #f1eeea; color: var(--texto); font-weight: 600; }
nav button:hover { background: #f1eeea; }
.user-box { display: flex; align-items: center; gap: 0.55rem; font-size: 0.9rem; }
.user-box img { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--vinho-claro); }
button.link { background: none; border: none; color: var(--vinho); cursor: pointer; text-decoration: underline; font-size: 0.85rem; }

main { max-width: 1240px; margin: 0 auto; padding: 1.4rem 1.2rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }

/* ---- inputs e botões ---- */
input, select, textarea { padding: 0.55rem 0.75rem; border: 1px solid var(--borda); border-radius: 10px; font-size: 0.92rem; background: #fff; color: var(--texto); font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #d9b3ba; border-color: var(--vinho); }
button { font-family: inherit; }
button.primario { background: var(--vinho); color: #fff; border: none; padding: 0.55rem 1.15rem; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 0.92rem; }
button.primario:hover { background: var(--vinho-escuro); }
button.primario:disabled { opacity: 0.5; cursor: wait; }
button.secundario { background: #fff; color: var(--texto); border: 1px solid var(--borda); padding: 0.5rem 1rem; border-radius: 10px; cursor: pointer; font-weight: 500; }
button.secundario:hover { border-color: var(--vinho); color: var(--vinho); }
button.perigo { background: #fff; color: var(--erro); border: 1px solid #f0c9c6; padding: 0.45rem 0.9rem; border-radius: 10px; cursor: pointer; }
button.perigo:hover { background: #fdecea; }

/* ---- filtros ---- */
.filtros { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filtros input[type="search"] { flex: 2; min-width: 230px; }

/* ---- grid de livros ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.card-livro { background: var(--card); border: 1px solid var(--borda); border-radius: 14px; cursor: pointer; display: flex; flex-direction: column; transition: box-shadow 0.15s, transform 0.15s; overflow: hidden; box-shadow: var(--sombra); }
.card-livro:hover { box-shadow: var(--sombra-hover); transform: translateY(-2px); }
.card-livro .capa { aspect-ratio: 3 / 4; background: linear-gradient(155deg, #f1eae2, #e2d5c3); display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.card-livro .capa img { width: 100%; height: 100%; object-fit: cover; }
.card-livro .capa .sem-capa { font-family: Georgia, serif; color: #a3927b; font-size: 0.82rem; text-align: center; padding: 0.8rem; line-height: 1.35; }
.card-livro .capa .selo { position: absolute; top: 8px; left: 8px; display: flex; flex-direction: column; gap: 4px; }
.card-corpo { padding: 0.7rem 0.85rem 0.85rem; display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.card-livro h3 { margin: 0; font-size: 0.93rem; line-height: 1.3; font-weight: 600; }
.card-livro .autor { color: var(--muted); font-size: 0.8rem; }
.badges { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: auto; padding-top: 0.45rem; }
.badge { font-size: 0.7rem; padding: 0.18rem 0.55rem; border-radius: 999px; background: var(--fundo); border: 1px solid var(--borda); color: var(--muted); font-weight: 500; }
.badge.area { background: var(--vinho-claro); color: var(--vinho); border-color: #efd4d9; }
.badge.lido { background: var(--ok-claro); color: var(--ok); border-color: #cde5cf; }
.badge.lendo { background: var(--aviso-claro); color: var(--aviso); border-color: #f3ddb5; }
.badge.emprestado { background: #fdecea; color: var(--erro); border-color: #f5cbc7; }

/* ---- modal ---- */
#modal { position: fixed; inset: 0; background: rgba(30, 20, 15, 0.5); display: flex; align-items: flex-start; justify-content: center; padding: 3vh 1rem; z-index: 100; overflow-y: auto; backdrop-filter: blur(2px); }
.modal-caixa { background: var(--card); border-radius: 16px; max-width: 760px; width: 100%; padding: 1.6rem; position: relative; margin-bottom: 3vh; }
.modal-fechar { position: absolute; top: 0.9rem; right: 1.1rem; background: var(--fundo); border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); border-radius: 50%; width: 32px; height: 32px; }
.modal-caixa h2 { margin-top: 0; font-family: Georgia, serif; color: var(--vinho); padding-right: 2.2rem; }
.detalhe-topo { display: flex; gap: 1.2rem; }
.detalhe-topo .capa-g { width: 150px; min-width: 150px; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: linear-gradient(155deg, #f1eae2, #e2d5c3); box-shadow: var(--sombra); }
.detalhe-topo .capa-g img { width: 100%; height: 100%; object-fit: cover; }
.ficha { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 1rem; font-size: 0.9rem; margin: 0.6rem 0; flex: 1; align-content: start; }
.ficha div b { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; display: block; letter-spacing: 0.5px; }
.secao { border-top: 1px solid var(--borda); margin-top: 1.1rem; padding-top: 1rem; }
.secao h4 { margin: 0 0 0.6rem; font-family: Georgia, serif; color: var(--vinho); font-size: 1.02rem; }
.estrelas { cursor: pointer; font-size: 1.35rem; letter-spacing: 2px; user-select: none; color: #d9a520; }
.estrelas .off { opacity: 0.22; }
.comentario { background: var(--fundo); border-radius: 10px; padding: 0.65rem 0.85rem; margin-bottom: 0.5rem; font-size: 0.9rem; }
.comentario .meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 0.25rem; display: flex; justify-content: space-between; }
.linha { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.4rem 0; }
.linha textarea { flex: 1; min-height: 55px; }

/* ---- tabelas ---- */
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 14px; overflow: hidden; font-size: 0.9rem; box-shadow: var(--sombra); border: 1px solid var(--borda); }
th, td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--borda); }
th { background: #faf9f7; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; }
tr:last-child td { border-bottom: none; }
tr.atrasado td { background: #fdf0ef; }

/* ---- dashboard ---- */
.cards-resumo { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.9rem; margin-bottom: 1.3rem; }
.card-num { background: var(--card); border: 1px solid var(--borda); border-radius: 14px; padding: 1rem 1.1rem; display: flex; align-items: center; gap: 0.9rem; box-shadow: var(--sombra); }
.card-num.alerta { background: #fdf0ef; border-color: #f5cbc7; }
.card-num .icone { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.icone.i1 { background: var(--vinho-claro); }
.icone.i2 { background: var(--ok-claro); }
.icone.i3 { background: var(--aviso-claro); }
.icone.i4 { background: #fdecea; }
.icone.i5 { background: #ece9f7; }
.card-num .num { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.card-num .rotulo { font-size: 0.76rem; color: var(--muted); }
.duas-colunas { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.painel { background: var(--card); border: 1px solid var(--borda); border-radius: 14px; padding: 1.1rem 1.2rem; box-shadow: var(--sombra); }
.painel h4 { margin: 0 0 0.7rem; font-family: Georgia, serif; color: var(--vinho); }
.painel ul { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; }
.painel li { margin-bottom: 0.35rem; }
.painel a { color: var(--vinho); }

/* ---- barras por área ---- */
.area-barra { margin-bottom: 0.55rem; font-size: 0.85rem; }
.area-barra .topo { display: flex; justify-content: space-between; margin-bottom: 0.2rem; }
.area-barra .trilha { height: 8px; background: var(--fundo); border-radius: 999px; overflow: hidden; }
.area-barra .preenchido { height: 100%; background: var(--vinho); border-radius: 999px; }

/* ---- assistente (chat) ---- */
.chat-caixa { background: var(--card); border: 1px solid var(--borda); border-radius: 16px; box-shadow: var(--sombra); display: flex; flex-direction: column; height: calc(100vh - 240px); min-height: 420px; }
#chat-mensagens { flex: 1; overflow-y: auto; padding: 1.2rem; display: flex; flex-direction: column; gap: 0.8rem; }
.msg { max-width: 78%; padding: 0.7rem 1rem; border-radius: 14px; font-size: 0.93rem; line-height: 1.5; white-space: pre-wrap; }
.msg.usuario { align-self: flex-end; background: var(--vinho); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistente { align-self: flex-start; background: var(--fundo); border: 1px solid var(--borda); border-bottom-left-radius: 4px; }
.msg.pensando { align-self: flex-start; color: var(--muted); font-style: italic; background: none; border: none; }
.chat-input { display: flex; gap: 0.6rem; padding: 0.9rem; border-top: 1px solid var(--borda); }
.chat-input textarea { flex: 1; resize: none; }

/* ---- admin ---- */
.abas { display: flex; gap: 0.35rem; margin-bottom: 1rem; flex-wrap: wrap; }
.abas button { background: #fff; border: 1px solid var(--borda); padding: 0.45rem 1.05rem; border-radius: 999px; cursor: pointer; font-weight: 500; }
.abas button.ativo { background: var(--vinho); color: #fff; border-color: var(--vinho); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
.form-grid .full { grid-column: 1 / -1; }
label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; font-weight: 600; display: block; margin-bottom: 0.2rem; letter-spacing: 0.5px; }
.form-grid input, .form-grid select { width: 100%; }

/* ---- toast ---- */
#toast { position: fixed; bottom: 1.3rem; left: 50%; transform: translateX(-50%); background: var(--texto); color: #fff; padding: 0.75rem 1.4rem; border-radius: 12px; z-index: 200; box-shadow: var(--sombra-hover); font-size: 0.92rem; }

@media (max-width: 640px) {
  .ficha, .duas-colunas, .form-grid { grid-template-columns: 1fr; }
  header { gap: 0.6rem; }
  .detalhe-topo { flex-direction: column; }
  .detalhe-topo .capa-g { width: 130px; }
  .msg { max-width: 92%; }
}
