:root {
  /* DARK MODE (Default) */
  --bg-body:    #0f1117;
  --bg-sidebar: #0f172a;
  --bg-card:    #1e293b;
  --bg-input:   #0f172a;
  --border:     #334155;
  --text:       #e2e8f0;
  --text-muted: #64748b;
  --text-hint:  #475569;
  --primary:    #2563eb;
  --green:      #34d399;
  --red:        #f87171;
  --yellow:     #fbbf24;
  --purple:     #a78bfa;
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  12px;
}

body.light-mode {
  /* LIGHT MODE */
  --bg-body:    #eef2f7;
  --bg-sidebar: #dbe4f0;
  --bg-card:    #ffffff;
  --bg-input:   #f1f5f9;
  --border:     #c8d4e3;
  --text:       #0f172a;
  --text-muted: #4a5a72;
  --text-hint:  #7a8fa8;
  --primary:    #2563eb;
  --green:      #059669;
  --red:        #dc2626;
  --yellow:     #d97706;
  --purple:     #7c3aed;
}

/* Light mode: overrides diretos de estrutura */
body.light-mode .sidebar {
  background: #d0dced;
  border-right: 1px solid #b8c9de;
}
body.light-mode .sidebar-logo {
  color: #1e40af;
}
body.light-mode .sidebar-link {
  color: #334c6e;
}
body.light-mode .sidebar-link:hover,
body.light-mode .sidebar-link.active {
  background: rgba(37,99,235,0.12);
  color: #1d4ed8;
}
body.light-mode .tenant-bar {
  background: #c6d5e8;
  border-bottom: 1px solid #aec0d4;
}
body.light-mode .sidebar-bottom {
  border-top-color: #b0c4d8;
}
body.light-mode .tenant-switcher select {
  background: #dce8f5;
  border-color: #aec0d4;
  color: #0f172a;
}
body.light-mode .btn-ghost {
  color: #334c6e;
}
body.light-mode .btn-ghost:hover {
  background: rgba(37,99,235,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-body);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card { background: var(--bg-card); width: 100%; max-width: 400px; padding: 40px; border-radius: var(--radius-lg); box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.auth-logo { font-size: 40px; text-align: center; margin-bottom: 10px; }
.auth-title { font-size: 24px; text-align: center; margin-bottom: 5px; font-weight: 600; }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: 14px; margin-bottom: 30px; }

.field { margin-bottom: 15px; }
.field label { display: block; margin-bottom: 5px; font-size: 14px; color: var(--text-muted); }
.field input, .field select { width: 100%; padding: 12px 15px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-input); color: var(--text); outline: none; transition: border-color 0.2s; }
.field input:focus, .field select:focus { border-color: var(--primary); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }

.btn-primary, .btn-secondary, .btn-ghost { display: inline-block; padding: 12px 20px; border-radius: var(--radius-sm); font-weight: 600; text-align: center; cursor: pointer; border: none; font-size: 14px; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: 0.9; text-decoration: none; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-full { width: 100%; }
.btn-link-center { display: block; text-align: center; margin-top: 15px; font-size: 14px; color: var(--text-muted); }
.btn-group { display: flex; gap: 10px; }

.alert { padding: 12px 15px; border-radius: var(--radius-sm); margin-bottom: 20px; font-size: 14px; }
.alert-error { background: rgba(248,113,113,0.1); border: 1px solid var(--red); color: var(--red); }
.alert-success { background: rgba(52,211,153,0.1); border: 1px solid var(--green); color: var(--green); }

.strength-bar-wrap { height: 4px; background: var(--bg-body); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.strength-bar { height: 100%; width: 0; transition: all 0.3s; }
.strength-label { font-size: 12px; margin-top: 4px; display: block; }
.field-error { color: var(--red); font-size: 12px; margin-top: 4px; }
.field-link-right { float: right; font-size: 12px; margin-top: -20px; position: relative; z-index: 10; }

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-content { position: relative; background: var(--bg-card); padding: 30px; border-radius: var(--radius-lg); width: 100%; max-width: 500px; box-shadow: 0 20px 40px rgba(0,0,0,0.5); z-index: 51; }
.modal-subtitle { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }

.empty-state { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 60px; margin-bottom: 20px; }
.empty-state h2 { margin-bottom: 10px; }
.empty-state p { color: var(--text-muted); margin-bottom: 30px; }
.empty-state .btn-group { justify-content: center; }

/* --- SIDEBAR RESPONSIVA & RETRÁTIL --- */

/* Variáveis de Largura */
:root {
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 70px;
}

.app-layout { display: flex; min-height: 100vh; position: relative; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  padding: 20px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.25s;
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 40px;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  margin-bottom: 5px;
  transition: all 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
}

.sidebar-link span {
  transition: opacity 0.3s;
}

.sidebar-link i {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

/* Estado Colapsado (Desktop) */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  padding: 20px 10px;
}

.sidebar.collapsed .sidebar-logo {
  justify-content: center;
}
.sidebar.collapsed .sidebar-logo span {
  display: none;
}

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

.sidebar.collapsed .sidebar-link span,
.sidebar.collapsed .sidebar-nav-title {
  display: none;
}

.sidebar-nav-title {
  color: var(--text-muted);
  font-size: 11px;
  margin: 25px 0 10px 15px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Botão de Toggle da Sidebar (Desktop) */
.sidebar-toggle-btn {
  position: absolute;
  top: 20px;
  right: -15px;
  width: 30px;
  height: 30px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 4px solid var(--bg-body);
  z-index: 101;
  transition: transform 0.3s;
}
.sidebar.collapsed .sidebar-toggle-btn {
  transform: rotate(180deg);
}

/* --- MOBILE & TABLET --- */

.mobile-nav-toggle {
  display: none; /* Escondido no desktop */
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  padding: 5px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  z-index: 99;
}

@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    height: 100vh;
    left: calc(-1 * var(--sidebar-width));
    width: var(--sidebar-width) !important;
  }
  
  .sidebar.mobile-open {
    left: 0;
  }
  
  .sidebar-toggle-btn {
    display: none;
  }
  
  .mobile-nav-toggle {
    display: block;
  }
  
  .sidebar-overlay.active {
    display: block;
  }

  .tenant-bar {
    padding: 10px 20px;
  }
  
  .content-area {
    padding: 20px;
  }

  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .tenant-bar {
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
  }
  
  .user-menu {
    width: 100%;
    justify-content: space-between;
  }
  
  .tenant-switcher {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  
  .tenant-switcher select {
    flex: 1;
    min-width: 150px;
  }
}

.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tenant-bar { background: var(--bg-card); padding: 15px 30px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; transition: background 0.25s; }
.tenant-switcher select { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); padding: 8px 15px; border-radius: var(--radius-sm); transition: background 0.25s, color 0.25s; }
.user-menu { font-size: 14px; color: var(--text-muted); }
.content-area { padding: 30px; flex: 1; overflow-y: auto; }

/* Transições globais */
body, .sidebar, .tenant-bar, .content-area, .kpi-card,
.modal-content, .auth-card, input, select, textarea, button {
  transition: background 0.25s ease, color 0.15s ease, border-color 0.25s ease;
}

/* Light mode overrides */
body.light-mode .sidebar-toggle-btn {
  border-color: var(--bg-body);
}

/* Light mode: sombra leve nos cards */
body.light-mode .kpi-card,
body.light-mode .modal-content,
body.light-mode .auth-card {
  box-shadow: 0 1px 8px rgba(0,0,0,0.08);
}

/* Light mode: sidebar com borda mais visível */
body.light-mode .sidebar {
  box-shadow: 2px 0 8px rgba(0,0,0,0.06);
}

/* Light mode: tenant bar com sombra sutil */
body.light-mode .tenant-bar {
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* Light mode: inputs */
body.light-mode input,
body.light-mode select,
body.light-mode textarea {
  border-color: #cbd5e1;
}
