/*
 * LM CRM — Tailwind CSS — Custom base styles
 * 
 * This file contains only styles that Tailwind utility classes can't handle:
 * - CSS custom properties for theming
 * - Sidebar layout (fixed positioning, transitions)
 * - Dark mode overrides
 * - Component styles that are too complex for utility classes alone
 * - Print / responsive overrides
 */

/* ===== CSS Custom Properties ===== */
:root {
  --sidebar-width: 250px;
  --header-height: 56px;
  --sidebar-bg: #5a1fb3;
  --sidebar-text: #ffffff;
  --sidebar-active: #b48aff;
  --sidebar-hover-bg: #4718a0;
  --primary: #843cff;
  --primary-hover: #6d2ed4;
  --accent: #a78bfa;
}

.dark {
  --sidebar-bg: #4718a0;
  --sidebar-hover-bg: #3a1288;
}

/* ===== Base Reset ===== */
* { box-sizing: border-box; }

body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  margin: 0;
  background: #f1f5f9;
  color: #0f172a;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.dark body,
body.dark-mode {
  background: #0f172a;
  color: #e2e8f0;
}

/* ===== Layout Shell ===== */
.app-wrapper {
  display: flex;
  width: 100%;
  min-height: 100vh;
}

.app-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

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

/* ===== Sidebar ===== */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s ease;
  display: flex;
  flex-direction: column;
}

.app-sidebar.collapsed {
  width: 70px;
}

.app-sidebar.collapsed .sidebar-label,
.app-sidebar.collapsed .sidebar-divider-text,
.app-sidebar.collapsed .sidebar-footer-text {
  display: none;
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: rgba(0,0,0,0.2);
  color: #fff;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.sidebar-brand:hover { color: #fff; }

.sidebar-nav {
  list-style: none;
  padding: 8px 0;
  margin: 0;
  flex: 1;
}

.sidebar-nav li { margin-bottom: 2px; }

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 8px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: all 0.2s ease;
  gap: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  color: #fff;
  background: var(--sidebar-hover-bg);
  border-left-color: var(--sidebar-active);
}

.sidebar-link.active {
  color: #fff;
  background: var(--sidebar-active);
  border-left-color: #fff;
  font-weight: 600;
}

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

.sidebar-divider {
  padding: 10px 20px 5px;
  color: rgba(255,255,255,0.5);
  font-size: 0.6875rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.sidebar-footer {
  padding: 10px 0;
  border-top: 1px solid rgba(255,255,255,0.08);
}

/* ===== Sidebar Submenu (Configurações) ===== */
.sidebar-submenu { position: relative; }

.sidebar-submenu-toggle {
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sidebar-submenu-toggle.open {
  color: #fff;
  background: rgba(255,255,255,0.1);
  border-left-color: var(--sidebar-active);
}

.submenu-arrow { transition: transform 0.2s ease; font-size: 0.75rem; }
.submenu-arrow.rotate-180 { transform: rotate(180deg); }

.sidebar-submenu-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 0 0 8px;
}

.sidebar-submenu-content.open {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 4px 0 8px 8px;
}

.sidebar-sub-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 32px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 400;
  border-radius: 6px;
  margin: 1px 12px 1px 0;
  transition: all 0.15s ease;
}

.sidebar-sub-link:hover {
  color: #fff;
  background: var(--sidebar-hover-bg);
}

.sidebar-sub-link.active {
  color: #fff;
  background: var(--sidebar-active);
  font-weight: 500;
}

.sidebar-sub-link i { font-size: 0.9rem; width: 16px; text-align: center; }

/* Esconde submenu quando sidebar está colapsada */
.app-sidebar.collapsed .sidebar-submenu-content { display: none; }
.app-sidebar.collapsed .sidebar-submenu-toggle .submenu-arrow { display: none; }

/* ===== Header ===== */
.app-header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 0 24px;
  height: var(--header-height);
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 999;
  min-width: 0;
}

.dark .app-header {
  background: #1e293b;
  border-color: #334155;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-sidebar {
    width: 70px;
  }
  .app-sidebar .sidebar-label,
  .app-sidebar .sidebar-divider-text,
  .app-sidebar .sidebar-footer-text {
    display: none;
  }
  .app-sidebar .sidebar-link {
    justify-content: center;
    padding: 12px;
  }
  .app-main {
    margin-left: 70px;
  }
  .app-content {
    padding: 16px;
  }
}

/* ===== Scrollbar Styling ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }

/* ===== Modal Backdrop ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}

.modal-backdrop.hidden { display: none; }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-slide-up { animation: slideUp 0.2s ease; }
.animate-slide-down { animation: slideDown 0.2s ease; }

/* ===== Form Controls ===== */
.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  background: #fff;
  color: #0f172a;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.dark .form-input {
  background: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-input::placeholder {
  color: #94a3b8;
}

.form-select-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  background: #fff;
  color: #0f172a;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 20px;
  padding-right: 32px;
}

.dark .form-select-input {
  background-color: #1e293b;
  border-color: #475569;
  color: #e2e8f0;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
}

.form-select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

/* ===== Toggle Switch ===== */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 44px;
  height: 24px;
  background: #cbd5e1;
  border-radius: 12px;
  transition: background 0.2s ease;
  position: relative;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(20px);
}

.dark .toggle-track {
  background: #475569;
}

/* ===== Dropdown Menu ===== */
.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 50;
  min-width: 180px;
  padding: 4px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  display: none;
}

.dark .dropdown-menu {
  background: #1e293b;
  border-color: #334155;
}

.dropdown-menu.show { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.875rem;
  color: #0f172a;
  text-decoration: none;
  transition: background 0.15s ease;
}

.dark .dropdown-item { color: #e2e8f0; }

.dropdown-item:hover {
  background: #f1f5f9;
}

.dark .dropdown-item:hover {
  background: #334155;
}

/* ===== Stats Card Hover ===== */
.stats-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stats-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px -8px rgba(0,0,0,0.15);
}
