/* ============================================================
   CRM M.A.S - Visual estilo Pipedrive com cores da marca
   Sidebar toggle MANUAL (default recolhida, NÃO mexe no resize)
   ============================================================ */

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

:root {
  --brand-blue: #1B3A6B;
  --brand-blue-dark: #0F2547;
  --brand-blue-darker: #0A1B33;
  --brand-blue-light: #2C5490;
  --brand-orange: #E87722;
  --brand-orange-dark: #C85F12;
  --brand-orange-light: #FF9645;

  --bg-main: #F7F8FA;
  --bg-card: #FFFFFF;
  --bg-hover: #F3F5F8;
  --border: #E5E8ED;
  --border-strong: #D1D7E0;

  --text: #1A1F2E;
  --text-medium: #4B5563;
  --text-light: #6B7280;
  --text-muted: #9CA3AF;

  --success: #10B981;
  --success-bg: #ECFDF5;
  --danger: #EF4444;
  --danger-bg: #FEF2F2;
  --warning: #F59E0B;
  --warning-bg: #FFFBEB;
  --info: #3B82F6;
  --info-bg: #EFF6FF;

  --shadow-sm: 0 1px 2px rgba(15, 37, 71, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 37, 71, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 37, 71, 0.12);

  --sidebar-width-collapsed: 68px;
  --sidebar-width-expanded: 248px;
  --sidebar-bg: #0F2547;
  --sidebar-bg-hover: #1B3A6B;
  --sidebar-text: #C5D0E0;
  --sidebar-text-active: #FFFFFF;

  --header-height: 64px;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-main);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
button { font-family: inherit; cursor: pointer; }

/* ============================================================
   APP WRAPPER
   ============================================================ */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  position: relative;
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width-collapsed);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Quando html tem .sidebar-expanded, empurra o conteúdo */
html.sidebar-expanded .app-main {
  margin-left: var(--sidebar-width-expanded);
}

.app-content {
  flex: 1;
  padding: 28px 36px;
  max-width: 100%;
  overflow-x: auto;
}

/* ============================================================
   SIDEBAR - Toggle manual (sem hover, sem listener de resize)
   ============================================================ */
.app-sidebar {
  width: var(--sidebar-width-collapsed);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  box-shadow: 4px 0 24px rgba(10, 27, 51, 0.08);
}

html.sidebar-expanded .app-sidebar {
  width: var(--sidebar-width-expanded);
  box-shadow: 8px 0 40px rgba(10, 27, 51, 0.18);
}

.sidebar-header {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.sidebar-logo-img {
  max-width: 72px;
  max-height: 72px;
  width: auto;
  height: auto;
  object-fit: contain;
  transition: max-width 0.25s ease, max-height 0.25s ease;
}

html.sidebar-expanded .sidebar-logo-img {
  max-width: 220px;
  max-height: 90px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; }

.nav-section { margin-bottom: 16px; }

.nav-section-title {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: rgba(197, 208, 224, 0.4);
  letter-spacing: 0.1em;
  padding: 0 14px 8px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s ease 0.05s;
  height: 24px;
}

html.sidebar-expanded .nav-section-title {
  opacity: 1;
}

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

.sidebar-nav ul li a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  color: var(--sidebar-text);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
  position: relative;
}

.sidebar-nav ul li a i {
  font-size: 20px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-nav ul li a span {
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 0.2s ease 0.05s, transform 0.2s ease 0.05s;
}

html.sidebar-expanded .sidebar-nav ul li a span {
  opacity: 1;
  transform: translateX(0);
}

.sidebar-nav ul li a:hover {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-text-active);
}

.sidebar-nav ul li a.active {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.sidebar-nav ul li a.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  background: var(--brand-orange);
  border-radius: 0 4px 4px 0;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  color: var(--sidebar-text);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.sidebar-logout i {
  font-size: 20px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.sidebar-logout span {
  opacity: 0;
  transform: translateX(-8px);
  transition: opacity 0.2s ease 0.05s, transform 0.2s ease 0.05s;
}

html.sidebar-expanded .sidebar-logout span {
  opacity: 1;
  transform: translateX(0);
}

.sidebar-logout:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #FCA5A5;
}

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  font-size: 20px;
  color: var(--brand-blue);
  padding: 0;
  border-radius: 10px;
  width: 40px;
  height: 40px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--brand-blue);
  color: white;
  border-color: var(--brand-blue);
}

.header-title { flex: 1; min-width: 0; }

.header-title h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-orange);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.15s ease;
  box-shadow: 0 2px 8px rgba(232, 119, 34, 0.25);
  text-decoration: none;
}

.btn-primary:hover {
  background: var(--brand-orange-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(232, 119, 34, 0.35);
}

.btn-primary i { font-size: 18px; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease;
}

.user-menu:hover { background: var(--bg-hover); }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-blue-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-name { font-weight: 600; font-size: 13px; color: var(--text); }
.user-role { font-size: 11px; color: var(--text-light); text-transform: capitalize; }

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
}

.app-footer strong { color: var(--brand-blue); font-weight: 600; }

/* ============================================================
   FLASH
   ============================================================ */
.flash {
  margin-bottom: 20px;
  padding: 14px 18px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid;
}

.flash i { font-size: 20px; }

.flash-success {
  background: var(--success-bg);
  color: #065F46;
  border-left-color: var(--success);
}

.flash-error {
  background: var(--danger-bg);
  color: #991B1B;
  border-left-color: var(--danger);
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header { margin-bottom: 28px; }

.page-header-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.025em;
  margin-bottom: 4px;
}

.page-header-subtitle { font-size: 14px; color: var(--text-light); }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  transition: all 0.2s ease;
  position: relative;
}

.stat-card:hover {
  border-color: var(--brand-blue-light);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.stat-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.stat-card-label {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-card-icon.blue { background: rgba(27, 58, 107, 0.1); color: var(--brand-blue); }
.stat-card-icon.orange { background: rgba(232, 119, 34, 0.1); color: var(--brand-orange); }
.stat-card-icon.green { background: var(--success-bg); color: var(--success); }
.stat-card-icon.purple { background: rgba(124, 58, 237, 0.1); color: #7c3aed; }
.stat-card-icon.amber { background: var(--warning-bg); color: var(--warning); }

.stat-card-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-card-footer {
  font-size: 12px;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================================
   WELCOME + EMPTY STATE
   ============================================================ */
.welcome-banner {
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-blue-light) 100%);
  border-radius: 14px;
  padding: 24px 28px;
  color: white;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}

.welcome-banner::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(232, 119, 34, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.welcome-banner h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: white;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 1;
}

.welcome-banner p {
  opacity: 0.9;
  font-size: 14px;
  position: relative;
  z-index: 1;
}

.empty-state {
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  padding: 56px 28px;
  text-align: center;
  color: var(--text-light);
}

.empty-state i {
  font-size: 48px;
  color: var(--border-strong);
  margin-bottom: 16px;
  display: block;
}

.empty-state h3 {
  color: var(--text);
  margin-bottom: 6px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.empty-state p { font-size: 14px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-title {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--text);
  letter-spacing: -0.025em;
}

.login-subtitle {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 28px;
}

/* ============================================================
   FORMS - Padrão horizontal com grid de 12 colunas
   ============================================================ */

/* Espaçamento entre form groups */
.form-group { margin-bottom: 14px; }
.form-card .form-group { margin-bottom: 14px; }

/* Grid horizontal pra forms */
.form-row {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  margin-bottom: 0;
}

.form-col-12 { grid-column: span 12; }
.form-col-6  { grid-column: span 6; }
.form-col-4  { grid-column: span 4; }
.form-col-3  { grid-column: span 3; }

/* Labels */
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
  letter-spacing: 0;
}

/* Inputs */
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 13.5px;
  font-family: inherit;
  background: white;
  color: var(--text);
  transition: all 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(27, 58, 107, 0.1);
}

.form-control::placeholder { color: var(--text-muted); }

textarea.form-control {
  resize: vertical;
  min-height: 70px;
  font-family: inherit;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 38px;
}

/* Marcador obrigatório */
.required {
  color: var(--danger);
  font-weight: 700;
  margin-left: 2px;
}

/* Botão de login (legado) */
.btn-login {
  width: 100%;
  padding: 13px;
  background: var(--brand-orange);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-top: 8px;
  font-family: inherit;
  box-shadow: 0 4px 12px rgba(232, 119, 34, 0.3);
  letter-spacing: -0.01em;
}

.btn-login:hover {
  background: var(--brand-orange-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(232, 119, 34, 0.4);
}

/* ============================================================
   RESPONSIVO
   ============================================================ */
@media (max-width: 960px) {
  .app-content { padding: 20px 18px; }
  .app-header { padding: 0 18px; }
  .app-footer {
    padding: 14px 18px;
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }
  .user-info { display: none; }
}

@media (max-width: 760px) {
  .form-row {
    grid-template-columns: 1fr;
  }
  .form-col-12, .form-col-6, .form-col-4, .form-col-3 {
    grid-column: span 1;
  }
}
