/* Layout shell — sidebar em árvore + dark mode */

:root {
  --sidebar-w: 4.5rem;
  --sidebar-w-expanded: 16.5rem;
  --header-h: 4rem;
  --tabs-h: 2.5rem;
  --accent: #0f766e;
  --surface: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
}

html.dark {
  --accent: #2dd4bf;
  --surface: #0b1220;
  --panel: #111827;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #94a3b8;
}

html, body {
  height: 100%;
}

body.app-shell {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: "Segoe UI", "IBM Plex Sans", system-ui, sans-serif;
}

.app-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.app-body {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* Barra de módulos (ícones → árvore) */
.module-rail {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  transition: width 200ms ease;
  overflow-x: hidden;
  overflow-y: auto;
}

.module-rail.is-expanded,
.module-rail:hover,
.module-rail.is-pinned {
  width: var(--sidebar-w-expanded);
}

.module-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.7rem 1rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  font: inherit;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.module-link:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--text);
}

.module-link.is-active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.module-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
}

.module-label {
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 150ms ease, transform 150ms ease;
  overflow: hidden;
  text-overflow: ellipsis;
}

.module-rail.is-expanded .module-label,
.module-rail:hover .module-label,
.module-rail.is-pinned .module-label {
  opacity: 1;
  transform: translateX(0);
}

.module-group.is-open > .module-toggle .module-chevron {
  transform: rotate(90deg);
}

.module-children {
  padding: 0.15rem 0 0.45rem;
}

.module-child {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 1rem 0.45rem 2.35rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
}

.module-child:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.module-child.is-active {
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.module-sublabel {
  padding: 0.55rem 1rem 0.2rem 2.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.module-child.is-nested {
  padding-left: 2.85rem;
}

/* Quando a barra está só com ícones, esconde os filhos */
.module-rail:not(:hover):not(.is-expanded):not(.is-pinned) .module-children {
  display: none !important;
}

.main-content {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 1.25rem 1.5rem 2rem;
}

.card-surface {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}

.btn-accent {
  background: #0f766e;
  color: #fff;
  border-radius: 0.5rem;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

html.dark .btn-accent {
  background: #0d9488;
  color: #042f2e;
}

.btn-accent:hover {
  filter: brightness(1.05);
}

.btn-ghost {
  border: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  border-radius: 0.5rem;
  padding: 0.45rem 0.8rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 0.5rem;
  padding: 0.55rem 0.75rem;
}

.form-field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.table-shell th {
  background: color-mix(in srgb, var(--accent) 6%, var(--panel));
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.table-shell td,
.table-shell th {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.table-shell tr:hover td {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.icon-btn.is-active {
  color: #fff;
  background: #0f766e;
  border-color: #0f766e;
  box-shadow: 0 0 0 2px color-mix(in srgb, #0f766e 25%, transparent);
}

html.dark .icon-btn.is-active {
  color: #042f2e;
  background: #2dd4bf;
  border-color: #2dd4bf;
  box-shadow: 0 0 0 2px color-mix(in srgb, #2dd4bf 30%, transparent);
}

.icon-btn.is-active svg {
  transform: rotate(-45deg);
}

.icon-btn svg {
  transition: transform 180ms ease;
}

#pin-modules.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
}

#pin-modules.icon-btn svg {
  width: 1rem;
  height: 1rem;
}

/* Códigos, números de pedido/orçamento e sequência de itens */
.code-cell {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.item-seq {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.875rem;
  font-weight: 600;
}

.doc-number {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.table-shell td.code-cell,
.table-shell th.code-cell {
  font-size: 0.9375rem;
}

body.app-shell input:not([type="password"]):not([type="email"]):not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="number"]):not([type="date"]):not([type="datetime-local"]):not([type="time"]):not([type="color"]):not([type="range"]):not([data-preserve-case]),
body.app-shell textarea:not([data-preserve-case]) {
  text-transform: uppercase;
}

/* Abas internas + uma janela no navegador */
html.erp-shell-host {
  overflow: hidden;
}

html.erp-shell-host body.app-shell {
  height: 100%;
  overflow: hidden;
}

html.erp-shell-host .app-body {
  height: calc(100vh - var(--header-h) - var(--tabs-h));
  min-height: 0;
}

html.erp-embed .app-header,
html.erp-embed .workspace-tabstrip,
html.erp-embed .module-rail,
html.erp-embed .erp-lock-overlay {
  display: none !important;
}

html.erp-embed .app-body {
  min-height: 100vh;
  height: auto;
}

.workspace-tabstrip {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
  height: var(--tabs-h);
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.workspace-tabs {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.workspace-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 16rem;
  padding: 0 0.55rem 0 0.75rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 0.4rem 0.4rem 0 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.workspace-tab:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.workspace-tab.is-active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: var(--border);
}

.workspace-tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.workspace-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.workspace-tab-close:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--text);
}

.workspace-new-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin: 0.25rem 0;
  padding: 0 0.7rem;
  border: 1px dashed var(--border);
  border-radius: 0.4rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.workspace-new-tab:hover,
.workspace-tabstrip.is-picking .workspace-new-tab {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.workspace-frames {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--surface);
}

.workspace-frames iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
}

.workspace-frames iframe.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

.workspace-toast {
  position: fixed;
  top: calc(var(--header-h) + var(--tabs-h) + 0.75rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(32rem, calc(100vw - 2rem));
  padding: 0.7rem 1rem;
  border-radius: 0.6rem;
  background: #0f766e;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25);
}

html.dark .workspace-toast {
  background: #0d9488;
  color: #042f2e;
}

.erp-lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: color-mix(in srgb, var(--surface) 88%, #0f172a);
}

.erp-lock-overlay[hidden] {
  display: none;
}

.erp-lock-card {
  max-width: 26rem;
  padding: 1.5rem 1.35rem;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--panel);
  text-align: center;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
}

.erp-lock-title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.erp-lock-text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.menu-toggle {
  display: none;
}

.module-rail-backdrop {
  display: none;
}

.pwa-install-card {
  margin-top: 1.25rem;
  padding: 1rem 1.1rem;
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  background: var(--panel);
  text-align: left;
}

.pwa-install-card p {
  margin: 0 0 0.65rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--muted);
}

.pwa-install-card p:last-child {
  margin-bottom: 0;
}

.pwa-install-card[hidden],
.pwa-install-card [hidden] {
  display: none !important;
}

/* Celular / PWA: menu em gaveta, áreas seguras, toque maior */
@media (max-width: 767.98px) {
  :root {
    --header-h: 3.5rem;
  }

  html, body {
    overflow-x: hidden;
  }

  body.app-shell {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .app-header {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--header-h) + env(safe-area-inset-top));
    gap: 0.35rem;
  }

  .menu-toggle {
    display: inline-flex;
    width: 2.75rem;
    height: 2.75rem;
    flex-shrink: 0;
  }

  .icon-btn {
    width: 2.75rem;
    height: 2.75rem;
  }

  .module-rail-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  .module-rail-backdrop.is-visible {
    opacity: 1;
    pointer-events: auto;
  }

  .module-rail {
    position: fixed;
    z-index: 60;
    top: 0;
    left: 0;
    height: 100dvh;
    width: min(20.5rem, 88vw) !important;
    max-width: 88vw;
    transform: translateX(-105%);
    transition: transform 200ms ease;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .module-rail.is-expanded,
  .module-rail:hover,
  .module-rail.is-pinned {
    width: min(20.5rem, 88vw) !important;
  }

  .module-rail.is-drawer-open {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(15, 23, 42, 0.28);
  }

  .module-rail .module-label,
  .module-rail.is-expanded .module-label,
  .module-rail:hover .module-label,
  .module-rail.is-pinned .module-label {
    opacity: 1;
    transform: none;
  }

  .module-rail:not(:hover):not(.is-expanded):not(.is-pinned) .module-children {
    display: block;
  }

  #pin-modules {
    display: none;
  }

  .module-rail .module-children {
    display: block;
  }

  .module-rail .module-children[hidden] {
    display: none !important;
  }

  .module-link,
  .module-child {
    min-height: 2.75rem;
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
  }

  .app-body {
    min-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top));
  }

  .main-content {
    padding: 0.85rem 0.85rem 1.5rem;
  }

  .workspace-tabstrip {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }

  .workspace-new-tab-label {
    display: none;
  }

  .workspace-tab {
    max-width: 9rem;
    font-size: 0.75rem;
  }

  html.erp-shell-host .app-body {
    height: calc(100dvh - var(--header-h) - var(--tabs-h) - env(safe-area-inset-top));
  }

  .btn-accent {
    min-height: 2.75rem;
    justify-content: center;
    padding: 0.7rem 1rem;
  }

  .form-field input,
  .form-field select,
  .form-field textarea {
    font-size: 16px;
    min-height: 2.75rem;
  }

  .table-shell {
    -webkit-overflow-scrolling: touch;
  }

  .table-shell td,
  .table-shell th {
    padding: 0.65rem 0.7rem;
  }

  .doc-number {
    font-size: 1.35rem;
  }
}

@media (display-mode: standalone) {
  .pwa-install-card {
    display: none !important;
  }
}

/* Árvore de estrutura (BOM) */
.estrutura-heading {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.estrutura-heading-code {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #0f766e;
  overflow-wrap: anywhere;
}

html.dark .estrutura-heading-code {
  color: #2dd4bf;
}

.estrutura-heading-name {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bom-tree-root {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.6rem;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.5rem;
  border-radius: 0.5rem;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--border));
}

.bom-tree-root .bom-codigo {
  flex-shrink: 0;
}

.bom-tree-root .bom-desc {
  flex: 1 1 12rem;
  min-width: 0;
}

.bom-root-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.bom-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.45rem 0.5rem;
  border-radius: 0.5rem;
}

.bom-row:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.bom-row-main {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  min-width: 0;
  padding-left: calc(var(--bom-nivel, 0) * 0.55rem);
}

.bom-branch {
  width: 1rem;
  flex-shrink: 0;
  text-align: center;
  color: #cbd5e1;
  user-select: none;
}

html.dark .bom-branch {
  color: #475569;
}

.bom-toggle,
.bom-leaf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  flex-shrink: 0;
  border-radius: 0.4rem;
}

.bom-toggle {
  border: 1px solid var(--border);
  background: #fffbeb;
  cursor: pointer;
}

html.dark .bom-toggle {
  background: color-mix(in srgb, #78350f 30%, var(--panel));
}

.bom-leaf {
  color: var(--muted);
}

.bom-row-text {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.15rem 0.5rem;
  min-width: 0;
}

.bom-codigo {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f766e;
  overflow-wrap: anywhere;
}

html.dark .bom-codigo {
  color: #2dd4bf;
}

.bom-desc {
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bom-desc.is-root {
  font-weight: 600;
}

.bom-row-meta {
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.bom-children {
  margin-left: 0.85rem;
  border-left: 1px solid var(--border);
}

.bom-alterar-desc {
  padding-left: calc((var(--bom-nivel, 0) + 1) * 0.45rem);
}

@media (min-width: 768px) {
  .bom-alterar-desc {
    padding-left: calc((var(--bom-nivel, 0) + 1) * 1rem);
  }
}

@media (max-width: 767.98px) {
  .estrutura-heading-name {
    font-size: 1.05rem;
  }

  .bom-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.15rem;
    align-items: start;
  }

  .bom-row-text {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
  }

  .bom-row-meta {
    white-space: normal;
    padding-left: 2.35rem;
  }

  .bom-tree-root .bom-desc {
    flex-basis: 100%;
  }

  .bom-tree-root .bom-root-badge {
    margin-left: 0;
  }

  .bom-children {
    margin-left: 0.55rem;
  }
}

@keyframes flash-red {
  0%, 100% {
    background-color: rgb(239 68 68);
    color: white;
    border-color: rgb(220 38 38);
  }
  50% {
    background-color: rgb(254 202 202);
    color: rgb(153 27 27);
    border-color: rgb(252 165 165);
  }
}

.animate-flash-red {
  animation: flash-red 1s infinite ease-in-out;
}




