:root {
  --azul: #0d2b6b;
  --azul-hover: #1a3d8f;
  --laranja: #f5a623;
  --laranja-dark: #e09518;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --bg: #f4f6fb;
  --bg-card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --green: #166534;
  --green-bg: #dcfce7;
  --orange-bg: #fff7ed;
  --blue-bg: #eff6ff;
  --red: #991b1b;
  --red-bg: #fef2f2;
  --yellow-bg: #fefce8;
  --yellow: #854d0e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.5;
}

/* ── LOGIN ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--azul);
}

.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.logo-icon {
  width: 48px;
  height: 48px;
  background: var(--azul);
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.login-brand { font-size: 15px; font-weight: 600; color: var(--azul); }
.login-sub { font-size: 12px; color: var(--text-secondary); }
.login-error { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.login-footer { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 20px; }

/* ── APP LAYOUT ── */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 220px;
  background: var(--azul);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--laranja);
  color: #412402;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-brand { color: #fff; font-size: 14px; font-weight: 600; }
.sidebar-sub { color: var(--laranja); font-size: 11px; }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: all .15s;
  cursor: pointer;
}

.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.12); color: #fff; border-left-color: var(--laranja); }

.nav-divider { border-top: 1px solid rgba(255,255,255,0.1); margin: 8px 0; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--laranja);
  color: #412402;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name { color: #fff; font-size: 12px; font-weight: 500; }
.user-role { color: rgba(255,255,255,0.5); font-size: 11px; }

.logout-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: color .15s;
}
.logout-btn:hover { color: rgba(255,255,255,0.8); }

/* ── MAIN ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.page-title { font-size: 17px; font-weight: 600; color: var(--azul); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.alert-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--green-bg);
  color: var(--green);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.content { flex: 1; overflow-y: auto; padding: 24px 28px; }

.screen { display: none; }
.screen.active { display: block; }

/* ── BUTTONS ── */
.btn-primary {
  background: var(--azul);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--azul-hover); }
.btn-primary.full { width: 100%; justify-content: center; padding: 12px; }

.btn-orange {
  background: var(--laranja);
  color: #412402;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .15s;
}
.btn-orange:hover { background: var(--laranja-dark); }

.btn-secondary {
  background: transparent;
  color: var(--azul);
  border: 1.5px solid var(--azul);
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all .15s;
}
.btn-secondary:hover { background: var(--blue-bg); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
}
.btn-ghost:hover { background: var(--bg); }

.btn-link {
  background: none;
  border: none;
  color: var(--laranja);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.back-btn { margin-bottom: 16px; }

/* ── CARDS ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title { font-size: 14px; font-weight: 600; color: var(--azul); }

/* ── STATS ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.stat-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text-primary); }
.stat-value.orange { color: #c2710c; }
.stat-value.green { color: var(--green); }
.stat-value.blue { color: var(--azul); }

/* ── FORMS ── */
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.col-2 { grid-column: span 2; }

label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

input, select, textarea {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
  background: #fff;
  font-family: inherit;
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(13,43,107,0.08);
}
textarea { resize: vertical; }

/* ── SERVIÇOS ── */
.services-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.service-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.service-row input { font-size: 13px; }
.svc-desc { flex: 1; }
.svc-qty { width: 70px; text-align: center; }
.svc-unit { width: 110px; }
.svc-total { width: 110px; background: var(--bg) !important; color: var(--text-secondary) !important; }
.svc-del {
  width: 32px;
  height: 32px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all .15s;
}
.svc-del:hover { border-color: var(--red); color: var(--red); background: var(--red-bg); }

.add-service-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 8px;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  margin-top: 4px;
}
.add-service-btn:hover { border-color: var(--azul); color: var(--azul); background: var(--blue-bg); }

.totals-panel {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px 18px;
  margin-top: 16px;
}

.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0;
}

.total-line.main {
  font-size: 15px;
  font-weight: 700;
  color: var(--azul);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 8px;
}

/* ── TOGGLE ── */
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle-label input[type=checkbox] { display: none; }
.toggle-track {
  width: 38px;
  height: 22px;
  background: var(--border-strong);
  border-radius: 20px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-thumb {
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-label input:checked + .toggle-track { background: var(--azul); }
.toggle-label input:checked + .toggle-track .toggle-thumb { left: 19px; }

/* ── FORM ACTIONS ── */
.form-actions { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

/* ── SEARCH / FILTERS ── */
.search-bar {
  position: relative;
  margin-bottom: 20px;
}
.search-bar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search-bar input { padding-left: 38px; }

.filters-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters-bar select { width: 180px; }

/* ── TABLE ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #fafbff; }

.action-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all .15s;
  font-size: 12px;
}
.action-icon:hover { background: var(--bg); color: var(--text-primary); }

/* ── BADGES ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-enviada { background: var(--blue-bg); color: #1e3a8a; }
.badge-aprovada { background: var(--green-bg); color: var(--green); }
.badge-contrato { background: var(--yellow-bg); color: var(--yellow); }
.badge-cancelada { background: var(--red-bg); color: var(--red); }

/* ── CLIENT CARDS ── */
.clientes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }

.client-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  cursor: pointer;
  transition: all .15s;
}
.client-card:hover { border-color: var(--azul); box-shadow: 0 2px 12px rgba(13,43,107,.08); }

.client-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.client-initials {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue-bg);
  color: #1e3a8a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.client-razao { font-size: 14px; font-weight: 600; }
.client-cnpj { font-size: 12px; color: var(--text-secondary); }
.client-stats { display: flex; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--border); }
.client-stat-item { text-align: center; }
.client-stat-val { font-size: 16px; font-weight: 700; color: var(--azul); }
.client-stat-lbl { font-size: 11px; color: var(--text-muted); }

/* ── CLIENT DETAIL ── */
.client-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.client-avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue-bg);
  color: #1e3a8a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}
.client-name { font-size: 20px; font-weight: 700; color: var(--azul); }
.client-meta { font-size: 13px; color: var(--text-secondary); }

/* ── MODALS ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 15px; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-muted); line-height: 1; }

.status-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: all .15s;
}
.status-option:hover { border-color: var(--azul); background: var(--blue-bg); }

/* ── DASHBOARD RECENT ── */
.recent-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.recent-row:last-child { border-bottom: none; }
.recent-num { font-size: 11px; color: var(--text-muted); width: 60px; }
.recent-info { flex: 1; }
.recent-name { font-size: 13px; font-weight: 500; }
.recent-sub { font-size: 12px; color: var(--text-secondary); }
.recent-value { font-weight: 700; color: var(--azul); font-size: 14px; }
.recent-sub-val { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state svg { margin-bottom: 12px; opacity: .3; }
.empty-state p { font-size: 14px; }

/* ── PREVIEW ── */
.preview-page {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 720px;
  overflow: hidden;
}

.preview-header {
  background: var(--azul);
  padding: 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-orange-bar { height: 5px; background: var(--laranja); }

.preview-body { padding: 28px 32px; }

.preview-section { margin-bottom: 24px; }

.preview-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--laranja);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 2px solid var(--laranja);
  padding-bottom: 6px;
  margin-bottom: 14px;
}

.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 12px; }
.preview-table th { background: var(--azul); color: #fff; padding: 9px 12px; text-align: left; font-size: 12px; }
.preview-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.preview-table tr.total-row td { background: var(--blue-bg); font-weight: 700; color: var(--azul); }
.preview-table tr.implant-row td { background: var(--bg); }
.preview-table tr.grand-row td { background: var(--orange-bg); font-weight: 700; color: #92400e; font-size: 14px; }

.preview-footer {
  background: var(--azul);
  padding: 14px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .form-group.col-2 { grid-column: span 1; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}

/* ── CNPJ LOOKUP ── */
#cnpj-status {
  transition: color .2s;
  font-size: 12px;
}

input:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(13,43,107,0.08);
}

/* ── TIPO DE COBRANÇA ── */
.svc-tipo {
  width: 120px;
  font-size: 12px;
  padding: 8px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text-primary);
  cursor: pointer;
}

.service-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
