/* ─── Reset & Variables ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 240px;
  --sidebar-collapsed: 64px;
  --topbar-h: 64px;

  /* Light */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --border: #e4e4e7;
  --text: #18181b;
  --text-2: #71717a;
  --text-3: #a1a1aa;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-hover: #1d4ed8;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --success: #22c55e;
  --success-light: #f0fdf4;
  --warning: #f59e0b;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #ffffff;
  --sidebar-active-bg: rgba(255,255,255,0.08);
  --sidebar-hover: rgba(255,255,255,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --transition: 220ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg: #0d0d10;
  --surface: #18181b;
  --surface-2: #222228;
  --border: #2d2d35;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #52525b;
  --accent: #3b82f6;
  --accent-light: #1e3a5f;
  --accent-hover: #60a5fa;
  --danger: #f87171;
  --danger-light: #2d1515;
  --success: #4ade80;
  --success-light: #162415;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.4);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition);
  z-index: 100;
  position: relative;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
  min-width: var(--sidebar-collapsed);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 14px 18px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  min-height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
}

.logo-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
}

.logo-text {
  color: #e2e8f0;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: .5px;
  transition: opacity var(--transition);
}
.logo-text strong { font-weight: 700; color: white; }

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .badge-soon,
.sidebar.collapsed .user-meta { opacity: 0; pointer-events: none; }

.sidebar.collapsed .nav-item span:not(.badge-soon) { opacity: 0; }
.sidebar.collapsed .sidebar-toggle i { transform: rotate(180deg); }

.sidebar-toggle {
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--sidebar-text);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.12); color: white; }
.sidebar-toggle i { transition: transform var(--transition); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.nav-section { display: flex; flex-direction: column; gap: 2px; }

.nav-label {
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 8px;
  white-space: nowrap;
  transition: opacity var(--transition);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
  position: relative;
}
.nav-item i { width: 18px; text-align: center; flex-shrink: 0; font-size: 15px; }
.nav-item span { transition: opacity var(--transition); }
.nav-item:hover:not(.disabled) { background: var(--sidebar-hover); color: white; }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 500; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-item.disabled { opacity: .4; cursor: not-allowed; }

.badge-soon {
  margin-left: auto;
  background: rgba(59,130,246,.2);
  color: #93c5fd;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 20px;
  white-space: nowrap;
  transition: opacity var(--transition);
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.user-info { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.user-avatar {
  width: 32px; height: 32px; min-width: 32px;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--sidebar-text);
  font-size: 13px;
}
.user-meta { overflow: hidden; transition: opacity var(--transition); }
.user-name { display: block; color: #e2e8f0; font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.user-role { display: block; color: #475569; font-size: 11px; }

/* ─── Main Wrapper ───────────────────────────────────────── */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all var(--transition);
}

/* ─── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  box-shadow: var(--shadow);
  z-index: 50;
  position: relative;
}

.search-container {
  flex: 1;
  max-width: 680px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-3);
  font-size: 14px;
  pointer-events: none;
}

.global-search {
  width: 100%;
  height: 40px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0 90px 0 40px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  outline: none;
}
.global-search::placeholder { color: var(--text-3); }
.global-search:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-kbd {
  position: absolute;
  right: 12px;
  background: var(--border);
  color: var(--text-3);
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: none;
  z-index: 999;
}
.search-results.open { display: block; }
.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface-2); }
.sri-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.sri-pf { background: var(--accent-light); color: var(--accent); }
.sri-pj { background: #fef3c7; color: #d97706; }
[data-theme="dark"] .sri-pj { background: #292314; color: #fbbf24; }
.sri-info { overflow: hidden; }
.sri-nome { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sri-detalhe { font-size: 12px; color: var(--text-2); }
.search-no-results { padding: 20px; text-align: center; color: var(--text-3); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.btn-icon {
  width: 36px; height: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ─── Content ────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}
.content::-webkit-scrollbar { width: 5px; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }

/* ─── Page Header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-title { font-size: 20px; font-weight: 600; }
.page-subtitle { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ─── Stats Cards ────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.stat-icon.blue { background: var(--accent-light); color: var(--accent); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: #fff7ed; color: #f97316; }
.stat-icon.purple { background: #f5f3ff; color: #7c3aed; }
[data-theme="dark"] .stat-icon.orange { background: #2a1a08; color: #fb923c; }
[data-theme="dark"] .stat-icon.purple { background: #1e1630; color: #a78bfa; }
.stat-num { font-size: 22px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 3px; }

/* ─── Card / Table ───────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--surface-2);
  padding: 11px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody td { padding: 13px 16px; font-size: 13.5px; vertical-align: middle; }

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-pf { background: var(--accent-light); color: var(--accent); }
.badge-pj { background: #fef3c7; color: #b45309; }
[data-theme="dark"] .badge-pj { background: #292314; color: #fbbf24; }
.badge-ativo { background: var(--success-light); color: #15803d; }
[data-theme="dark"] .badge-ativo { color: #4ade80; }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(37,99,235,.35); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger-light); color: var(--danger); border: 1px solid transparent; }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }

/* ─── Form ───────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .4px;
}
input, select, textarea {
  height: 40px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  width: 100%;
}
textarea { height: 80px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-light);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }

.form-section {
  margin-bottom: 8px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.form-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Tipo pessoa toggle */
.tipo-toggle { display: flex; gap: 8px; }
.tipo-btn {
  flex: 1;
  height: 40px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tipo-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.tipo-btn:hover:not(.active) { background: var(--surface); border-color: var(--text-3); }

/* ─── Alert ──────────────────────────────────────────────── */
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 20px;
  animation: fadeDown .25s ease;
}
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #86efac; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
[data-theme="dark"] .alert-success { color: #4ade80; border-color: #166534; }

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 6px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.page-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
  transition: all var(--transition);
}
.page-btn:hover { background: var(--surface-2); color: var(--text); }
.page-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ─── Cliente Detail ─────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding: 20px;
}
.detail-field label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-3); display: block; margin-bottom: 3px; }
.detail-field span { font-size: 14px; color: var(--text); }
.detail-field span.empty { color: var(--text-3); font-style: italic; font-size: 13px; }

/* ─── Empty State ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.empty-state i { font-size: 40px; margin-bottom: 14px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ─── Loading ────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fadeDown { from { opacity:0; transform:translateY(-8px);} to {opacity:1; transform:translateY(0);} }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .content { padding: 18px; }
}
