:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4f;
  --text: #e8ecf1;
  --muted: #8b9cb3;
  --accent: #3d9ee5;
  --accent-dim: #2a7ab8;
  --success: #3ecf8e;
  --warning: #e8a838;
  --danger: #e85d5d;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
}

html[data-theme="light"] {
  --bg: #f0f3f8;
  --surface: #ffffff;
  --surface-hover: #e8eef6;
  --border: #c8d2e0;
  --text: #15202b;
  --muted: #5a6b80;
  --accent: #1b6fb8;
  --accent-dim: #155a94;
  --success: #1f8f5a;
  --warning: #c77a0a;
  --danger: #c43d3d;
}

@media (prefers-color-scheme: light) {
  html[data-theme="auto"] {
    --bg: #f0f3f8;
    --surface: #ffffff;
    --surface-hover: #e8eef6;
    --border: #c8d2e0;
    --text: #15202b;
    --muted: #5a6b80;
    --accent: #1b6fb8;
    --accent-dim: #155a94;
    --success: #1f8f5a;
    --warning: #c77a0a;
    --danger: #c43d3d;
  }
}

.theme-select {
  max-width: 130px;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

a:hover {
  text-decoration: underline;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

header.site {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header.site .inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.header-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle:hover {
  background: var(--surface-hover);
}

.nav-toggle-bars {
  display: block;
  width: 1.25rem;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  box-shadow:
    0 -6px 0 currentColor,
    0 6px 0 currentColor;
}

.header-org-form .header-org-select {
  width: 100%;
  max-width: none;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.header-user-label {
  margin: 0;
  white-space: normal;
  font-size: 0.82rem;
  line-height: 1.35;
  max-width: 100%;
  word-break: break-word;
}

.main-nav {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  width: 100%;
  padding: 0.35rem 0 0;
  border-top: 1px solid var(--border);
}

.inner.is-nav-open .main-nav {
  display: flex;
}

.header-end {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  white-space: normal;
  justify-content: flex-start;
  width: 100%;
}

@media (min-width: 960px) {
  header.site .inner {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
  }

  .header-brand-row {
    order: 1;
    width: auto;
    flex-shrink: 0;
  }

  .header-org-form {
    order: 2;
    flex-shrink: 1;
    min-width: 0;
  }

  .header-org-form .header-org-select {
    max-width: 240px;
    width: auto;
  }

  .main-nav {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 0;
    border-top: none;
    gap: 0.35rem;
    justify-content: flex-end;
    order: 3;
  }

  .inner.is-nav-open .main-nav {
    display: flex !important;
  }

  .header-end {
    order: 4;
    width: auto;
    flex-shrink: 0;
    justify-content: flex-end;
    margin-left: auto;
  }

  .nav-toggle {
    display: none;
  }

  .header-user-label {
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.main-nav {
  overflow: visible;
}

.main-nav > a {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

.main-nav > a:hover,
.main-nav > a.active {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}

.main-nav .nav-dropdown {
  position: relative;
}

.nav-dropdown summary {
  list-style: none;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

.nav-dropdown summary::-webkit-details-marker {
  display: none;
}

.nav-dropdown summary:hover,
.nav-dropdown summary.active,
.nav-dropdown[open] summary {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  padding: 0.35rem;
  z-index: 50;
}

@media (max-width: 959px) {
  .main-nav .nav-dropdown-menu {
    position: static;
    margin: 0.25rem 0 0.35rem 0.5rem;
    box-shadow: none;
    border: 1px solid var(--border);
    min-width: 0;
  }

  .main-nav .nav-dropdown summary {
    width: 100%;
    box-sizing: border-box;
  }
}

/* Keep the dropdown floating and visible above header flow */
header.site .inner,
.nav-dropdown {
  overflow: visible;
}

.nav-dropdown-menu a {
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
}

.nav-pending-badge {
  display: inline-block;
  min-width: 1.15em;
  padding: 0.08rem 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  vertical-align: middle;
}

.restock-status {
  font-size: 0.85rem;
  font-weight: 600;
}

.restock-status-pending {
  color: var(--muted);
}

.restock-status-approved {
  color: var(--accent);
}

.restock-status-rejected {
  color: var(--danger);
}

.restock-status-fulfilled {
  color: var(--success);
}

.restock-req-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: min(640px, 96vw);
}

.restock-req-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.restock-req-dialog-inner {
  padding: 1.25rem 1.35rem;
}

.restock-req-dialog--qty {
  max-width: min(820px, 98vw);
}

.solicitacao-itens-dialog.restock-req-dialog {
  max-width: min(720px, 96vw);
}

.solicitacao-itens-dialog .solicitacao-itens-table-wrap {
  max-height: min(55vh, 420px);
  overflow: auto;
}

.solicitacao-reject-dialog .field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.solicitacao-reject-textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  min-height: 5rem;
}

.restock-req-dialog-inner h2 {
  font-size: 1.15rem;
  margin: 0 0 0.35rem;
}

.restock-req-qty-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0 1rem;
  font-size: 0.9rem;
}

.restock-req-qty-table th,
.restock-req-qty-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.restock-req-qty-table input[type="number"] {
  width: 100%;
  max-width: 110px;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.restock-req-qty-table .restock-req-stock-input {
  max-width: 100px;
}

h1 {
  font-size: 1.65rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
}

.sub {
  color: var(--muted);
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
}

.card .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card .value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

.card.warning .value {
  color: var(--warning);
}

.relatorios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  align-items: stretch;
}

.relatorio-card {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.relatorio-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}

.relatorio-card .badge-soon {
  margin-top: auto;
  align-self: flex-start;
}

.comparativo-table {
  width: 100%;
  min-width: 520px;
}

.comparativo-melhor {
  background: color-mix(in srgb, var(--success) 14%, transparent);
}

.comparativo-melhor .comparativo-preco {
  font-weight: 700;
}

.comparativo-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: var(--success);
  color: #fff;
}

.comparativo-selecionado-pedido {
  background: color-mix(in srgb, var(--warning) 32%, transparent);
}

.comparativo-selecionado-pedido .comparativo-preco {
  font-weight: 600;
}

.comparativo-badge--selecionado {
  background: var(--warning);
  color: #1a1408;
}

.comparativo-badge--apos-melhor {
  margin-left: 0.35rem;
}

.badge-soon {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  background: var(--surface-hover);
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #0a0e12;
}

.btn-primary:hover {
  background: var(--accent-dim);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  filter: brightness(1.08);
  color: #fff;
  text-decoration: none;
}

.btn-success {
  background: var(--success);
  color: #0a0e12;
  border: 1px solid var(--success);
}

.btn-success:hover {
  filter: brightness(1.06);
  color: #0a0e12;
  text-decoration: none;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.users-actions-col {
  white-space: nowrap;
}

.users-delete-form {
  display: inline-block;
  margin: 0 0 0 0.35rem;
  vertical-align: middle;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

/* Página de produtos: pesquisa + tabela */
.items-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1.15rem;
}

.items-toolbar .items-search-group {
  flex: 1 1 240px;
  min-width: min(100%, 200px);
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.items-toolbar .items-search-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.items-search-input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.35;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.items-search-input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.items-search-input:hover {
  border-color: var(--surface-hover);
}

.items-search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.items-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.items-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.items-table-scroll table {
  border: none;
  border-radius: 0;
  background: transparent;
}

.items-table-scroll tr.items-row-hidden {
  display: none;
}

.items-filter-empty {
  display: none;
  margin-top: 0.75rem;
  padding: 1.1rem 1rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.items-filter-empty.is-visible {
  display: block;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.2);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--surface-hover);
}

.low {
  color: var(--warning);
  font-weight: 600;
}

.ok {
  color: var(--success);
}

.flash {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash.success {
  background: rgba(62, 207, 142, 0.15);
  border: 1px solid var(--success);
  color: var(--success);
}

.flash.error {
  background: rgba(232, 93, 93, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
}

form.stacked label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

form.stacked .field {
  margin-bottom: 1rem;
}

form.stacked input,
form.stacked select,
form.stacked textarea {
  width: 100%;
  max-width: 420px;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

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

form.stacked input:focus,
form.stacked select:focus,
form.stacked textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.dispatch-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-bottom: 1.25rem;
}

.dispatch-block h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

.dispatch-block pre {
  margin: 0.75rem 0;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.dispatch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.empty {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.checkbox-cell {
  width: 2.5rem;
}

.restock-section-title,
.restock-manual-col-label,
.restock-manual-filter label {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}

.restock-section-title {
  margin: 1.5rem 0 0.5rem;
}

.restock-section-title--viewer {
  margin: 1.25rem 0 0.5rem;
}

.restock-section-rule {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0 0;
  padding: 0;
  height: 0;
}

.restock-section-rule + .restock-section-title {
  margin-top: 1rem;
}

.restock-manual-panel {
  max-width: 920px;
}

.restock-manual-filter {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  margin-bottom: 2rem;
}

.restock-manual-filter label {
  display: block;
  margin: 0;
}

.restock-manual-filter input {
  width: 100%;
  max-width: none;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  box-sizing: border-box;
}

.restock-manual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto minmax(260px, min(40vh, 360px));
  gap: 2rem 1rem;
  align-items: stretch;
  grid-template-areas:
    "lb1 lb2"
    "list1 list2";
}

.restock-manual-area-lb1 {
  grid-area: lb1;
}

.restock-manual-area-lb2 {
  grid-area: lb2;
}

.restock-manual-area-list1 {
  grid-area: list1;
  min-height: 0;
}

.restock-manual-area-list2 {
  grid-area: list2;
  min-height: 0;
}

.restock-manual-col-label {
  display: block;
  margin: 0;
  text-align: center;
}

@media (max-width: 720px) {
  .restock-manual-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(200px, 280px) auto minmax(200px, 280px);
    grid-template-areas:
      "lb1"
      "list1"
      "lb2"
      "list2";
  }
}

.restock-pick-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.restock-pick-item {
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: left;
  width: 100%;
  box-sizing: border-box;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  border-left: 0;
  border-right: 0;
  border-top: 0;
}

.restock-pick-item:last-child {
  border-bottom: 0;
}

.restock-pick-item:hover {
  background: var(--surface-hover);
}

.restock-pick-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.restock-pick-item .meta {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.restock-pick-item.user-org-locked {
  cursor: default;
  opacity: 0.95;
}

.restock-pick-item.user-org-locked .meta {
  font-style: italic;
}

.restock-pick-empty {
  padding: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

@media (max-width: 640px) {
  table {
    font-size: 0.85rem;
  }

  th,
  td {
    padding: 0.5rem;
  }

  .items-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .items-toolbar .items-search-group {
    max-width: none;
  }

  .items-toolbar-actions {
    justify-content: flex-start;
  }
}
