@import url("tokens.css");

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, .brand h1, .topbar h2, .modal-header h3 {
  font-family: var(--font-display);
  font-weight: 600;
}

button, input, select, textarea, .btn, label {
  font-family: var(--font-body);
}

.hidden { display: none !important; }

/* Auth legado (portal / modais) — login split em auth.css */

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}

.auth-card-wide {
  max-width: 480px;
}

.portal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.modal-dialog-sm {
  max-width: 420px;
}

.field-hint {
  font-size: 0.78rem;
  color: var(--gray);
}

.credentials-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--accent-soft);
  border-radius: 10px;
  margin: 12px 0 4px;
}

.credentials-box div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.credentials-box span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.credentials-box strong {
  font-size: 0.95rem;
  word-break: break-all;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--white);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.brand-icon.sm {
  width: 36px;
  height: 36px;
  font-size: 0.75rem;
}

.brand h1 {
  font-size: 1.5rem;
  line-height: 1.2;
}

.brand p,
.auth-footer {
  color: var(--gray);
  font-size: 0.9rem;
}

.auth-footer {
  margin-top: 20px;
  text-align: center;
}

/* Layout app */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--sidebar-text-active);
}

.sidebar-brand span {
  color: var(--sidebar-text);
  font-size: 0.75rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  border-left: 3px solid transparent;
}

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

.nav-item:hover:not(.disabled) {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-text-active);
}

.nav-item.active {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
  border-left-color: var(--sidebar-accent-bar);
}

.nav-item.active .nav-icon {
  opacity: 1;
  color: var(--accent);
}

.nav-item.disabled {
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.topbar h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.topbar p {
  color: var(--gray);
  font-size: 0.9rem;
  margin-top: 4px;
}

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

.user-badge {
  background: var(--bg-muted);
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 500;
}

.content {
  padding: 20px 24px 32px;
}

/* Toolbar & card */
.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.search-box__icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 0.8125rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding-left: 2.1rem;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* Form */
.form,
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.field-full {
  grid-column: 1 / -1;
}

.logo-upload {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.logo-preview-wrap {
  width: 88px;
  height: 88px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--white);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.logo-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
}

.logo-placeholder {
  font-size: 0.72rem;
  color: var(--gray);
  text-align: center;
  padding: 8px;
  line-height: 1.35;
}

.logo-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.logo-file-btn {
  cursor: pointer;
  margin: 0;
}

.table-company {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  border: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}

.table-logo-empty {
  display: inline-grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: none;
}

.table-company strong {
  display: block;
}

.table-company small {
  color: var(--gray);
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-hover);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn:active { opacity: 0.92; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

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

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

.btn-ghost:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-muted);
  color: var(--text);
}

/* Table */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f0f2f5;
  border-bottom: 1px solid var(--border-strong);
}

.table tbody tr:nth-child(even) {
  background: #fafbfc;
}

.table tbody tr:hover {
  background: #f5f7fa;
}

.table td small {
  display: block;
  color: var(--gray);
  font-size: 0.82rem;
  margin-top: 2px;
}

.table .empty {
  text-align: center;
  color: var(--gray);
  padding: 40px;
}

.table .empty.error {
  color: var(--danger);
}

.table .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-success {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-muted {
  background: #F3F4F6;
  color: var(--gray);
}

.badge-erp {
  background: #EFF6FF;
  color: #1D4ED8;
}

.badge-tenant {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-family: ui-monospace, monospace;
  font-size: 0.72rem;
}

/* Alert */
.alert {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.45);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: auto;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 0 24px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin: 20px 0 16px;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--gray);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.auth-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.auth-footer--muted {
  font-size: 0.85rem;
}

.erp-test-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.alert-success {
  background: rgba(47, 143, 47, 0.08);
  color: #1e6b1e;
  border: 1px solid rgba(47, 143, 47, 0.25);
}

.form-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0 12px;
}

.tab-hint {
  color: var(--gray);
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.45;
}

/* Responsive */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    padding: 20px;
  }

  .content {
    padding: 20px;
  }
}
