/* ==========================================================================
   BROSSARD LAB — Design System
   Plataforma Interna | main.css
   ========================================================================== */

/* ---------- Custom Properties ---------- */
:root {
  /* Colors */
  --color-bg:            #111A1E;
  --color-surface:       #0F171B;
  --color-surface-hover: #152028;
  --color-border:        #223039;
  --color-border-light:  #2a3d49;
  --color-text:          #E7EEF2;
  --color-text-muted:    #C7D7DE;
  --color-text-dim:      #7a929d;
  --color-accent:        #2EC3B3;
  --color-accent-hover:  #27AC9E;
  --color-accent-dim:    hsla(171, 63%, 47%, 0.15);
  --color-accent-glow:   0 0 60px hsla(171, 63%, 47%, 0.15);
  --color-danger:        #E74C4C;
  --color-danger-hover:  #D43D3D;
  --color-danger-dim:    hsla(0, 75%, 60%, 0.12);
  --color-warning:       #E7A84C;
  --color-warning-dim:   hsla(36, 75%, 60%, 0.12);
  --color-success:       #2EC36B;
  --color-success-dim:   hsla(147, 63%, 47%, 0.12);
  --color-info:          #4C9AE7;
  --color-info-dim:      hsla(213, 75%, 60%, 0.12);

  /* Typography */
  --font-family:     'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-size-xs:    0.6875rem;   /* 11px */
  --font-size-sm:    0.75rem;     /* 12px */
  --font-size-base:  0.875rem;    /* 14px */
  --font-size-md:    1rem;        /* 16px */
  --font-size-lg:    1.125rem;    /* 18px */
  --font-size-xl:    1.5rem;      /* 24px */
  --font-size-2xl:   2rem;        /* 32px */
  --font-weight-light:    300;
  --font-weight-regular:  400;
  --font-weight-medium:   500;
  --font-weight-semibold: 600;
  --font-weight-bold:     700;
  --line-height:     1.6;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Layout */
  --sidebar-width:    260px;
  --sidebar-collapsed: 64px;
  --header-height:    60px;
  --content-max-width: 100%;

  /* Borders & Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-card:    0 4px 24px hsla(0, 0%, 0%, 0.4);
  --shadow-elevated: 0 8px 40px hsla(0, 0%, 0%, 0.55);
  --shadow-subtle:  0 2px 8px hsla(0, 0%, 0%, 0.25);

  /* Transitions */
  --transition-fast:   150ms ease;
  --transition-base:   250ms ease;
  --transition-slow:   400ms ease;
}

/* ---------- Reset / Normalize ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-regular);
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--color-accent-hover); }

img, svg { display: block; max-width: 100%; }

ul, ol { list-style: none; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-light);
}

/* ---------- App Layout ---------- */
#app {
  display: flex;
  min-height: 100vh;
}

#sidebar-container {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  transition: width var(--transition-base), min-width var(--transition-base);
}

#app.sidebar-collapsed #sidebar-container {
  width: var(--sidebar-collapsed);
  min-width: var(--sidebar-collapsed);
}

#main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
  transition: margin-left var(--transition-base);
}

#app.sidebar-collapsed #main-wrapper {
  margin-left: var(--sidebar-collapsed);
}

#app.no-sidebar #sidebar-container { display: none; }
#app.no-sidebar #main-wrapper { margin-left: 0; }
#app.no-sidebar #header-container { display: none; }

#header-container {
  height: var(--header-height);
  min-height: var(--header-height);
  position: sticky;
  top: 0;
  z-index: 50;
}

#page-content {
  flex: 1;
  padding: var(--space-8);
  max-width: var(--content-max-width);
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
  animation: fadeInPage 0.3s ease;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo {
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 80px;
}

.sidebar-logo svg {
  width: 100%;
  max-width: 200px;
  height: auto;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) 0;
  overflow-y: auto;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-fast);
  cursor: pointer;
  border-left: 3px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}

.sidebar-nav-item:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}

.sidebar-nav-item.active {
  color: var(--color-accent);
  background: var(--color-accent-dim);
  border-left-color: var(--color-accent);
}

.sidebar-nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  color: var(--color-text-dim);
}

/* ---------- Mobile Menu Button ---------- */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--color-text);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.mobile-menu-btn:hover { background: var(--color-bg-hover, rgba(255,255,255,0.08)); }
.mobile-menu-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ---------- Header ---------- */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 var(--space-8);
  gap: var(--space-4);
}

.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--color-accent-dim);
  border: 2px solid var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-accent);
}

.header-name {
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-base);
}

.header-role {
  font-size: var(--font-size-xs);
  color: var(--color-text-dim);
}

.header-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}
.header-btn:hover {
  color: var(--color-text);
  background: var(--color-surface-hover);
}
.header-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Typography ---------- */
.text-2xl { font-size: var(--font-size-2xl); font-weight: var(--font-weight-bold); line-height: 1.2; }
.text-xl  { font-size: var(--font-size-xl);  font-weight: var(--font-weight-semibold); line-height: 1.3; }
.text-lg  { font-size: var(--font-size-lg);  font-weight: var(--font-weight-semibold); }
.text-md  { font-size: var(--font-size-md);  font-weight: var(--font-weight-medium); }
.text-base { font-size: var(--font-size-base); }
.text-sm  { font-size: var(--font-size-sm); }
.text-xs  { font-size: var(--font-size-xs); }
.text-muted { color: var(--color-text-muted); }
.text-dim  { color: var(--color-text-dim); }
.text-accent { color: var(--color-accent); }
.font-light    { font-weight: var(--font-weight-light); }
.font-medium   { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold     { font-weight: var(--font-weight-bold); }

/* ---------- Grid Utilities ---------- */
.grid       { display: grid; gap: var(--space-6); }
.grid-2     { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.grid-3     { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-4     { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.grid-5     { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.grid-auto  { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); max-width: 100%; }

.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.flex-wrap  { flex-wrap: wrap; }
.items-center  { align-items: center; }
.items-start   { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* ---------- Spacing ---------- */
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.p-4  { padding: var(--space-4); }
.p-6  { padding: var(--space-6); }
.p-8  { padding: var(--space-8); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }

/* ---------- Form Elements ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input,
.form-select,
.form-textarea {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  color: var(--color-text);
  font-size: var(--font-size-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  width: 100%;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-dim);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-dim);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%23C7D7DE' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-select option {
  background: var(--color-surface);
  color: var(--color-text);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--font-size-base);
}

.form-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.form-error {
  font-size: var(--font-size-sm);
  color: var(--color-danger);
}

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-dim);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1;
}

.btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-bg);
  font-weight: var(--font-weight-semibold);
}
.btn-primary:hover {
  background: var(--color-accent-hover);
  box-shadow: var(--color-accent-glow);
}

.btn-secondary {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  color: var(--color-text);
  border-color: var(--color-border-light);
  background: var(--color-surface-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--color-danger-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--color-accent);
  padding: var(--space-2) var(--space-3);
}
.btn-ghost:hover {
  background: var(--color-accent-dim);
}

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--font-size-md);
}

.btn:disabled,
.btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-md);
}

/* ---------- Page Transition ---------- */
@keyframes fadeInPage {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Utility ---------- */
.hidden     { display: none !important; }
.sr-only    { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full     { width: 100%; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.relative    { position: relative; }
.overflow-auto { overflow: auto; }
.cursor-pointer { cursor: pointer; }

/* ---------- Responsive ----------
 * As classes .grid-2/3/4/5/auto ja usam auto-fit + minmax entao sao responsivas
 * por natureza. As media queries abaixo ajustam APENAS padding, sidebar e
 * elementos que nao tem fluidez intrinseca.
 */
@media (max-width: 1400px) {
  #page-content { padding: var(--space-6); }
}
@media (max-width: 1200px) {
  /* Notebook: sidebar mais estreito para liberar espaço */
  :root { --sidebar-width: 220px; }
  #page-content { padding: var(--space-5); }
  /* Tabelas com células mais compactas */
  .data-table th,
  .data-table td { padding: var(--space-2) var(--space-3); font-size: var(--font-size-sm); }
}
@media (max-width: 900px) {
  #page-content { padding: var(--space-4); }
  :root { --sidebar-width: 200px; }
  .page-title { font-size: var(--font-size-lg); }
}
@media (max-width: 768px) {
  /* Tablet portrait: sidebar as overlay */
  :root { --sidebar-width: min(85vw, 300px); }
  #sidebar-container {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    z-index: 200;
  }
  #sidebar-container.mobile-open { transform: translateX(0); }
  #main-wrapper { margin-left: 0; width: 100%; max-width: 100vw; }
  #page-content { padding: var(--space-3); max-width: 100vw; }
  .page-header { flex-direction: column; align-items: stretch; gap: var(--space-3); }

  /* Sidebar items fit better on narrow widths */
  .sidebar-nav-item { padding: var(--space-3) var(--space-4); font-size: var(--font-size-sm); }
  .sidebar-nav-item svg { width: 18px; height: 18px; }
  .sidebar-logo { padding: var(--space-4); min-height: 64px; }
  .sidebar-logo svg { max-width: 150px; }

  /* Header compact on mobile */
  .header { padding: 0 var(--space-3); gap: var(--space-2); }
  .header-name { font-size: var(--font-size-sm); }
  .header-role { font-size: 0.65rem; }
  .header-avatar { width: 32px; height: 32px; }

  /* Hamburger button */
  .mobile-menu-btn { display: flex !important; }

  /* Overlay backdrop */
  .mobile-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 199;
  }
  .mobile-overlay.active { display: block; }

  /* Dashboard financeiro charts stack */
  #fin-charts-grid { grid-template-columns: 1fr !important; }

  /* Payment rows compact */
  .card { font-size: 0.875rem; }

  /* Form rows stack */
  .form-row { grid-template-columns: 1fr !important; }

  /* Filter bar fills width, no min-width overflow */
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .form-select,
  .filter-bar .form-input { width: 100%; min-width: 0; }

  /* Tables scroll horizontally within wrapper (not page) */
  .table-wrapper { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 600px; }

  /* Toast fits viewport */
  .toast { min-width: 0; max-width: calc(100vw - 24px); }
  .toast-container { left: 12px; right: 12px; }

  /* Modal full-width on mobile */
  .modal { width: calc(100vw - 24px); max-width: none; margin: var(--space-3); }
  .modal-lg { max-width: none; }

  /* Cards don't force min width */
  .card { max-width: 100%; }

  /* Images/media contained */
  img, video, iframe, canvas { max-width: 100%; height: auto; }
}

@media (max-width: 480px) {
  #page-content { padding: var(--space-3) var(--space-2); }
  .page-title { font-size: 1.1rem; }
  .page-description { font-size: 0.8rem; }
  .btn { padding: 8px 12px; font-size: 0.8rem; }
  .sidebar-logo svg { max-width: 130px; }
  .header { padding: 0 var(--space-2); }
}

/* Scrollbar visível e estilizada para containers com overflow horizontal */
.table-wrapper::-webkit-scrollbar { height: 10px; width: 10px; }
.table-wrapper::-webkit-scrollbar-track { background: hsla(200, 20%, 8%, 0.3); border-radius: 5px; }
.table-wrapper::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 5px; }
.table-wrapper::-webkit-scrollbar-thumb:hover { background: var(--color-accent); }
