/* ============================================================
   EQUIPADORA M&D — Design System v2
   Cor principal: vermelho #b20303
   ============================================================ */

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1c1c1c;
  --surface-3: #262626;
  --border: #2d2d2d;
  --border-strong: #3f3f3f;
  --text: #fafafa;
  --text-muted: #a3a3a3;
  --text-dim: #6b6b6b;

  /* === MARCA EQUIPADORA M&D — VERMELHO === */
  --accent: #b20303;
  --accent-hover: #8c0202;
  --accent-soft: rgba(178, 3, 3, 0.14);
  --accent-text: #ff6b6b;        /* leve mais claro pra texto sobre fundo escuro */

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.12);
  --info: #3b82f6;
  --info-soft: rgba(59, 130, 246, 0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.12);

  --max-mobile: 520px;
  --max-content: 1100px;
}

* { -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  min-height: 100vh;
}

/* === Container central de toda a SPA ===
   No mobile: ocupa tudo. No desktop: limita largura e centraliza
   pra não esticar feio em monitor. */
#app {
  max-width: var(--max-mobile);
  margin: 0 auto;
  position: relative;
  min-height: 100vh;
  background: var(--bg);
}

/* Em telas grandes, dá um respiro decorativo nas laterais */
@media (min-width: 768px) {
  body {
    background:
      radial-gradient(circle at 20% 0%, rgba(178, 3, 3, 0.06), transparent 40%),
      radial-gradient(circle at 80% 100%, rgba(178, 3, 3, 0.04), transparent 40%),
      var(--bg);
  }
  #app {
    max-width: 720px;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (min-width: 1100px) {
  #app { max-width: 820px; }
}

.font-display { font-family: "Archivo Black", sans-serif; letter-spacing: -0.03em; }
.font-heading { font-family: "Archivo", sans-serif; font-weight: 800; letter-spacing: -0.02em; }
.font-mono    { font-family: "JetBrains Mono", monospace; }

/* === Buttons === */
.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  padding: 16px 24px;
  border-radius: 14px;
  transition: transform 0.1s, background 0.2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: "Archivo", sans-serif; letter-spacing: -0.01em;
  width: auto;
}
.btn-primary:active, .btn-primary:hover { transform: scale(0.98); background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2); color: var(--text); font-weight: 600;
  padding: 14px 20px; border-radius: 14px; border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.15s;
  cursor: pointer;
}
.btn-secondary:active, .btn-secondary:hover { background: var(--surface-3); }

.btn-danger {
  background: transparent; color: var(--danger); font-weight: 600;
  padding: 14px 20px; border-radius: 14px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
}
.btn-danger:active, .btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

.btn-success {
  background: var(--success); color: #000; font-weight: 800;
  padding: 16px 24px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: "Archivo", sans-serif;
  cursor: pointer;
}
.btn-success:active, .btn-success:hover { transform: scale(0.98); filter: brightness(1.05); }

.btn-ghost {
  padding: 12px; border-radius: 12px; display: inline-flex;
  align-items: center; justify-content: center; color: var(--text);
  cursor: pointer;
}
.btn-ghost:active, .btn-ghost:hover { background: var(--surface-2); }

.btn-whatsapp {
  background: #25d366; color: #000; font-weight: 800;
  padding: 16px 24px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-family: "Archivo", sans-serif;
  cursor: pointer;
}
.btn-whatsapp:active, .btn-whatsapp:hover { transform: scale(0.98); background: #1ebe5d; }

.btn-soft {
  background: var(--surface-2); color: var(--text); font-weight: 600;
  padding: 10px 14px; border-radius: 10px; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  cursor: pointer; white-space: nowrap;
}
.btn-soft:active, .btn-soft:hover { background: var(--surface-3); }

/* === Inputs === */
.input {
  background: var(--surface-2); border: 1.5px solid var(--border); color: var(--text);
  padding: 14px 16px; border-radius: 12px; width: 100%; font-size: 16px;
  transition: border-color 0.15s;
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--accent); background: var(--surface-3); }
.input::placeholder { color: var(--text-dim); }
textarea.input { resize: vertical; min-height: 80px; font-family: inherit; }
.input-plate {
  font-family: "JetBrains Mono", monospace; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase; text-align: center; font-size: 20px;
}
.input-money {
  font-family: "JetBrains Mono", monospace; font-weight: 700; font-size: 18px; text-align: right;
}
.label {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 8px; display: block;
}
.label-required::after { content: " *"; color: var(--accent-text); }

/* === Fix para inputs de data/hora em mobile === */
input[type="date"],
input[type="time"],
input[type="datetime-local"] {
  min-width: 0; /* previne overflow */
  max-width: 100%;
  font-size: 16px; /* previne zoom automático no iOS */
  -webkit-appearance: none;
  appearance: none;
}

/* Fix específico para iOS/Safari */
input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.2em;
}

/* Ajusta grids para não estourarem */
.grid { display: grid; }
.grid-cols-2 { 
  grid-template-columns: repeat(2, minmax(0, 1fr)); 
  gap: 0.75rem;
}
.grid-cols-3 { 
  grid-template-columns: repeat(3, minmax(0, 1fr)); 
  gap: 0.75rem;
}

/* Previne overflow horizontal em todo o app */
.screen, .px-4 {
  max-width: 100%;
  overflow-x: hidden;
}

/* Fix para selects que podem estourar */
select.input {
  min-width: 0;
  max-width: 100%;
  text-overflow: ellipsis;
}

/* === Cards === */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
.card-interactive { transition: transform 0.1s, border-color 0.15s; cursor: pointer; }
.card-interactive:active, .card-interactive:hover { transform: scale(0.98); border-color: var(--border-strong); }

/* === Chips === */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
}
.chip-required { background: var(--accent-soft); color: var(--accent-text); border: 1px solid rgba(178,3,3,.35); }
.chip-done     { background: var(--success-soft); color: var(--success); border: 1px solid rgba(34,197,94,.25); }
.chip-optional { background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border); }
.chip-defect   { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.chip-warn     { background: var(--warn-soft); color: var(--warn); border: 1px solid rgba(245,158,11,.3); }
.chip-info     { background: var(--info-soft); color: var(--info); border: 1px solid rgba(59,130,246,.3); }

/* status / payment */
.status-aguardando   { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); }
.status-em_andamento { background: var(--info-soft); color: var(--info); border-color: rgba(59,130,246,.3); }
.status-pronto       { background: var(--accent-soft); color: var(--accent-text); border-color: rgba(178,3,3,.35); }
.status-entregue     { background: var(--success-soft); color: var(--success); border-color: rgba(34,197,94,.25); }
.status-cancelado    { background: var(--danger-soft); color: var(--danger); border-color: rgba(239,68,68,.3); }
.pay-pendente { background: var(--danger-soft); color: var(--danger); border-color: rgba(239,68,68,.3); }
.pay-parcial  { background: var(--warn-soft); color: var(--warn); border-color: rgba(245,158,11,.3); }
.pay-pago     { background: var(--success-soft); color: var(--success); border-color: rgba(34,197,94,.25); }

/* === Placa Mercosul === */
.plate-display {
  display: inline-flex; flex-direction: column; align-items: center;
  background: #fafafa; color: #000; border-radius: 8px; padding: 0;
  overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.plate-display .plate-top {
  background: #1e40af; color: #fff; width: 100%; padding: 3px 16px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.2em; text-align: center;
}
.plate-display .plate-body {
  font-family: "JetBrains Mono", monospace; font-weight: 700;
  font-size: 22px; padding: 8px 16px; letter-spacing: 0.12em;
}
.plate-display.sm .plate-top  { font-size: 8px; padding: 2px 10px; }
.plate-display.sm .plate-body { font-size: 15px; padding: 5px 10px; }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* === Toast === */
#toast-container {
  position: fixed; top: calc(env(safe-area-inset-top) + 16px); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 1000; pointer-events: none;
  padding: 0 16px; /* previne toast estourar nas laterais */
  max-width: 100vw;
  overflow: hidden;
}
.toast {
  background: var(--surface-3); border: 1px solid var(--border-strong);
  padding: 12px 18px; border-radius: 14px; animation: toast-in 0.2s ease-out;
  max-width: 90vw; box-shadow: 0 10px 30px rgba(0,0,0,0.5); pointer-events: auto;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px); } }

/* Textos de erro também precisam quebrar linha */
.text-danger, .text-error {
  word-wrap: break-word;
  max-width: 100%;
}

/* === Sheet === */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 40;
  animation: fade-in 0.2s;
}
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 0; z-index: 50;
  width: 100%; max-width: var(--max-mobile);
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slide-up 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  max-height: 88vh; overflow-y: auto;
}
@media (min-width: 768px) {
  .sheet { max-width: 720px; }
}
@media (min-width: 1100px) {
  .sheet { max-width: 820px; }
}
.sheet-handle { width: 40px; height: 4px; background: var(--border-strong); border-radius: 999px; margin: 0 auto 16px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateX(-50%) translateY(100%); } }

/* === Photo thumb === */
.photo-thumb {
  aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); position: relative; border: 1px solid var(--border);
  cursor: pointer;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .thumb-badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--danger); color: #fff; font-weight: 800; font-size: 11px;
  padding: 2px 8px; border-radius: 999px; font-family: "JetBrains Mono", monospace;
}

.stripe-accent { height: 4px; background: repeating-linear-gradient(-45deg, var(--accent) 0 10px, #000 10px 20px); }
.grid-pattern-bg {
  background-image:
    linear-gradient(rgba(178, 3, 3, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(178, 3, 3, 0.05) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* === Spinner === */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Canvas === */
.canvas-wrapper {
  position: relative; width: 100%; background: #000; border-radius: 14px;
  overflow: hidden; border: 1px solid var(--border); touch-action: none;
}
.canvas-wrapper canvas { display: block; width: 100%; height: auto; cursor: crosshair; }

/* === Header === */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

/* === Tabs === */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-mobile);
  z-index: 25;
  background: rgba(10,10,10,0.96); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: space-around;
}
@media (min-width: 768px) {
  .tabbar { max-width: 720px; }
}
@media (min-width: 1100px) {
  .tabbar { max-width: 820px; }
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 10px 4px 8px; gap: 4px;
  color: var(--text-dim); font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  transition: color 0.15s; min-width: 0;
  cursor: pointer;
}
.tab-item.active { color: var(--accent-text); }
.tab-item.active svg { stroke: var(--accent-text); }
.tab-item:active, .tab-item:hover { background: var(--surface-2); }

/* === Util === */
.text-muted   { color: var(--text-muted); }
.text-dim     { color: var(--text-dim); }
.text-accent  { color: var(--accent-text); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warn    { color: var(--warn); }
.text-info    { color: var(--info); }
.border-default  { border-color: var(--border); }
.bg-surface     { background: var(--surface); }
.bg-surface-2   { background: var(--surface-2); }
.bg-surface-3   { background: var(--surface-3); }
.bg-accent-soft { background: var(--accent-soft); }

.screen { animation: screen-in 0.2s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(4px); } }

/* === Stat card === */
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px;
}
.stat-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
}
.stat-value { font-family: "Archivo Black", sans-serif; font-size: 28px; line-height: 1; margin-top: 6px; }
.stat-sub   { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* === FAB === */
.fab {
  position: fixed; right: calc(16px + env(safe-area-inset-right));
  bottom: calc(78px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 30px; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); z-index: 26;
  cursor: pointer;
}
.fab:active, .fab:hover { transform: scale(0.95); }
@media (min-width: 768px) {
  .fab {
    /* Em desktop, alinhar ao container central */
    right: max(calc((100vw - var(--max-content)) / 2 + 16px), 16px);
  }
}

/* Botão fixo de bottom (Salvar/Confirmar etc) — alinhado ao container central */
.bottom-fixed {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-mobile);
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 24;
}
@media (min-width: 768px) {
  .bottom-fixed { max-width: 720px; }
}
@media (min-width: 1100px) {
  .bottom-fixed { max-width: 820px; }
}
