:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0f766e;
  --primary-dark: #0f4f4a;
  --danger: #dc2626;
  --warning: #ca8a04;
  --success: #16a34a;
  --shadow: 0 20px 45px rgba(15, 23, 42, .08);
  --radius: 18px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 0; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dff6f0, transparent 35%), linear-gradient(135deg, #f8fafc, #eef5f7); }
.login-card { width: min(440px, 100%); background: rgba(255,255,255,.92); border: 1px solid rgba(226,232,240,.8); border-radius: 28px; padding: 34px; box-shadow: var(--shadow); backdrop-filter: blur(10px); }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.logo { width: 48px; height: 48px; border-radius: 15px; background: linear-gradient(135deg, #0f766e, #1d4ed8); color: white; display: grid; place-items: center; font-weight: 900; letter-spacing: -.06em; }
.brand h1 { margin: 0; font-size: 24px; letter-spacing: -.04em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 13px; color: #334155; font-weight: 700; }
.input, input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: white; padding: 12px 14px; color: var(--text); outline: none; }
textarea { min-height: 92px; resize: vertical; }
.input:focus, input:focus, select:focus, textarea:focus { border-color: #14b8a6; box-shadow: 0 0 0 3px rgba(20,184,166,.15); }
.btn { padding: 11px 15px; border-radius: 12px; background: #e2e8f0; color: var(--text); font-weight: 800; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fee2e2; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 7px 10px; font-size: 12px; border-radius: 10px; }
.error { color: var(--danger); background: #fef2f2; border: 1px solid #fecaca; padding: 10px; border-radius: 12px; font-size: 14px; margin: 12px 0; }
.success { color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0; padding: 10px; border-radius: 12px; font-size: 14px; margin: 12px 0; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar { background: #0f172a; color: white; padding: 22px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { background: linear-gradient(135deg, #14b8a6, #3b82f6); }
.sidebar-brand h2 { margin: 0; font-size: 20px; }
.sidebar-brand p { margin: 4px 0 0; color: #94a3b8; font-size: 12px; }
.nav { display: grid; gap: 8px; }
.nav button { background: transparent; color: #cbd5e1; text-align: left; padding: 11px 12px; border-radius: 12px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.1); color: white; }
.userbox { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.12); color: #cbd5e1; font-size: 13px; }
.main { padding: 28px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -.05em; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 28px rgba(15, 23, 42, .05); padding: 18px; }
.card h2, .card h3 { margin: 0 0 12px; letter-spacing: -.03em; }
.stat { display: flex; flex-direction: column; gap: 8px; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat strong { font-size: 28px; letter-spacing: -.05em; }
.table-wrap { overflow: auto; border-radius: 15px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: white; min-width: 760px; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
th { background: #f8fafc; color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 900; white-space: nowrap; }
.status-ABERTO { background: #e0f2fe; color: #075985; }
.status-ORCAMENTO { background: #fef3c7; color: #92400e; }
.status-AGUARDANDO_APROVACAO { background: #ede9fe; color: #5b21b6; }
.status-FINALIZADO { background: #dcfce7; color: #166534; }
.status-RETIDO { background: #fee2e2; color: #991b1b; }
.status-AGUARDANDO_PECAS { background: #ffedd5; color: #9a3412; }
.status-EM_ANDAMENTO { background: #ccfbf1; color: #115e59; }
.status-FATURADO { background: #dbeafe; color: #1e40af; }
.priority-URGENTE { background: #fee2e2; color: #991b1b; }
.priority-ALTA { background: #ffedd5; color: #9a3412; }
.priority-MEDIA { background: #fef3c7; color: #92400e; }
.priority-BAIXA { background: #e2e8f0; color: #334155; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.48); display: grid; place-items: center; padding: 20px; z-index: 100; }
.modal { width: min(860px, 100%); max-height: 90vh; overflow: auto; background: white; border-radius: 22px; padding: 22px; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }
.timeline { display: grid; gap: 10px; max-height: 420px; overflow: auto; }
.log-row, .comment-row { border-left: 3px solid #14b8a6; padding: 10px 12px; background: #f8fafc; border-radius: 12px; }
.log-row strong, .comment-row strong { display: block; margin-bottom: 4px; }
.muted { color: var(--muted); }
.kpi-money { color: var(--primary); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.mobile-menu { display: none; }
.photo-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photo-preview img { width: 86px; height: 86px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.notice { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 12px; border-radius: 14px; margin-bottom: 14px; }
.code { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 14px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 13px; }
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; transform: translateX(-105%); transition: .2s ease; z-index: 80; }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu { display: inline-flex; }
  .main { padding: 18px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .topbar { align-items: center; }
  .form-grid { grid-template-columns: 1fr; }
}

/* v1.1 - anexos, assinatura eletrônica e layout celular */
.sidebar-scrim { display: none; }
.mobile-bottom-nav { display: none; }
.attachment-list, .signature-list { display: grid; gap: 10px; }
.attachment-row, .signature-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); background: #f8fafc; border-radius: 14px; }
.signature-row img { width: 160px; max-height: 70px; object-fit: contain; border: 1px solid var(--line); border-radius: 10px; background: white; padding: 4px; }
.signature-pad { width: 100%; min-height: 170px; border: 2px dashed #94a3b8; border-radius: 16px; background: white; touch-action: none; display: block; }
.signature-card hr, .card hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.detail-grid .timeline { max-height: 360px; }

@media (max-width: 700px) {
  body { background: #f8fafc; }
  .login-page { padding: 14px; align-items: start; padding-top: 32px; }
  .login-card { border-radius: 22px; padding: 22px; }
  .brand h1 { font-size: 20px; }
  .app-shell { display: block; padding-bottom: 78px; }
  .sidebar { width: 86vw; max-width: 320px; box-shadow: 24px 0 60px rgba(15,23,42,.32); }
  .sidebar.open + .main + .sidebar-scrim, .sidebar-scrim { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.34); z-index: 70; }
  .main { padding: 14px; }
  .topbar { position: sticky; top: 0; z-index: 50; background: rgba(248,250,252,.94); backdrop-filter: blur(10px); margin: -14px -14px 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .topbar h1 { font-size: 22px; line-height: 1.05; }
  .topbar p { font-size: 13px; }
  .topbar .actions { display: none; }
  .grid, .grid.cols-4, .grid.cols-3, .grid.cols-2 { gap: 12px; }
  .card { border-radius: 16px; padding: 14px; box-shadow: 0 8px 18px rgba(15,23,42,.045); }
  .stat strong { font-size: 24px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .tabs .btn { white-space: nowrap; }
  .table-wrap { border: 0; overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; min-width: 0; width: 100%; }
  thead { display: none; }
  tr { background: white; border: 1px solid var(--line); border-radius: 16px; margin-bottom: 12px; overflow: hidden; }
  td { border-bottom: 1px solid #edf2f7; padding: 10px 12px; }
  td:last-child { border-bottom: 0; }
  .actions { gap: 6px; }
  .actions .btn { flex: 1; }
  .modal-backdrop { align-items: stretch; padding: 0; }
  .modal { width: 100%; height: 100dvh; max-height: none; border-radius: 0; padding: 16px; }
  .modal-head { position: sticky; top: -16px; background: white; z-index: 2; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .attachment-row, .signature-row { align-items: flex-start; flex-direction: column; }
  .signature-row img { width: 100%; max-height: 100px; }
  .photo-preview img { width: 76px; height: 76px; }
  .mobile-bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: rgba(255,255,255,.98); border-top: 1px solid var(--line); box-shadow: 0 -10px 30px rgba(15,23,42,.08); padding: 6px 4px env(safe-area-inset-bottom); }
  .mobile-bottom-nav button { background: transparent; color: #64748b; display: grid; gap: 2px; place-items: center; padding: 6px 2px; border-radius: 12px; font-size: 11px; font-weight: 800; }
  .mobile-bottom-nav button strong { font-size: 16px; line-height: 1; }
  .mobile-bottom-nav button.active { background: #ccfbf1; color: #0f766e; }
}

/* v1.5 - ISABEL IA flutuante e experiência APK/PWA */
.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 75;
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  color: #fff;
  box-shadow: 0 18px 40px rgba(15, 118, 110, .32);
  border: 3px solid rgba(255,255,255,.92);
  font-weight: 950;
  letter-spacing: -.04em;
  display: grid;
  place-items: center;
}
.ai-fab span { font-size: 19px; }
.ai-fab:hover { transform: translateY(-2px); box-shadow: 0 22px 48px rgba(37, 99, 235, .34); }
.ai-panel { display: grid; gap: 12px; }
.ai-quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-messages {
  min-height: 330px;
  max-height: min(54vh, 560px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #f8fafc;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
}
.ai-empty { padding: 18px; border-radius: 16px; background: white; color: var(--muted); border: 1px dashed #cbd5e1; }
.ai-empty strong { color: var(--text); }
.ai-msg { padding: 12px 14px; border-radius: 16px; border: 1px solid var(--line); background: white; line-height: 1.45; }
.ai-msg.user { margin-left: 18%; background: #ecfeff; border-color: #a5f3fc; }
.ai-msg.assistant { margin-right: 10%; background: #ffffff; }
.ai-msg strong { display: block; margin-bottom: 5px; }
.ai-msg details { margin-top: 10px; }
.ai-msg summary { cursor: pointer; color: #0f766e; font-weight: 800; }
.ai-source { border-left: 3px solid #14b8a6; margin: 8px 0; padding: 8px 10px; background: #f0fdfa; border-radius: 10px; }
.ai-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.ai-form textarea { min-height: 74px; }
@media (max-width: 700px) {
  .ai-fab { width: 58px; height: 58px; right: 16px; bottom: 88px; }
  .ai-messages { min-height: 48vh; max-height: 58vh; }
  .ai-form { grid-template-columns: 1fr; }
  .ai-msg.user, .ai-msg.assistant { margin-left: 0; margin-right: 0; }
  .ai-quick-actions { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .ai-quick-actions .btn { white-space: nowrap; }
}
