/* ERP Industrial — design system (nível SaaS) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --z-sidebar: 40;
  --z-overlay: 30;
  --z-header: 20;

  --bg-root: #0c0e12;
  --bg-subtle: #11141a;
  --bg-surface: #161a22;
  --bg-elevated: #1c212b;
  --bg-input: #0f1218;
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;

  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-muted: rgba(99, 102, 241, 0.15);
  --primary-glow: rgba(99, 102, 241, 0.35);

  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.12);
  --danger: #f43f5e;
  --danger-muted: rgba(244, 63, 94, 0.12);
  --warning: #eab308;
  --warning-muted: rgba(234, 179, 8, 0.12);
  --info: #38bdf8;
  --info-muted: rgba(56, 189, 248, 0.12);

  --sidebar-w: 268px;
  --header-h: 64px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.4);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg-root);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--primary-muted);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ——— App shell ——— */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #12151c 0%, #0e1016 100%);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar__logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  box-shadow: 0 4px 14px var(--primary-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.sidebar__titles {
  min-width: 0;
}

.sidebar__name {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}

.sidebar__tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar__scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.6rem 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.85rem 0.75rem 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.15s var(--ease);
  border: 1px solid transparent;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-item.is-active {
  background: var(--primary-muted);
  color: #e0e7ff;
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.08);
}

.nav-item.is-active .nav-icon-svg {
  color: var(--primary-hover);
  opacity: 1;
}

.nav-item.disabled {
  color: var(--text-muted);
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.nav-icon-svg {
  flex-shrink: 0;
  opacity: 0.85;
  color: var(--text-secondary);
}

.sidebar__footer {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Main content */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.08), transparent 50%),
    var(--bg-root);
}

.main-inner {
  flex: 1;
  padding: 0 1.75rem 2.5rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  margin-bottom: 0.25rem;
  backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(12, 14, 18, 0.92) 0%, rgba(12, 14, 18, 0.75) 100%);
  border-bottom: 1px solid transparent;
}

.topbar__titles h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.topbar__subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.65rem 0.35rem 0.35rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.user-chip__avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary-muted), rgba(139, 92, 246, 0.2));
  color: #c7d2fe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.user-chip__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-right: 0.35rem;
}

.user-chip__login {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip__role {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Cards & surfaces */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-sm);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.card__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card__desc {
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.grid-cards > .card {
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}

.grid-cards > .card:hover {
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  transform: translateY(-2px);
}

.card h3.card__title {
  margin-top: 0;
}

.kpi-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  background: linear-gradient(145deg, var(--bg-elevated) 0%, var(--bg-surface) 100%);
  border: 1px solid var(--border);
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle at top right, var(--primary-glow), transparent 70%);
  opacity: 0.5;
  pointer-events: none;
}

.stat {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  position: relative;
  z-index: 1;
}

.stat--danger {
  color: #fb7185;
}
.stat--success {
  color: #4ade80;
}
.stat--accent {
  color: #a5b4fc;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  font-weight: 500;
  position: relative;
  z-index: 1;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.page-actions .muted {
  flex: 1;
  min-width: 200px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.data-table thead th {
  text-align: left;
  padding: 0.85rem 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border);
}

table.data-table tbody td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

table.data-table tbody tr {
  transition: background 0.12s var(--ease);
}

table.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.12s var(--ease),
    box-shadow 0.15s var(--ease);
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary:disabled {
  filter: grayscale(0.3);
}

.btn-primary {
  border: none;
  background: linear-gradient(135deg, #6366f1 0%, #7c3aed 100%);
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn-sm {
  padding: 0.38rem 0.75rem;
  font-size: 0.8125rem;
}

/* Forms */
label.form-label,
.form-label {
  display: block;
  margin-top: 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

label.form-label:first-child,
.form-label:first-child {
  margin-top: 0;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input:hover,
select:hover,
textarea:hover {
  border-color: rgba(148, 163, 184, 0.28);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

input[type='file'] {
  padding: 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
}

code {
  font-family: ui-monospace, 'Cascadia Code', monospace;
  font-size: 0.85em;
  padding: 0.12rem 0.35rem;
  border-radius: var(--radius-sm);
  background: var(--bg-root);
  border: 1px solid var(--border);
  color: #c4b5fd;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

/* Alerts */
.alert {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
}

.alert-error {
  background: var(--danger-muted);
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.25);
}

.alert-success {
  background: var(--success-muted);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.25);
}

.alert-info {
  background: var(--info-muted);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.25);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge--success {
  background: var(--success-muted);
  border-color: rgba(34, 197, 94, 0.3);
  color: #86efac;
}

.badge--danger {
  background: var(--danger-muted);
  border-color: rgba(244, 63, 94, 0.3);
  color: #fda4af;
}

.badge--warn {
  background: var(--warning-muted);
  color: #fde047;
}

.muted {
  color: var(--text-muted);
}

/* JSON audit snippet */
code.json-snippet {
  display: block;
  white-space: pre-wrap;
  font-size: 0.72rem;
  font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  background: var(--bg-root);
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 140px;
  overflow: auto;
  color: var(--text-secondary);
}

/* ——— Auth / SaaS login ——— */
.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr minmax(420px, 480px);
}

@media (max-width: 960px) {
  .auth-page {
    grid-template-columns: 1fr;
  }
}

.auth-hero {
  position: relative;
  padding: 3rem 3.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  background: linear-gradient(145deg, #0f172a 0%, #1e1b4b 42%, #312e81 100%);
}

.auth-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 120% 80% at 20% 20%, rgba(99, 102, 241, 0.35), transparent 50%),
    radial-gradient(ellipse 80% 60% at 80% 80%, rgba(168, 85, 247, 0.2), transparent 45%);
  pointer-events: none;
}

.auth-hero__content {
  position: relative;
  z-index: 1;
  max-width: 420px;
}

.auth-hero__logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  margin-bottom: 1.75rem;
}

.auth-hero h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.65rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  line-height: 1.2;
}

.auth-hero p {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(224, 231, 255, 0.82);
  line-height: 1.65;
}

.auth-hero__stats {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-top: 2.5rem;
}

.auth-stat {
  min-width: 100px;
}

.auth-stat strong {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.auth-stat span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(224, 231, 255, 0.55);
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 2rem;
  background: var(--bg-root);
  border-left: 1px solid var(--border);
}

@media (max-width: 960px) {
  .auth-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .auth-hero {
    padding: 2rem 1.75rem;
    min-height: auto;
  }
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2rem 2rem 2.25rem;
  box-shadow: var(--shadow-lg);
}

.auth-card__head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-card__head p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-footnote {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

@media (max-width: 1024px) {
  .sidebar-toggle {
    display: inline-flex;
  }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .main-wrap {
    margin-left: 0;
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.is-visible {
    display: block;
  }
}

@media (max-width: 640px) {
  .main-inner {
    padding: 0 1rem 2rem;
  }
  .topbar {
    flex-wrap: wrap;
  }
  .user-chip__meta {
    display: none;
  }
}

/* Installer (optional body.theme-install overrides) */
.theme-install body {
  background: var(--bg-root);
}

.min-w-0 {
  min-width: 0;
}

/* ——— Instalador web ——— */
.install-layout {
  min-height: 100vh;
  padding: 2rem 1.25rem 3rem;
  background: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.12), transparent 50%), var(--bg-root);
}

.install-wrap {
  max-width: 720px;
  margin: 0 auto;
}

.install-head h1 {
  margin: 0 0 0.35rem;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.install-head p {
  margin: 0 0 1.75rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 520px;
}

.install-steps {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.install-steps span {
  padding: 0.38rem 0.8rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.install-steps span.is-current {
  background: var(--primary-muted);
  border-color: rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
}

.install-steps span.is-done {
  opacity: 0.45;
}

.install-h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.install-checks {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
}

.install-checks li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.install-checks li:last-child {
  border-bottom: none;
}

.text-ok {
  color: #86efac;
}

.text-bad {
  color: #fda4af;
}

.install-form .form-label:first-child,
.install-form label.form-label:first-child {
  margin-top: 0;
}

.install-form button[type='submit'] {
  margin-top: 1.35rem;
}

a.install-link {
  color: #a5b4fc;
  text-decoration: none;
  font-weight: 500;
}

a.install-link:hover {
  text-decoration: underline;
}

.empty-state-card {
  text-align: center;
  padding: 2.5rem 2rem !important;
  max-width: 440px;
  margin: 2rem auto;
}

.empty-state-icon {
  color: var(--primary-hover);
  margin: 0 auto 1rem;
  display: block;
  opacity: 0.9;
}

.empty-state-text {
  margin: 0.75rem 0 1.35rem;
  line-height: 1.55;
}
