:root {
  --primary: #1f2937;
  --accent: #0070F2;
  --muted: #6b7280;
  --card: #ffffff;
  --page-bg: #F5F6F7;
  --sidebar-width: 300px;
  --fiori-primary: #0070F2;
  --fiori-secondary: #58697A;
  --fiori-tertiary: #0854A0;
  --fiori-neutral-bg: #F5F6F7;
  --fiori-text: #1C2B36;
  --fiori-success: #2B7C2B;
  --fiori-success-bg: #E5F2E5;
  --fiori-error: #BB0000;
  --fiori-error-bg: #FFEBEB;
  --fiori-white: #FFFFFF;
}

* {
  box-sizing: border-box;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  margin: 0;
  color: var(--fiori-text);
  font-size: 14px;
  /* Escala global do UI (20% menor) */
  zoom: var(--ui-scale, 1);
}

/* Fallback para browsers sem suporte a zoom (ex.: Firefox) */
@supports not (zoom: 1) {
  body {
    transform: scale(var(--ui-scale));
    transform-origin: top left;
    width: calc(100% / var(--ui-scale));
  }
}

.app {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  color: #fff;
  padding: 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
}

.app-sidebar .brand {
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 1.1rem;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
}

.app-sidebar .menu {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Garante que submenus abertos nao criem rolagem lateral na sidebar */
.app .app-sidebar .sidebar-scroll {
  overflow-y: auto;
  overflow-x: hidden;
}

.app-sidebar .menu a.menu-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: rgba(255, 255, 255, 0.92);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  margin: 0.15rem 0.75rem;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.15s ease;
  line-height: 1.3;
}

.app-sidebar .menu a.menu-item span {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.app-sidebar .menu a.menu-item .arrow-icon {
  flex-shrink: 0;
  margin-left: auto;
}

.app-sidebar .menu a.menu-item .icon {
  font-size: 1.1rem;
  opacity: 0.9;
  flex-shrink: 0;
}

.app-sidebar .menu a.menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.app-sidebar .menu a.menu-item.active {
  background: rgba(255, 255, 255, 0.12);
  font-weight: 500;
}

/* Company Select */
.app-sidebar .company-select {
  padding: 0.5rem 0.75rem;
}

.app-sidebar .company-select .form-select {
  font-size: 0.85rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0.4rem 0.6rem;
}

.app-sidebar .company-select .form-select:focus {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: none;
}

.app-sidebar .company-select .form-select option {
  background: var(--primary);
  color: #fff;
}

/* No seletor de empresa da sidebar: truncar somente no campo fechado */
.app-sidebar .sidebar-company .form-select {
  max-width: 100%;
  padding-right: 2.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mantem o nome completo nas opcoes do dropdown */
.app-sidebar .sidebar-company .form-select option {
  white-space: normal;
  text-overflow: clip;
}

/* Topbar */
.app-topbar {
  height: 60px;
  background: #ffffff;
  border-bottom: 1px solid #e6e9ee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.04);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-left h5 {
  margin: 0;
  font-weight: 600;
  color: #0f1724;
  font-size: 1.1rem;
}

.topbar-search {
  flex: 1;
  max-width: 400px;
  margin: 0 2rem;
}

.topbar-search input {
  width: 100%;
  font-size: 0.9rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-actions .dropdown img {
  border-radius: 8px;
  object-fit: cover;
}

/* Main Content */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-width);
}

.app-content {
  padding: 1.5rem;
  flex: 1;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid #e6e9ee;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  margin-bottom: 1rem;
}

.card h6 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* Page Title */
.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e6e9ee;
}

.page-title h4 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  color: #111827;
}

/* Tables */
.table {
  font-size: 0.9rem;
}

.table th {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #e6e9ee;
}

/* Buttons */
.btn {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
}

.btn-sm {
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
}

.btn-ai-generate {
  background: linear-gradient(135deg, #fff9db 0%, #ffe8a3 100%);
  color: #7a4f00;
  border: 1px solid #f0c95a;
  box-shadow: 0 0 0 0 rgba(240, 201, 90, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
  animation: ai-magic-glow 2.2s ease-in-out infinite;
}

.btn-ai-generate:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(122, 79, 0, 0.2);
  filter: saturate(1.06);
}

.btn-ai-generate:disabled {
  background: #f5f5f5;
  color: #8b8b8b;
  border-color: #d9d9d9;
  animation: none;
  box-shadow: none;
}

@keyframes ai-magic-glow {
  0% {
    box-shadow: 0 0 0 0 rgba(240, 201, 90, 0.38);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(240, 201, 90, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(240, 201, 90, 0);
  }
}

/* Forms */
.form-label {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: #374151;
}

.form-control,
.form-select {
  font-size: 0.9rem;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  padding: 0.5rem 0.75rem;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 94, 215, 0.1);
}

/* Responsive */
@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  .app-sidebar.show {
    transform: translateX(0);
  }
  
  .app-main {
    margin-left: 0;
  }
  
  .topbar-search {
    display: none;
  }
  
  .app-content {
    padding: 1rem;
  }
}

/* Scrollbar personalizada para sidebar */
.app-sidebar::-webkit-scrollbar {
  width: 6px;
}

.app-sidebar::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}

.app-sidebar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}


/* --- Estilos do Menu Retrátil --- */

/* Esconde o submenu por padrão */
.submenu {
    display: none;
    background: rgba(0, 0, 0, 0.15);
    padding-bottom: 5px;
    max-width: 100%;
    overflow-x: hidden;
}

.app-sidebar .menu-folder-container,
.app-sidebar .submenu,
.app-sidebar .submenu .menu-item {
    max-width: 100%;
    overflow-x: hidden;
}

/* Identação visual para subníveis */
.submenu .menu-item {
    padding-left: 2.5rem;
    font-size: 0.85rem;
    min-height: 35px;
}

/* Seta de indicação */
.arrow-icon {
    transition: transform 0.3s ease;
    font-size: 1.2rem;
    opacity: 0.7;
}

/* Rotação da seta quando a pasta estiver aberta */
.folder-open > .folder-toggle .arrow-icon {
    transform: rotate(90deg);
}

/* Destaque para o container da pasta ativa */
.menu-folder-container.folder-open {
    background: rgba(255, 255, 255, 0.03);
}

/* Dashboard */
.dashboard-toolbar {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  border: none;
  background: var(--fiori-white);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05), 0 2px 4px 0 rgba(0,0,0,0.08);
  border-radius: 4px;
  padding: 1rem 1.5rem;
}

.dashboard-toolbar-left {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  flex: 1 1 auto;
  min-width: 220px;
}

.dashboard-toolbar-left h4 {
  font-weight: 600;
  color: var(--fiori-text);
  font-size: 1.40rem;
  letter-spacing: 0;
}

.dashboard-toolbar-right {
  display: flex;
  gap: 1.50rem;
  width: 70%;
  margin-left: 1rem;
  justify-content: flex-end;
  align-items: center;
}

.dashboard-toolbar-right .form-check {
  white-space: nowrap;
}

.dashboard-select {
  min-width: 85px;
  max-width: 100px;
  font-size: 0.78rem;
  padding: 0.25rem 0.45rem;
}

.btn-refresh {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #cfd8e3;
  background: #ffffff;
  color: #0b5ed7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-refresh:hover {
  background: #eaf2ff;
  border-color: #9fc0f6;
}

.btn-refresh i {
  font-size: 1rem;
}

@media (max-width: 900px) {
  .dashboard-toolbar {
    align-items: flex-start;
  }

  .dashboard-toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }
}

.dashboard-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1rem;
}

.dashboard-group {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

.dashboard-group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #D9D9D9;
}

.dashboard-group-head h5 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--fiori-text);
}

.dashboard-group-actions {
  display: flex;
  gap: 0.4rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
  grid-auto-flow: dense;
}

.dashboard-card {
  border: none;
  border-radius: 8px;
  background: var(--fiori-white);
  padding: 1.25rem;
  min-height: 320px;
  max-height: 760px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05), 0 2px 4px 0 rgba(0,0,0,0.08); /* Fiori Standard Shadow */
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dashboard-card:hover {
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05), 0 4px 8px 0 rgba(0,0,0,0.12);
}

.dashboard-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.dashboard-card-head-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dashboard-card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--fiori-text);
}

.dashboard-card-drag-handle {
  cursor: grab;
  color: var(--fiori-secondary);
  font-size: 1.2rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.dashboard-card-drag-handle:hover {
  opacity: 1;
}
.dashboard-card-drag-handle:active {
  cursor: grabbing;
}

.dashboard-card-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.btn-fiori-icon {
  background: transparent;
  border: none;
  color: var(--fiori-secondary);
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
}
.btn-fiori-icon:hover {
  color: var(--fiori-primary);
  background: var(--fiori-neutral-bg);
}

.dashboard-card-remarks {
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--fiori-secondary);
}

.dashboard-chart-wrap {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  min-height: 200px;
  max-height: none;
  border: none;
  background: transparent;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  overflow: auto;
}

.dashboard-card-content-frame,
.dashboard-preview-frame {
  width: 100%;
  height: 100%;
  min-height: 100%;
  border: 0;
  display: block;
  background: transparent;
}

.dashboard-card-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #F0F0F0;
  display: flex;
  justify-content: flex-end;
}

.dashboard-card .badge.text-bg-light {
  border: 1px solid #D9D9D9;
  color: var(--fiori-secondary);
  background: var(--fiori-white) !important;
  font-weight: 400;
}
.dashboard-card .badge.text-bg-primary {
  background: var(--fiori-primary) !important;
  color: var(--fiori-white);
  font-weight: 500;
}

/* Fiori Custom Components inside Card Content */
.fiori-kpi-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
}
.fiori-kpi-title {
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--fiori-secondary);
  margin-bottom: 0.5rem;
}
.fiori-kpi-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.fiori-kpi-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--fiori-text);
  line-height: 1;
}
.fiori-kpi-delta {
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.15rem;
}
.fiori-kpi-footer {
  font-size: 0.75rem;
  color: var(--fiori-secondary);
  font-style: italic;
}

.fiori-list-container {
  overflow-x: auto;
}
.fiori-table th {
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--fiori-secondary);
  padding: 0.5rem;
  border-bottom: 1px solid #E4E5E7;
}
.fiori-table td {
  font-size: 0.85rem;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid #F0F0F0;
  vertical-align: middle;
}
.fiori-table tr:last-child td {
  border-bottom: none;
}
.fiori-badge {
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Tamanhos Fiori */
.card-size-1x1 {
  grid-column: span 1;
  grid-row: span 1;
}

.card-size-2x1 {
  grid-column: span 2;
  grid-row: span 1;
}

.card-size-1x2 {
  grid-column: span 1;
  grid-row: span 2;
  min-height: 656px;
  max-height: 760px;
}

.card-size-2x2 {
  grid-column: span 2;
  grid-row: span 2;
  min-height: 760px;
  max-height: 760px;
}

.dashboard-preview-stage {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.dashboard-preview-stage .dashboard-preview-placeholder {
  background: linear-gradient(145deg, #eef1f4, #e6eaee);
  border: 1px dashed #c7d0db;
  box-shadow: none;
  min-height: 320px;
  max-height: 760px;
  pointer-events: none;
}

.dashboard-preview-stage .dashboard-preview-placeholder::before {
  content: '';
  display: block;
  width: 72%;
  height: 12px;
  margin: 10px 0 14px 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.35);
}

/* Sortable JS styles */
.sortable-ghost {
  opacity: 0.45;
  background: #eef4ff;
  border: 1px dashed #7aa7f5;
}

@media (max-width: 1024px) {
  .card-size-2x1, .card-size-2x2 {
    grid-column: span 1;
  }
}

@media (max-width: 768px) {
  .dashboard-toolbar-right {
    width: 100%;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-card {
    min-height: 250px;
  }
}