/* =============================================
   GestãoPro — Sistema de Gestão
   style.css
   ============================================= */

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

:root {
  --sidebar-w: 225px;
  --header-h: 54px;
  --accent: #1D6FA4;
  --accent-hover: #185FA5;
  --accent-light: #E6F1FB;
  --accent-text: #0C447C;

  --bg: #ffffff;
  --bg-secondary: #f5f5f3;
  --bg-tertiary: #efefed;

  --text-primary: #1a1a18;
  --text-secondary: #6b6b67;
  --text-tertiary: #a0a09c;

  --border: rgba(0,0,0,0.1);
  --border-md: rgba(0,0,0,0.15);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  line-height: 1.5;
}

/* =============================================
   LAYOUT
   ============================================= */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-tertiary);
  min-width: 0;
}

/* CORREÇÃO PRINCIPAL: garante rolagem em todas as páginas */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px;
  -webkit-overflow-scrolling: touch; /* scroll suave no iOS */
}

/* Cada página ocupa no mínimo 100% mas pode crescer */
[id^="pg-"] {
  min-height: 100%;
}

.hidden { display: none !important; }

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  position: relative;
  transition: width 0.2s, min-width 0.2s;
}

.logo {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}

.logo-icon {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.logo-sub {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: sticky;
  top: 0;
}

.nav-section {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 14px 16px 5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-right: 2px solid transparent;
  user-select: none;
}

.nav-item i {
  font-size: 16px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
  border-right-color: var(--accent);
}

.badge-count {
  margin-left: auto;
  background: #E24B4A;
  color: #fff;
  font-size: 10px;
  border-radius: 10px;
  padding: 1px 6px;
  font-weight: 600;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}

.user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.user-role {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* =============================================
   TOPBAR
   ============================================= */
.topbar {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 10px;
  flex-shrink: 0;
}

.page-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  border: 0.5px solid var(--border-md);
  background: var(--bg);
  color: var(--text-primary);
  transition: background 0.12s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:hover { background: var(--bg-secondary); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

/* =============================================
   SEARCH BAR
   ============================================= */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  width: 220px;
}

.search-bar i {
  font-size: 14px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-bar input {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  width: 100%;
  font-family: inherit;
}

.search-bar input::placeholder { color: var(--text-tertiary); }

/* =============================================
   CARDS & METRICS
   ============================================= */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.metric-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 22px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.2;
}

.metric-delta {
  font-size: 11px;
  margin-top: 4px;
}

.delta-up { color: #3B6D11; }
.delta-down { color: #A32D2D; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* =============================================
   AVATAR
   ============================================= */
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

/* =============================================
   TABLE
   ============================================= */
.table-wrap {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg);
  margin-bottom: 20px;
  overflow-x: auto; /* scroll horizontal em tabelas no mobile */
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 500px; /* evita tabela espremida no mobile */
}

th {
  background: var(--bg-secondary);
  padding: 9px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  border-bottom: 0.5px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }

/* =============================================
   STATUS BADGES
   ============================================= */
.status {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.status-open    { background: #E6F1FB; color: #0C447C; }
.status-progress{ background: #FAEEDA; color: #633806; }
.status-done    { background: #EAF3DE; color: #27500A; }
.status-cancel  { background: #FCEBEB; color: #791F1F; }
.status-budget  { background: #EEEDFE; color: #3C3489; }

/* =============================================
   TAGS
   ============================================= */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.tag-blue  { background: #E6F1FB; color: #0C447C; }
.tag-green { background: #EAF3DE; color: #27500A; }
.tag-amber { background: #FAEEDA; color: #633806; }
.tag-red   { background: #FCEBEB; color: #791F1F; }

/* =============================================
   FORMS
   ============================================= */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-control {
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
  width: 100%;
}

.form-control:focus { border-color: var(--accent); }

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

/* =============================================
   INFO GRID (detail view)
   ============================================= */
.info-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 13px;
  align-items: center;
}

.info-label { color: var(--text-secondary); }

/* =============================================
   FINANCIAL ROWS
   ============================================= */
.fin-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}

.fin-row:last-child { border-bottom: none; }

.fin-name { font-size: 13px; font-weight: 500; }
.fin-date { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.fin-value { font-size: 14px; font-weight: 500; }
.fin-value.green { color: #3B6D11; }
.fin-value.red   { color: #A32D2D; }

.fin-total {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 0.5px solid var(--border);
  font-size: 13px;
}

/* =============================================
   STOCK / PROGRESS
   ============================================= */
.stock-label  { font-size: 12px; color: var(--text-secondary); }
.stock-qty    { font-size: 13px; font-weight: 500; margin-top: 3px; }
.stock-qty.red    { color: #A32D2D; }
.stock-qty.orange { color: #BA7517; }

.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* =============================================
   CLIENTS TABLE
   ============================================= */
.client-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.client-name { font-size: 13px; font-weight: 500; }
.client-doc  { font-size: 11px; color: var(--text-tertiary); }

/* =============================================
   REPORTS GRID
   ============================================= */
.report-card {
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}

.report-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

.report-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 18px;
}

.report-title { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.report-desc  { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

/* =============================================
   SCROLLBAR
   ============================================= */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

/* =============================================
   RESPONSIVE — Tablet (max 900px)
   ============================================= */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }

  .sidebar {
    width: 60px;
    min-width: 60px;
  }

  .logo-text, .logo-sub, .nav-section { display: none; }
  .nav-item span:not(.badge-count) { display: none; }
  .user-info > div:not(.avatar) { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .nav-item.active { border-right: none; border-left: 2px solid var(--accent); }

  .search-bar { width: 160px; }
  .content { padding: 16px; }
}

/* =============================================
   RESPONSIVE — Mobile (max 600px)
   ============================================= */
@media (max-width: 600px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100%;
    width: 240px !important;
    min-width: 240px !important;
    box-shadow: 2px 0 16px rgba(0,0,0,0.12);
    transition: left 0.25s ease;
  }

  .sidebar.open {
    left: 0;
  }

  /* Mostra textos novamente no mobile quando aberto */
  .sidebar.open .logo-text,
  .sidebar.open .logo-sub,
  .sidebar.open .nav-section,
  .sidebar.open .nav-item span:not(.badge-count),
  .sidebar.open .user-info > div { display: block; }

  .sidebar.open .nav-item { justify-content: flex-start; padding: 8px 16px; }

  /* Overlay ao abrir sidebar */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 99;
  }

  .sidebar-overlay.show { display: block; }

  /* Botão hamburguer na topbar */
  .btn-menu {
    display: flex !important;
  }

  .grid-4 { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }

  .content { padding: 12px; }
  .search-bar { width: 100%; }

  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  /* Esconde busca no mobile para economizar espaço */
  .topbar .search-bar { display: none; }
}

/* Botão hamburguer — oculto por padrão, visível só no mobile */
.btn-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 20px;
  flex-shrink: 0;
}
