:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --border: #e2e8f0;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.req { color: var(--danger); }
.error-text { color: var(--danger); font-size: 0.9rem; margin-top: 0.6rem; }

/* ===== LOGIN ===== */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-sub { color: var(--muted); margin-bottom: 1.5rem; }

/* ===== TOP BAR ===== */
.topbar {
  background: var(--bg-2);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.05rem; }
.topbar-logo {
  height: 34px;
  width: auto;
  max-width: 150px;
  object-fit: contain;
  display: block;
}
.login-logo {
  height: 64px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  display: block;
  margin: 0 auto 0.5rem;
}
.badge {
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 0.5rem;
}
.topbar-right { display: flex; gap: 0.5rem; }

/* ===== TABS ===== */
.tabs {
  display: flex;
  background: var(--bg-2);
  position: sticky;
  top: 52px;
  z-index: 9;
}
.tab {
  flex: 1;
  padding: 0.8rem 0;
  background: transparent;
  color: #94a3b8;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active {
  color: #fff;
  border-bottom-color: var(--primary);
}

/* ===== CONTENT ===== */
.content {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 1rem calc(4rem + env(safe-area-inset-bottom));
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
  flex-wrap: wrap;
}
.toolbar input[type="search"],
.toolbar select {
  flex: 1;
  min-width: 200px;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
}

/* ===== CARDS / LISTAS ===== */
.card-list { display: flex; flex-direction: column; gap: 0.6rem; }
.device-item, .sale-item {
  background: var(--card);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.device-item .main, .sale-item .main { flex: 1; min-width: 160px; }
.device-item .title, .sale-item .title { font-weight: 700; font-size: 1rem; }
.device-item .sub, .sale-item .sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}
.device-item .price, .sale-item .price { font-weight: 700; }

/* Bolinha da cor do aparelho */
.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.device-card-inner .color-dot { width: 28px; height: 28px; }
.device-card-inner {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.device-card-inner .main { flex: 1; min-width: 0; }
.actions { display: flex; gap: 0.4rem; }
.actions button {
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}
.actions button.danger { color: var(--danger); border-color: #fecaca; }

.pill {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.pill.quitado { background: #dcfce7; color: #166534; }
.pill.pendente { background: #fef9c3; color: #854d0e; }
.pill.vencido { background: #fee2e2; color: #991b1b; }
.pill.pago { background: #dcfce7; color: #166534; }

.countdown { color: var(--warning); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 2rem; }

/* ===== FORMULÁRIOS ===== */
.form-card {
  background: var(--card);
  border-radius: 16px;
  padding: 1.25rem;
  margin-top: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.form-card h2 { font-size: 1.1rem; margin-bottom: 1rem; }
label { display: block; margin-bottom: 0.85rem; font-weight: 600; font-size: 0.85rem; color: #334155; }
input, select, textarea {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.85rem; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-2); color: #fff; }
.btn-secondary:hover { background: #273449; }
.btn-ghost { background: transparent; color: inherit; border: 1px solid rgba(255, 255, 255, 0.3); }
.btn-block { width: 100%; }
.btn-photo { padding: 1.1rem; font-size: 1.05rem; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.row { display: flex; gap: 0.5rem; }
.row input { flex: 1; min-width: 0; }
.row .btn { white-space: nowrap; }

.alert-warn {
  background: #fef9c3;
  border: 1px solid #fde047;
  color: #854d0e;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

/* ===== VENDA ===== */
.device-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--card);
  border-radius: 12px;
  padding: 1rem;
  margin-top: 1rem;
  border-left: 5px solid var(--success);
}
.device-card .title { font-weight: 700; font-size: 1.05rem; }
.device-card .sub { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }
.device-card .price-row { margin-top: 0.6rem; font-size: 0.95rem; }
.device-card .price-row strong { font-size: 1.1rem; }

.lucro-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin: 0.85rem 0;
}
.lucro-box strong { color: var(--success); font-size: 1.15rem; }

/* ===== TOTAIS ===== */
.totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-top: 1rem;
}
.total-card {
  background: var(--card);
  border-radius: 12px;
  padding: 0.9rem 0.75rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.total-card span { display: block; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
.total-card strong { font-size: 1.05rem; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 1.5rem;
}
.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* ===== USUÁRIOS ===== */
.user-list { list-style: none; margin-top: 1rem; }
.user-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  max-width: 90%;
  text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ===== DICA DE INSTALAÇÃO ===== */
.install-hint {
  position: fixed;
  bottom: calc(0.75rem + env(safe-area-inset-bottom));
  left: 0.75rem;
  right: 0.75rem;
  margin: 0 auto;
  max-width: 520px;
  background: #fff;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 90;
  border: 1px solid var(--border);
}
.install-hint strong { display: block; margin-bottom: 0.2rem; }
.install-hint p { color: var(--muted); font-size: 0.82rem; }
.install-hint .btn {
  flex-shrink: 0;
  color: var(--primary);
  border-color: #bfdbfe;
  font-size: 0.9rem;
}

@media (min-width: 768px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 16px; }
}
