:root {
  --bg: #06090f;
  --bg2: #0d1117;
  --bg3: #161b22;
  --surface: #1c2333;
  --border: #2d3748;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #ff5722;
  --accent-hover: #e64a19;
  --accent-dim: rgba(255,87,34,0.10);
  --accent-border: rgba(255,87,34,0.25);
  --success: #2ea043;
  --error: #f85149;
  --warning: #d29922;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-width: 320px;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--accent);
  text-decoration: none;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

/* ── HEADER PADRÃO ── */
.header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-back {
  width: 36px; height: 36px;
  border: none; background: none;
  color: var(--accent); font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.header-title {
  font-size: 16px; font-weight: 800;
  text-transform: uppercase; color: var(--accent);
  letter-spacing: 0.3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
.header-version {
  font-size: 10px; color: var(--text2); font-weight: 500;
  line-height: 1;
}
.header-user {
  font-size: 9px; color: var(--text2);
  line-height: 1;
}
.header-middle {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.header-subtitle {
  font-size: 11px; color: var(--text2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── LAYOUT ── */

.screen {
  display: none;
  width: 100%;
  min-height: 100dvh;
  padding: 20px 16px;
  padding-bottom: 80px;
}

.screen.active {
  display: block;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* ── LOGIN ── */

.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 16px;
  text-align: center;
}

.login-screen .logo {
  width: 96px;
  height: 96px;
  margin-bottom: 24px;
  border-radius: 24px;
}

.login-screen h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-screen p {
  color: var(--text2);
  font-size: .9rem;
  margin-bottom: 32px;
}

.login-screen .input-group {
  width: 100%;
  max-width: 320px;
}

.login-screen label {
  display: block;
  text-align: left;
  font-size: .85rem;
  color: var(--text2);
  margin-bottom: 8px;
}

/* ── FORM ELEMENTS ── */

.input-field {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}

.input-field:focus {
  border-color: var(--accent);
}

.input-field::placeholder {
  color: var(--text2);
}

textarea.input-field {
  height: auto;
  padding: 12px 16px;
  resize: vertical;
  min-height: 80px;
}

select.input-field {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%238b949e' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

/* ── BUTTONS ── */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 60px;
  padding: 0 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active {
  transform: scale(.97);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg3);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--error);
  color: #fff;
}

.btn-sm {
  height: 44px;
  font-size: .875rem;
  width: auto;
  padding: 0 16px;
}

.btn-icon {
  width: 60px;
  height: 60px;
  padding: 0;
  font-size: 1.5rem;
}

/* ── CARDS ── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-contract {
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}

.card-contract:hover {
  background: var(--bg3);
  border-color: var(--accent);
}

.card-contract .icon {
  font-size: 2rem;
  width: 48px;
  text-align: center;
  flex-shrink: 0;
}

.card-contract .info {
  flex: 1;
  min-width: 0;
}

.card-contract .info h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.card-contract .info p {
  font-size: .8rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-contract .arrow {
  color: var(--text2);
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* ── BADGE ── */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
}

.badge-pendencia {
  position: absolute;
  top: -6px;
  right: -6px;
}

/* ── TOAST ── */

.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: .9rem;
  text-align: center;
  animation: toastIn .3s ease, toastOut .3s ease 2.2s forwards;
  pointer-events: auto;
  box-shadow: var(--shadow);
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
.toast.warning { border-color: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateY(-8px); }
}

/* ── HEADER / TOPBAR ── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: 16px;
}

.topbar h2 {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .btn-back {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.topbar .btn-back:hover {
  background: var(--surface);
}

/* ── FORM GROUP ── */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: .85rem;
  color: var(--text2);
  margin-bottom: 6px;
}

.form-group .required::after {
  content: ' *';
  color: var(--accent);
}

/* ── FOTO PREVIEW ── */

.foto-preview {
  width: 100%;
  height: 200px;
  border-radius: var(--radius);
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: .9rem;
  overflow: hidden;
  margin-bottom: 8px;
  border: 1px dashed var(--border);
}

.foto-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── PENDENCIAS ── */

.pendencia-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg3);
  border-radius: var(--radius);
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.pendencia-item .thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  flex-shrink: 0;
  overflow: hidden;
}

.pendencia-item .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pendencia-item .info {
  flex: 1;
  min-width: 0;
}

.pendencia-item .info .titulo {
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.pendencia-item .info .subtitulo {
  font-size: .75rem;
  color: var(--text2);
}

.pendencia-item .status {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 4px;
  align-self: flex-start;
}

.status-pronto { background: var(--success); color: #fff; }
.status-enviando { background: var(--warning); color: #000; }
.status-erro { background: var(--error); color: #fff; }
.status-enviado { background: var(--text2); color: #fff; }

/* ── FOOTER / VERSION ── */

.footer-version {
  text-align: center;
  padding: 24px 0 12px;
  font-size: .7rem;
  color: var(--text2);
}

/* ── BANNER PWA ── */

.banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: none;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  animation: slideUp .3s ease;
}

.banner.show {
  display: flex;
}

.banner p {
  flex: 1;
  font-size: .85rem;
  color: var(--text);
}

.banner .btn-sm {
  flex-shrink: 0;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── LOADING ── */

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  gap: 16px;
  color: var(--text2);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── EMPTY STATE ── */

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text2);
}

.empty-state .emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: .85rem;
}

/* ── UTILITIES ── */

.hidden { display: none !important; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-muted { color: var(--text2); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── SCROLLBAR ── */

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── CONFIRM MODAL ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn .2s ease;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 16px;
  padding-bottom: 40px;
  width: 100%;
  max-width: 480px;
  animation: slideUp .3s ease;
}

.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.modal p {
  color: var(--text2);
  font-size: .9rem;
  margin-bottom: 20px;
}

.modal .btn-group {
  display: flex;
  gap: 12px;
}

.modal .btn-group .btn {
  flex: 1;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── BAIRRO SUGGESTIONS ── */

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-top: none;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.suggestions .sug-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
}
.suggestions .sug-item:hover {
  background: var(--surface);
}
.suggestions .sug-item .sug-zona {
  float: right;
  color: var(--text2);
  font-size: 12px;
}

/* ── STATUS BAR (armazenamento) ── */

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  font-size: .75rem;
  color: var(--text2);
  margin-bottom: 12px;
}

.status-bar .fill {
  height: 4px;
  background: var(--success);
  border-radius: 2px;
  transition: width .3s;
}

.status-bar.warning .fill { background: var(--warning); }
.status-bar.danger .fill { background: var(--error); }

/* ── SELECAO DE SERVICO ── */

.servico-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.servico-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}

.servico-card:hover {
  background: var(--bg3);
  border-color: var(--accent);
}

.servico-card .emoji {
  font-size: 2rem;
  margin-bottom: 8px;
}

.servico-card .nome {
  font-size: .85rem;
  font-weight: 600;
}

/* ── RESOLUÇÃO DE TELA ── */

@media (min-width: 768px) {
  .container {
    max-width: 600px;
  }

  .servico-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 720px;
  }
}

/* ── GPS BAR (padrão laranja) ── */
.gps-bar {
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--text2);
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
  overflow: hidden;
}
.gps-bar::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent);
  opacity: 0.6;
}
.gps-row {
  display: flex; justify-content: space-between; align-items: center;
}
.gps-item {
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gps-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.gps-dot.inactive { background: var(--error); }
.gps-endereco { color: var(--text); }
.gps-coord { color: var(--accent); font-weight: 700; }
.gps-status { font-weight: 800; }
.gps-time { }

/* ── LOADING OVERLAY ── */

.loading-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.85);
  color: #fff;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  font-weight: 700;
  text-align: center;
  padding: 20px;
}
.loading-overlay.show {
  display: flex;
}
.loading-overlay .loading-spinner {
  font-size: 32px;
  margin-bottom: 12px;
  animation: spin 1s linear infinite;
}
.loading-overlay .loading-msg {
  font-size: 1rem;
  margin-bottom: 6px;
}
.loading-overlay .loading-sub {
  font-size: .8rem;
  color: #aaa;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
