/* ==========================================================================
   CRM MODERN DASHBOARD STYLES & THEMES
   ========================================================================== */

/* --- 1. CSS VARIABLES & THEMES --- */
:root,
[data-theme="light"] {
  --bg-app: #f4f6f9;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-hover-bg: #334155;
  --sidebar-active-bg: #2563eb;
  --sidebar-active-text: #ffffff;
  --sidebar-border: #334155;
  --topbar-bg: #ffffff;
  --topbar-border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --info: #0ea5e9;
  --warning: #f59e0b;
  --danger: #ef4444;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --table-header-bg: #f1f5f9;
  --table-hover: #f8fafc;
  --input-border: #cbd5e1;
  --input-bg: #ffffff;
}

[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-alt: #182234;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --sidebar-bg: #090e17;
  --sidebar-text: #94a3b8;
  --sidebar-hover-bg: #1e293b;
  --sidebar-active-bg: #3b82f6;
  --sidebar-active-text: #ffffff;
  --sidebar-border: #1e293b;
  --topbar-bg: #1e293b;
  --topbar-border: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e3a5f;
  --success: #10b981;
  --info: #38bdf8;
  --warning: #fbbf24;
  --danger: #f87171;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --table-header-bg: #273549;
  --table-hover: #243144;
  --input-border: #475569;
  --input-bg: #182234;
}

[data-theme="light-blue"] {
  --bg-app: #f0f7ff;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f1f7fe;
  --text-main: #1e3a5f;
  --text-muted: #64748b;
  --border-color: #dbeafe;
  --sidebar-bg: #0f2744;
  --sidebar-text: #93c5fd;
  --sidebar-hover-bg: #1e3e66;
  --sidebar-active-bg: #0284c7;
  --sidebar-active-text: #ffffff;
  --sidebar-border: #1e3e66;
  --topbar-bg: #ffffff;
  --topbar-border: #bfdbfe;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-light: #e0f2fe;
  --success: #0d9488;
  --info: #0284c7;
  --warning: #f59e0b;
  --danger: #ef4444;
  --card-shadow: 0 4px 12px rgba(2, 132, 199, 0.08);
  --table-header-bg: #e0f2fe;
  --table-hover: #f0f9ff;
  --input-border: #bae6fd;
  --input-bg: #ffffff;
}

[data-theme="light-green"] {
  --bg-app: #f0fdf4;
  --bg-surface: #ffffff;
  --bg-surface-alt: #f3faf5;
  --text-main: #14532d;
  --text-muted: #4b6b55;
  --border-color: #dcfce7;
  --sidebar-bg: #064e3b;
  --sidebar-text: #a7f3d0;
  --sidebar-hover-bg: #047857;
  --sidebar-active-bg: #10b981;
  --sidebar-active-text: #ffffff;
  --sidebar-border: #047857;
  --topbar-bg: #ffffff;
  --topbar-border: #bbf7d0;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --success: #10b981;
  --info: #0891b2;
  --warning: #d97706;
  --danger: #dc2626;
  --card-shadow: 0 4px 12px rgba(5, 150, 105, 0.08);
  --table-header-bg: #d1fae5;
  --table-hover: #ecfdf5;
  --input-border: #a7f3d0;
  --input-bg: #ffffff;
}

/* --- 2. BASE & TYPOGRAPHY (AJUSTE FINO -10%) --- */
* {
  box-sizing: border-box;
}

html {
  font-size: 14.5px; /* Ajuste -10% para balance óptimo */
}

body {
  font-family: 'Inter', 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  font-size: 1rem !important; /* 14.5px */
  line-height: 1.5 !important;
  background-color: var(--bg-app) !important;
  color: var(--text-main) !important;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.8rem !important; }
h2 { font-size: 1.5rem !important; }
h3 { font-size: 1.3rem !important; }
h4 { font-size: 1.15rem !important; }
h5 { font-size: 1rem !important; }
h6 { font-size: 0.9rem !important; }

h1, h2, h3, h4, h5, h6 {
  font-family: 'Poppins', 'Inter', sans-serif !important;
  font-weight: 600 !important;
  color: var(--text-main) !important;
}

hr {
  border-color: var(--border-color) !important;
  opacity: 0.7;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover, a:focus {
  color: var(--primary-hover);
  text-decoration: none;
}

/* --- 3. DASHBOARD LAYOUT (SIDEBAR & TOPBAR) --- */
.crm-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
}

/* Sidebar */
.crm-sidebar {
  width: 250px;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1040;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  overflow-x: hidden;
}

.crm-sidebar-brand {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  color: #ffffff;
  border-bottom: 1px solid var(--sidebar-border);
  letter-spacing: 0.5px;
  text-decoration: none !important;
}

.crm-sidebar-brand i {
  font-size: 1.45rem;
  color: var(--primary);
}

.crm-sidebar-menu {
  list-style: none;
  padding: 12px 10px;
  margin: 0;
  flex-grow: 1;
}

.crm-menu-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #94a3b8;
  padding: 14px 10px 5px;
}

.crm-menu-item {
  margin-bottom: 3px;
}

.crm-menu-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  color: var(--sidebar-text) !important;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  text-decoration: none !important;
}

.crm-menu-link i.menu-icon {
  width: 20px;
  text-align: center;
  font-size: 1.08rem;
}

.crm-menu-link:hover {
  background-color: var(--sidebar-hover-bg);
  color: #ffffff !important;
  transform: translateX(3px);
}

.crm-menu-link.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active-text) !important;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.crm-sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: rgba(0, 0, 0, 0.15);
}

.crm-user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.crm-user-info {
  line-height: 1.2;
  overflow: hidden;
}

.crm-user-name {
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.crm-user-role {
  color: #94a3b8;
  font-size: 0.78rem;
}

/* Main Content Area */
.crm-main {
  flex-grow: 1;
  margin-left: 250px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background-color: var(--bg-app);
  width: calc(100% - 250px);
}

/* Topbar Header */
.crm-topbar {
  height: 64px;
  background-color: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.crm-topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.crm-toggle-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.crm-toggle-btn:hover {
  background-color: var(--bg-surface-alt);
  color: var(--primary);
}

.crm-topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Theme Selector */
.crm-theme-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 20px;
}

.crm-theme-selector select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
}

.crm-topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s;
  text-decoration: none !important;
}

.crm-btn-logout {
  background-color: #fee2e2;
  color: #dc2626 !important;
  border: 1px solid #fecaca;
}

.crm-btn-logout:hover {
  background-color: #dc2626;
  color: #ffffff !important;
}

[data-theme="dark"] .crm-btn-logout {
  background-color: rgba(220, 38, 38, 0.2);
  color: #f87171 !important;
  border-color: rgba(220, 38, 38, 0.4);
}

/* Content Container */
.crm-content {
  padding: 20px;
  flex-grow: 1;
}

.crm-content .container {
  width: 100% !important;
  max-width: 100% !important;
  padding-left: 0;
  padding-right: 0;
}

/* --- 4. TITLE & ACTION BAR (titulo function) --- */
.crm-page-header {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.crm-page-title-box {
  display: flex;
  align-items: center;
  gap: 12px;
}

.crm-page-title-box h3 {
  margin: 0 !important;
  font-size: 1.3rem !important;
  font-weight: 700;
  color: var(--text-main) !important;
}

.crm-quick-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.crm-quick-actions .btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.88rem !important;
  padding: 7px 14px !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-surface-alt);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  text-decoration: none !important;
}

.crm-quick-actions .btn:hover {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* --- 5. MODERN CARDS & FORM CONTAINER ESTILIZADO --- */
.crm-card {
  background-color: var(--bg-surface) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 12px !important;
  box-shadow: var(--card-shadow) !important;
  padding: 20px;
  margin-bottom: 20px;
}

.crm-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 0;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel, .card, .box, .box-body {
  background-color: var(--bg-surface) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 12px !important;
  box-shadow: var(--card-shadow) !important;
  color: var(--text-main) !important;
  padding: 16px;
  margin-bottom: 20px;
}

.panel-default {
  border: 1px solid var(--border-color) !important;
}

.panel-body {
  background: transparent !important;
  padding: 8px 0 !important;
}

/* Form Controls & Labels */
.form-group {
  margin-bottom: 15px;
}

.form-control, input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
  background-color: var(--input-bg) !important;
  border: 1px solid var(--input-border) !important;
  color: var(--text-main) !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  font-size: 0.9rem !important;
  height: auto !important;
  min-height: 38px;
  width: 100%;
  box-shadow: none !important;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}

label {
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.88rem !important;
  margin-bottom: 5px;
  display: inline-block;
}

/* Buttons */
.btn {
  border-radius: 8px !important;
  font-weight: 600 !important;
  font-size: 0.88rem !important;
  padding: 8px 15px !important;
  transition: all 0.2s ease !important;
  border: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background-color: var(--primary) !important;
  color: #ffffff !important;
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--primary-hover) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.btn-success {
  background-color: var(--success) !important;
  color: #ffffff !important;
}

.btn-info {
  background-color: var(--info) !important;
  color: #ffffff !important;
}

.btn-warning {
  background-color: var(--warning) !important;
  color: #ffffff !important;
}

.btn-danger {
  background-color: var(--danger) !important;
  color: #ffffff !important;
}

.btn-default {
  background-color: var(--bg-surface-alt) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-main) !important;
}

.btn-default:hover {
  background-color: var(--border-color) !important;
}

.btn-sm {
  padding: 5px 12px !important;
  font-size: 0.8rem !important;
  border-radius: 6px !important;
}

/* Badges */
.badge, .label {
  background-color: var(--primary) !important;
  color: #ffffff !important;
  padding: 5px 10px !important;
  border-radius: 20px !important;
  font-weight: 600 !important;
  font-size: 0.88rem !important;
  display: inline-block;
}

/* Tables */
.table-responsive {
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  margin-bottom: 20px;
  overflow: hidden;
}

.table {
  background-color: var(--bg-surface) !important;
  color: var(--text-main) !important;
  margin-bottom: 0 !important;
  font-size: 0.88rem !important;
}

.table > thead > tr > th,
.table > thead > tr.btn-primary > th,
.table > thead > tr.btn-info > th {
  background-color: var(--table-header-bg) !important;
  color: var(--text-main) !important;
  font-weight: 700 !important;
  text-transform: uppercase;
  font-size: 0.78rem !important;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border-color) !important;
  padding: 11px 14px !important;
}

.table > tbody > tr > td {
  border-top: 1px solid var(--border-color) !important;
  padding: 10px 14px !important;
  vertical-align: middle !important;
  font-size: 0.88rem !important;
}

.table-hover > tbody > tr:hover {
  background-color: var(--table-hover) !important;
}

.table tr.success td {
  background-color: rgba(16, 185, 129, 0.12) !important;
  font-weight: 600;
}

/* Modals */
.modal-content {
  background-color: var(--bg-surface) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 14px !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2) !important;
}

.modal-header, .modal-footer {
  border-color: var(--border-color) !important;
}

/* --- 6. MODERN LOGIN PAGE (index.php) --- */
.crm-login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, var(--primary-light), var(--bg-app));
  padding: 20px;
}

.crm-login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.crm-login-logo {
  width: 62px;
  height: 62px;
  background: var(--primary);
  color: #fff;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.crm-login-title {
  font-size: 1.45rem !important;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-main);
}

.crm-login-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 22px;
}

.crm-input-group {
  position: relative;
  margin-bottom: 18px;
  text-align: left;
}

.crm-input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 5px;
}

.crm-input-icon-wrapper {
  position: relative;
}

.crm-input-icon-wrapper i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1rem;
}

.crm-input-icon-wrapper input {
  padding-left: 38px !important;
  width: 100% !important;
  max-width: 100% !important;
}

.crm-login-btn {
  width: 100%;
  padding: 11px !important;
  font-size: 0.95rem !important;
  font-weight: 600 !important;
  border-radius: 8px !important;
  margin-top: 10px;
}

/* --- 7. COLLAPSED & RESPONSIVE BEHAVIOR --- */
.crm-layout.collapsed .crm-sidebar {
  width: 70px;
}

.crm-layout.collapsed .crm-sidebar .crm-sidebar-brand span,
.crm-layout.collapsed .crm-sidebar .crm-menu-link span,
.crm-layout.collapsed .crm-sidebar .crm-menu-header,
.crm-layout.collapsed .crm-sidebar .crm-user-info,
.crm-layout.collapsed .crm-sidebar .crm-submenu {
  display: none !important;
}

.crm-layout.collapsed .crm-sidebar .crm-menu-link {
  justify-content: center;
  padding: 12px 0;
}

.crm-layout.collapsed .crm-sidebar .crm-menu-link i.menu-icon {
  margin: 0;
  font-size: 1.25rem;
}

.crm-layout.collapsed .crm-main {
  margin-left: 70px;
  width: calc(100% - 70px);
}

.crm-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1030;
}

@media (max-width: 991.98px) {
  .crm-sidebar {
    margin-left: -250px;
  }
  .crm-main {
    margin-left: 0 !important;
    width: 100% !important;
  }
  .crm-layout.sidebar-mobile-open .crm-sidebar {
    margin-left: 0;
  }
  .crm-layout.sidebar-mobile-open .crm-backdrop {
    display: block;
  }
}
