/* ── Bertie Semijoias — Design System ──────────────────────────────────────
   Brand colors extracted from Papelaria/2022 - Atual:
   Gray:   #4C4D4F   Rose:  #E08981
   ─────────────────────────────────────────────────────────────────────── */

:root {
  --borde:          #4C4D4F;
  --borde-mid:      #636466;
  --borde-light:    #7A7B7D;
  --rose:           #E08981;
  --rose-light:     #F5D6CE;
  --rose-lighter:   #FDF2EF;
  --gray-dark:      #4C4D4F;
  --gray:           #888990;
  --gray-light:     #C8C9CA;
  --gray-pale:      #F0F0F1;
  --black:          #1A1A1A;
  --white:          #FFFFFF;
  --bg:             #F7F7F8;
  --border:         #E3E4E5;
  --shadow:         0 1px 3px rgba(76,77,79,.08), 0 4px 12px rgba(76,77,79,.06);
  --shadow-md:      0 4px 16px rgba(76,77,79,.12);
  --radius:         10px;
  --radius-sm:      6px;
  --sidebar-w:      256px;
  --topbar-h:       56px;
  --transition:     .18s ease;
  --font:           'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--black);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
img { max-width: 100%; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--borde);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  min-height: 72px;
}

.sidebar-logo {
  width: 100%;
  max-height: 44px;
  object-fit: contain;
  object-position: left center;
  filter: brightness(0) invert(1);
  opacity: .92;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section {
  padding: 16px 20px 6px;
}
.nav-section-title {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--rose);
  opacity: .8;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.75);
  font-size: .88rem;
  font-weight: 400;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
  position: relative;
}
.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}
.nav-item.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  font-weight: 500;
  border-left-color: var(--rose);
}

.nav-sub {
  padding-left: 28px;
  font-size: .83rem;
}

.nav-icon {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-tag {
  background: rgba(255,255,255,.12);
  color: var(--rose-light);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  min-width: 26px;
  text-align: center;
}
.nav-item.active .nav-tag {
  background: var(--rose);
  color: #fff;
}

.nav-badge {
  margin-left: auto;
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.7);
  font-size: .68rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}
.nav-badge.active-label {
  background: var(--rose);
  color: #fff;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.active-table-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,.6);
  font-size: .75rem;
}
.active-table-info.warning { color: #F5A623; }
.active-table-info .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4CAF50;
  flex-shrink: 0;
}
.active-table-info.warning .dot { background: #F5A623; }
.active-table-info span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main ───────────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--gray-dark);
  padding: 4px;
  display: none;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--gray);
  flex: 1;
}
.breadcrumb a { color: var(--borde); font-weight: 500; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--gray-light); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Content ────────────────────────────────────────────────────────────── */
.content {
  padding: 24px;
  flex: 1;
}

/* ── Flash messages ─────────────────────────────────────────────────────── */
.flash-container { padding: 0 24px; }
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: .85rem;
  font-weight: 500;
}
.flash-success { background: #E8F5E9; color: #2E7D32; border-left: 4px solid #4CAF50; }
.flash-error   { background: #FFEBEE; color: #C62828; border-left: 4px solid #EF5350; }
.flash-info    { background: #E3F2FD; color: #1565C0; border-left: 4px solid #42A5F5; }
.flash-close {
  background: none; border: none; font-size: 1.1rem; cursor: pointer;
  color: inherit; opacity: .6; padding: 0 4px; line-height: 1;
}
.flash-close:hover { opacity: 1; }

/* ── Page header ────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--borde);
  line-height: 1.2;
}
.page-subtitle {
  font-size: .82rem;
  color: var(--gray);
  margin-top: 2px;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--borde);
}
.card-body { padding: 20px; }

/* ── Stat cards (dashboard) ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
  border-top: 3px solid var(--borde);
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-card-label {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--gray);
}
.stat-card-prefix {
  font-size: .78rem;
  font-weight: 700;
  color: var(--borde);
  background: var(--rose-lighter);
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
}
.stat-card-count {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--borde);
  line-height: 1.1;
}
.stat-card-zero { border-top-color: var(--gray-light); }
.stat-card-zero .stat-card-count { color: var(--gray); }

/* ── Summary cards ──────────────────────────────────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.summary-icon {
  font-size: 1.6rem;
  margin-bottom: 8px;
}
.summary-label { font-size: .78rem; color: var(--gray); font-weight: 500; }
.summary-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--borde);
  line-height: 1.2;
}

/* ── Table ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
thead tr {
  border-bottom: 2px solid var(--border);
}
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gray);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--gray-pale);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--rose-lighter); }
td {
  padding: 11px 14px;
  vertical-align: middle;
}
.td-code {
  font-weight: 700;
  font-size: .9rem;
  color: var(--borde);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.td-price {
  font-weight: 600;
  color: var(--borde);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.td-muted { color: var(--gray); font-size: .8rem; }
.td-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-borde   { background: var(--rose-lighter); color: var(--borde); }
.badge-rose    { background: #FDE8E8; color: #C0392B; }
.badge-gray    { background: var(--gray-pale); color: var(--gray-dark); }
.badge-green   { background: #E8F5E9; color: #2E7D32; }
.badge-active  { background: #E8F5E9; color: #2E7D32; font-weight: 700; }
.badge-inactive{ background: var(--gray-pale); color: var(--gray); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .84rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
  line-height: 1.2;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn-secondary {
  background: var(--white);
  color: var(--borde);
  border-color: var(--borde);
}
.btn-secondary:hover { background: var(--rose-lighter); }

.btn-rose {
  background: var(--rose);
  color: #fff;
  border-color: var(--rose);
}
.btn-rose:hover { background: #C96E66; }

.btn-danger {
  background: #fff;
  color: #C62828;
  border-color: #FFCDD2;
}
.btn-danger:hover { background: #FFEBEE; }

.btn-icon {
  padding: 6px 10px;
  font-size: .8rem;
}

.btn-ghost {
  background: transparent;
  color: var(--gray);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--gray-pale); color: var(--gray-dark); }

.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-lg { padding: 11px 22px; font-size: .95rem; font-weight: 600; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.form-grid-wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.form-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label {
  font-size: .78rem;
  font-weight: 600;
  color: var(--gray-dark);
  letter-spacing: .03em;
}
.form-label .required { color: var(--rose); margin-left: 2px; }

.form-control {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--black);
  font-size: .88rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--borde);
  box-shadow: 0 0 0 3px rgba(76,77,79,.08);
}
.form-control::placeholder { color: var(--gray-light); }
.form-control[readonly] { background: var(--gray-pale); color: var(--gray-dark); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234C4D4F' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-hint {
  font-size: .72rem;
  color: var(--gray);
  margin-top: 2px;
}

.form-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.form-section-title {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--borde);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Calculation panel ──────────────────────────────────────────────────── */
.calc-panel {
  background: var(--rose-lighter);
  border: 1px solid var(--rose-light);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.calc-panel-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--borde);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: .83rem;
  border-bottom: 1px dashed rgba(76,77,79,.1);
}
.calc-row:last-child { border-bottom: none; }
.calc-row.total {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 2px solid var(--rose-light);
  border-bottom: none;
  font-weight: 700;
  font-size: .95rem;
  color: var(--borde);
}
.calc-label { color: var(--gray-dark); }
.calc-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--borde);
}

/* ── Search bar ─────────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-input-wrap .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray);
  font-size: .9rem;
  pointer-events: none;
}
.search-input-wrap .form-control { padding-left: 32px; }

/* ── Filter tabs ────────────────────────────────────────────────────────── */
.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.filter-tab {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 500;
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--gray-dark);
  cursor: pointer;
  transition: all var(--transition);
}
.filter-tab:hover { border-color: var(--borde); color: var(--borde); }
.filter-tab.active {
  background: var(--borde);
  border-color: var(--borde);
  color: #fff;
}
.filter-tab .count {
  background: rgba(255,255,255,.2);
  padding: 0 5px;
  border-radius: 10px;
  margin-left: 4px;
  font-size: .7rem;
}
.filter-tab:not(.active) .count {
  background: var(--gray-pale);
  color: var(--gray);
}

/* ── Cost table sections ────────────────────────────────────────────────── */
.cost-section {
  margin-bottom: 24px;
}
.cost-section-label {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--borde);
  padding: 8px 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 14px;
}

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--gray);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; opacity: .4; }
.empty-state-title { font-size: 1rem; font-weight: 600; color: var(--gray-dark); margin-bottom: 6px; }
.empty-state-text  { font-size: .83rem; margin-bottom: 20px; }

/* ── Divider ────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── Tags ───────────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--gray-pale);
  color: var(--gray-dark);
}
.tag-OU { background: #FFF8E1; color: #F9A825; }
.tag-PR { background: #FAFAFA; color: #616161; border: 1px solid #E0E0E0; }
.tag-RB { background: #E8EAF6; color: #3949AB; }
.tag-RN { background: #263238; color: #ECEFF1; }
.tag-GR { background: #EFEBE9; color: #4E342E; }

/* ── Responsive ─────────────────────────────────────────────────────────── */

/* Tablet + mobile: collapse sidebar */
@media (max-width: 900px) {
  /* Product form: stack columns */
  #produto-form > div[style*="grid-template-columns"],
  #form-exportar > div[style*="grid-template-columns"] {
    display: block !important;
  }
  #produto-form > div > div:last-child,
  #form-exportar > div > div:last-child {
    margin-top: 20px;
    position: static !important;
  }
}

@media (max-width: 768px) {
  /* Sidebar hidden by default, toggled open */
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: flex;
  }
  .content {
    padding: 14px;
  }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    gap: 10px;
  }
  .page-title { font-size: 1.15rem; }

  /* Stat cards: 2 columns */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card-count { font-size: 1.4rem; }

  /* Form grids: 1 column */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .form-grid-wide { grid-template-columns: 1fr; }

  /* Filter tabs: scrollable row */
  .filter-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .filter-tab {
    flex-shrink: 0;
    font-size: .74rem;
    padding: 4px 10px;
  }

  /* Tables: horizontal scroll */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { min-width: 600px; }

  /* Calc panel: full width */
  .calc-panel { font-size: .82rem; }
  .calc-row.total { font-size: .88rem; }

  /* Buttons: full-width on mobile form actions */
  .mobile-full { width: 100%; justify-content: center; }
  .btn-lg { padding: 10px 18px; }

  /* Topbar: shrink breadcrumb */
  .breadcrumb { font-size: .75rem; }
  .topbar { padding: 0 14px; gap: 8px; }

  /* Summary cards: 1 column */
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  /* Card body padding */
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
}

/* Small phones */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 1.05rem; }
  .topbar-actions .btn .btn-text { display: none; } /* hide button labels, keep icons */
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }

/* ── Utilities ──────────────────────────────────────────────────────────── */
.flex   { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.mt-4   { margin-top: 16px; }
.mt-6   { margin-top: 24px; }
.mb-4   { margin-bottom: 16px; }
.mb-6   { margin-bottom: 24px; }
.text-sm    { font-size: .82rem; }
.text-muted { color: var(--gray); }
.text-right { text-align: right; }
.font-mono  { font-family: 'Courier New', monospace; }
.font-bold  { font-weight: 700; }
.w-full     { width: 100%; }

/* ── Overlay (mobile sidebar) ───────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}
.overlay.open { display: block; }

/* ── Loading spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
