/* ===== Reset e base ===== */
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: var(--background); color: var(--text); }

/* ===== Tema vermelho e branco ===== */
:root {
  --primary: #c62828;
  --primary-dark: #a61f1f;
  --primary-light: #fdecec;
  --background: #f6f6f6;
  --surface: #ffffff;
  --text: #202124;
}

/* ===== Cabeçalho ===== */
header {
  background: var(--primary);
  color: #fff;
  padding: 18px 16px;
  position: sticky;
  top: 0;
  z-index: 4;
}
header h1 { margin: 0; font-size: 22px; }

/* ===== Layout principal ===== */
main { max-width: 760px; margin: auto; padding: 18px 14px 90px; }
.page { display: none; }
.page.active { display: block; }
h2 { font-size: 27px; margin: 5px 0 18px; color: var(--text); }
h3 { color: var(--text); }

/* ===== Grid e cards ===== */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card, .listitem {
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 15px;
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  margin-bottom: 10px;
}
.card > .item { background: #fafafa; }
.metric { font-size: 24px; font-weight: 800; margin-top: 5px; color: var(--text); }

/* ===== Utilitários ===== */
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row { display: flex; gap: 8px; align-items: end; }
.row > * { flex: 1; }
.item {
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 12px;
  margin: 8px 0;
}
.total { font-size: 24px; font-weight: 800; color: var(--text); }
.muted { font-size: 13px; color: #666; }
.empty { text-align: center; color: #777; padding: 35px; }
a { color: var(--primary); }

/* ===== Botões ===== */
button {
  border: 0;
  border-radius: 10px;
  padding: 12px 15px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
button:hover { background: var(--primary-dark); }
button.secondary { background: #eeeeee; color: #333; }
button.danger { background: #b91c1c; color: #fff; }

/* ===== Inputs ===== */
input, select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #d0d0d0;
  border-radius: 10px;
  font: inherit;
  margin: 5px 0 12px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary-light);
  border-color: var(--primary);
}
label { font-size: 13px; font-weight: 700; }

/* ===== Navegação inferior ===== */
nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #ddd;
  display: flex;
  z-index: 10;
}
nav button {
  flex: 1;
  background: #fff !important;
  color: #666 !important;
  border-radius: 0;
  padding: 9px 3px;
  font-size: 12px;
}
nav button.active { color: var(--primary) !important; }

/* ===== Modal / Bottom sheet ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 20;
  align-items: flex-end;
}
.modal.show { display: flex; }
.sheet {
  background: #fff;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  padding: 20px;
  border-radius: 20px 20px 0 0;
}
@media (min-width: 700px) {
  .modal { align-items: center; }
  .sheet { max-width: 650px; border-radius: 18px; }
}

/* ✅ ===== IMPRESSÃO — NOVA ABORDAGEM ===== */
@media print {
  /* Esconde TUDO por padrão */
  header, nav, main, .modal, .page, .no-print {
    display: none !important;
  }

  /* Mostra apenas o conteúdo de impressão */
  body {
    background: #fff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Quando o body foi substituído pelo conteúdo de impressão */
  body.printing {
    display: block !important;
  }

  body.printing > * {
    display: block !important;
  }

  /* Estilos da tabela de impressão */
  body.printing table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
  }

  body.printing th {
    background: #f4f4f4;
    text-align: left;
    padding: 10px;
    border-bottom: 2px solid #ccc;
    font-weight: 700;
  }

  body.printing th:last-child {
    text-align: right;
  }

  body.printing td {
    padding: 10px;
    border-bottom: 1px solid #eee;
  }

  body.printing td:last-child {
    text-align: right;
    font-weight: 600;
  }

  body.printing h1 {
    margin: 0 0 5px;
    font-size: 22px;
  }

  body.printing .cliente,
  body.printing .data {
    font-size: 14px;
    margin-bottom: 5px;
    color: #444;
  }

  body.printing .data {
    margin-bottom: 25px;
    color: #666;
  }

  body.printing .total {
    margin-top: 20px;
    font-size: 20px;
    text-align: right;
  }

  body.printing .total b {
    color: #000;
  }

  /* Configuração da página A4 */
  @page {
    size: A4;
    margin: 15mm;
  }
}

/* ===== Tela de login ===== */
#loginScreen {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid #eee;
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,.10);
}
.login-logo {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  background: #dc2626;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 900;
  margin-bottom: 18px;
}
.login-box h1 { margin: 0 0 8px; font-size: 27px; color: #111; }
.login-box p { margin: 0 0 22px; color: #666; }
.login-box label { display: block; font-weight: 700; margin: 14px 0 7px; color: #222; }
.login-box input {
  width: 100%;
  padding: 14px;
  border: 1px solid #ddd;
  border-radius: 12px;
  font-size: 16px;
}
.login-box button {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: #dc2626;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
}
.login-box .login-signup {
  background: #fff;
  color: #dc2626;
  border: 1px solid #dc2626;
}
.login-error {
  display: none;
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 14px;
}
.login-note { font-size: 12px !important; margin-top: 14px !important; color: #888 !important; }
body.auth-locked > *:not(#loginScreen) { display: none !important; }
