/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --canvas: #F5F5F5;
  --surface: #FFFFFF;
  --surface-sunken: #EEEEEE;
  --ink: #171717;
  --ink-soft: #555555;
  --line: #D7D7D7;

  --navy: #111111;
  --steel: #C81020;
  --rust: #C81020;

  --green: #2F7D5C;
  --green-soft: #DCEEE5;
  --amber: #8A6414;
  --amber-soft: #F1E7CC;
  --red: #B20E1D;
  --red-soft: #FCE7E9;

  --radius: 4px;
  --font-display: "Big Shoulders", "Inter", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --tap: 44px; /* alvo mínimo de toque */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.01em; margin: 0; color: var(--navy); }
h1 { font-size: 30px; line-height: 1.1; }
h2 { font-size: 18px; }
p { margin: 4px 0 0; color: var(--ink-soft); }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }

:focus-visible { outline: 2px solid var(--steel); outline-offset: 2px; }

/* ==========================================================================
   Marca, splash e login
   ========================================================================== */
.brand-mark {
  width: 36px; height: 36px; border-radius: var(--radius);
  background: var(--rust); color: #fff;
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.splash {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}

.login {
  --navy: #111111;
  --steel: #c81020;
  --rust: #c81020;
  --ink: #171717;
  --ink-soft: #555555;
  --line: #d7d7d7;
  --red: #b20e1d;
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 28px 20px;
  background: #080808;
}

.login-card {
  background: var(--surface);
  width: 100%; max-width: 440px;
  border-radius: 12px;
  padding: 32px 28px;
  border-top: 4px solid var(--rust);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.login-brand { display: flex; align-items: center; justify-content: center; background: #080808; border-radius: 6px; margin-bottom: 24px; overflow: hidden; }
.login-logo { display: block; width: min(100%, 270px); height: auto; object-fit: contain; }

.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.login-msg { min-height: 20px; font-size: 13.5px; color: var(--red); }
.login-msg.ok { color: var(--green); }
.login .btn { min-height: 44px; }
.login .btn.primary:hover { background: #a80d1b; }
.login .btn.link:hover { color: #a80d1b; text-decoration: underline; }
.login .login-form input { min-height: 46px; font-size: 16px; }
.login .login-form input:focus { border-color: var(--steel); box-shadow: 0 0 0 3px rgba(200, 16, 32, 0.15); }

/* ==========================================================================
   Layout (desktop)
   ========================================================================== */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.topbar, .sidebar-overlay { display: none; }

.sidebar {
  background: var(--navy); color: #FFFFFF;
  display: flex; flex-direction: column;
  padding: 24px 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,0.12); margin-bottom: 18px; }
.brand-logo { display: block; width: 84px; height: auto; flex-shrink: 0; border-radius: var(--radius); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: var(--font-display); font-size: 19px; letter-spacing: 0.02em; }
.brand-text small { color: #BDBDBD; font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  text-align: left; background: none; border: none; color: #D6D6D6;
  padding: 11px 12px; min-height: var(--tap);
  border-radius: var(--radius); cursor: pointer;
  font-size: 14.5px; font-weight: 500; border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(200,16,32,0.18); color: #fff; border-left-color: var(--rust); }

.sidebar-footer { padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }

.status-pill {
  font-size: 12px; padding: 8px 10px; border-radius: var(--radius);
  background: rgba(255,255,255,0.06); color: #D6D6D6; border: 1px solid rgba(255,255,255,0.1);
}
.status-pill.simulado { border-color: #B58A2C; color: #F1D8A0; }

.user-box {
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.12);
}
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.user-actions .btn.small { min-height: var(--tap); text-align: center; }
.user-actions #btn-alterar-senha { flex: 1 1 140px; }
.user-actions #btn-sair { flex: 0 0 auto; }
.user-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.user-info strong { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info small { color: #BDBDBD; font-size: 12px; }

.content { padding: 32px 40px 64px; min-width: 0; max-width: 1180px; width: 100%; }

.view-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }

/* ==========================================================================
   KPIs
   ========================================================================== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }

.kpi-card {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--steel);
  border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.kpi-card.accent { border-left-color: var(--rust); }
.kpi-label { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }
.kpi-value { font-family: var(--font-display); font-size: 28px; color: var(--navy); font-weight: 700; overflow-wrap: anywhere; }

/* ==========================================================================
   Painéis e tabelas
   ========================================================================== */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; }
.panel-header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }

thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface-sunken); white-space: nowrap;
}
tbody td { padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFAFA; }
.vazio-linha td { color: var(--ink-soft); font-style: italic; text-align: center; padding: 24px; }

.acoes { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: flex-end; }

.placa {
  font-family: var(--font-mono); font-weight: 600; letter-spacing: 0.06em;
  background: #F5F5F5; border: 1px solid #C9C9C9; border-top: 3px solid var(--steel);
  border-radius: 2px; padding: 3px 7px; display: inline-block; color: var(--navy);
}

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px; }
.badge.estoque, .badge.ativo, .badge.admin { background: var(--green-soft); color: var(--green); }
.badge.reservado, .badge.simulado, .badge.sucesso { background: var(--amber-soft); color: var(--amber); }
.badge.vendido, .badge.operador { background: var(--surface-sunken); color: var(--ink-soft); }
.badge.erro, .badge.inativo { background: var(--red-soft); color: var(--red); }

/* ==========================================================================
   Botões
   ========================================================================== */
.btn {
  font-weight: 600; font-size: 14px; padding: 10px 16px; min-height: 40px;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
}
.btn.primary { background: var(--rust); color: #fff; }
.btn.primary:hover { background: #A80D1B; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--navy); }
.btn.ghost:hover { background: var(--surface-sunken); }
.btn.ghost.light { border-color: rgba(255,255,255,0.25); color: #FFFFFF; }
.btn.ghost.light:hover { background: rgba(255,255,255,0.08); }
.btn.link { background: none; border: none; color: var(--steel); padding: 4px 0; min-height: 0; text-align: left; }
.btn.link.perigo { color: var(--red); }
.btn.small { padding: 6px 12px; font-size: 13px; min-height: 34px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.form-grid input[readonly] { background: #EEEEEE; color: #555555; cursor: not-allowed; }
.relatorio-controles { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 0 20px; }
.relatorio-controles label { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: min(240px, 100%); font-size: 14px; }
.relatorio-controles select { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); min-height: 44px; }
.relatorio-nota { padding: 0 20px; color: var(--ink-soft); font-size: 14px; line-height: 1.6; }
#relatorio-mensal h3 { padding: 0 20px; font-size: 16px; }

.icon-btn {
  background: none; border: none; width: var(--tap); height: var(--tap);
  display: flex; flex-direction: column; justify-content: center; gap: 5px; align-items: center; cursor: pointer;
}
.icon-btn span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

/* ==========================================================================
   Formulários
   ========================================================================== */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.toolbar input, .toolbar select, .filtro-periodo input {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); min-height: 40px;
}
.toolbar input[type="search"] { flex: 1; min-width: 0; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; padding: 20px; }
.form-grid label, .login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-soft); min-width: 0; }
.form-grid input, .form-grid select, .form-grid textarea, .login-form input {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); min-height: 40px; width: 100%;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus, .login-form input:focus {
  outline: none; border-color: var(--steel); box-shadow: 0 0 0 3px rgba(200, 16, 32, 0.15);
}
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.campos-extra { display: none; grid-template-columns: repeat(2, 1fr); gap: 14px 18px; }
.campos-extra.ativa { display: grid; }

/* ==========================================================================
   Abas
   ========================================================================== */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab-btn {
  background: none; border: none; padding: 10px 16px; min-height: var(--tap);
  font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab-btn.active { color: var(--navy); border-bottom-color: var(--rust); }

/* ==========================================================================
   Financeiro / avisos
   ========================================================================== */
.filtro-periodo { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filtro-periodo label { display: flex; flex-direction: column; font-size: 12px; color: var(--ink-soft); gap: 4px; }

.resumo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); }
.resumo-item { background: var(--surface); padding: 18px 20px; min-width: 0; }
.resumo-item span { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }
.resumo-item strong { font-family: var(--font-display); font-size: 22px; color: var(--navy); overflow-wrap: anywhere; }
.resumo-item.destaque strong { color: var(--rust); }

.banner {
  background: var(--amber-soft); border: 1px solid #E0CB92; color: #5E4710;
  padding: 14px 18px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; line-height: 1.6;
}

/* ==========================================================================
   Modais e toast
   ========================================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 640px; max-height: 90vh; max-height: 90dvh; overflow-y: auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-close { background: none; border: none; font-size: 28px; cursor: pointer; color: var(--ink-soft); line-height: 1; width: var(--tap); height: var(--tap); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-body p { margin: 0; }
.modal-recibo { max-width: 760px; }
.recibo-acoes { padding: 0 20px 20px; }
.recibo-marca { display: flex; align-items: center; gap: 20px; }
.recibo-marca img { width: 130px; height: auto; }
.recibo-marca strong { font-size: 22px; }
.recibo-aviso { border: 2px solid var(--rust); padding: 12px; color: var(--ink); font-weight: 600; }
.recibo-dados { margin: 0; }
.recibo-dados div { padding: 8px 0; border-bottom: 1px solid var(--line); break-inside: avoid; }
.recibo-dados dt { font-size: 12px; color: var(--ink-soft); }
.recibo-dados dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@media print {
  body.imprimindo-recibo { background: #fff; color: #000; }
  body.imprimindo-recibo > * { display: none !important; }
  body.imprimindo-recibo > #modal-recibo { display: block !important; position: static; background: #fff; padding: 0; }
  body.imprimindo-recibo .modal-recibo { width: 100%; max-width: none; max-height: none; overflow: visible; border-radius: 0; }
  body.imprimindo-recibo .modal-header, body.imprimindo-recibo .recibo-acoes { display: none; }
  body.imprimindo-recibo .recibo-aviso { border-color: #000; }
  body.imprimindo-recibo .modal-body { padding: 0; }
}
.modal-body pre {
  margin: 0; padding: 12px; background: var(--surface-sunken); border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow-y: auto;
}

.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); right: 24px;
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease; pointer-events: none; max-width: 360px; z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.erro { background: var(--red); }

/* ==========================================================================
   Tablet / celular
   ========================================================================== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  /* barra superior com botão de menu */
  .topbar {
    display: flex; align-items: center; gap: 4px;
    position: sticky; top: 0; z-index: 40;
    background: var(--navy); color: #fff;
    padding: calc(4px + env(safe-area-inset-top)) 8px 4px;
  }
  .topbar-title { font-family: var(--font-display); font-size: 20px; letter-spacing: 0.02em; }

  /* menu lateral vira gaveta */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 290px; max-width: 85vw; height: auto;
    transform: translateX(-100%); transition: transform 0.22s ease; z-index: 60;
    padding-top: calc(24px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .sidebar.aberto { transform: none; }
  .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 50; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .sidebar-overlay.aberto { opacity: 1; pointer-events: auto; }

  .content { padding: 20px 16px 48px; }
  h1 { font-size: 26px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-value { font-size: 22px; }
  .resumo-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
  /* inputs com 16px evitam o zoom automático do iPhone */
  button, input, select, textarea { font-size: 16px; }

  .view-header { align-items: stretch; flex-direction: column; }
  .view-header .btn { width: 100%; }

  .toolbar { flex-direction: column; }
  .form-grid, .campos-extra, .campos-extra.ativa { grid-template-columns: 1fr; padding: 16px; }
  .campos-extra.ativa { padding: 0; }
  .span-2 { grid-column: span 1; }
  .form-actions .btn { width: 100%; }
  .filtro-periodo { width: 100%; }
  .filtro-periodo label { flex: 1; min-width: 120px; }
  .filtro-periodo .btn { width: 100%; }

  /* TABELAS viram cartões: cada linha é um cartão, cada célula mostra seu rótulo */
  .table-wrap { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { position: absolute; left: -9999px; }
  tbody tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  tbody tr:last-child { border-bottom: none; }
  tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    padding: 5px 0; border: none; white-space: normal; text-align: right; overflow-wrap: anywhere;
  }
  tbody td::before { content: attr(data-label); font-weight: 600; font-size: 12.5px; color: var(--ink-soft); text-align: left; flex-shrink: 0; }
  tbody td:not([data-label])::before, .vazio-linha td::before { display: none; }
  .vazio-linha td { display: block; text-align: center; }
  td.celula-acoes { padding-top: 10px; }

  .btn.link { min-height: var(--tap); display: inline-flex; align-items: center; }

  /* modal vira folha de baixo para cima */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 94dvh; border-radius: 12px 12px 0 0; padding-bottom: env(safe-area-inset-bottom); }

  .toast { left: 16px; right: 16px; max-width: none; text-align: center; }
  .login-card { padding: 26px 20px; }
}

/* Formularios privados de alteracao e redefinicao de senha. */
dialog { max-width: min(420px, 90vw); padding: 24px; border: 1px solid #c62828; border-radius: 12px; color: #181818; background: #fff; }
dialog::backdrop { background: rgb(0 0 0 / 65%); }
dialog label { display: block; margin: 14px 0; }
dialog input { display: block; width: 100%; margin-top: 6px; }
dialog .senha-erro { color: #b71c1c; }
