:root {
  --bg: #0f1117;
  --bg-alt: #161925;
  --card: #1b1f2e;
  --card-hover: #212739;
  --border: #2a2f42;
  --text: #eef0f6;
  --text-dim: #9aa1b8;
  --primary: #6d5efc;
  --primary-hover: #5a4be0;
  --primary-soft: rgba(109, 94, 252, 0.12);
  --success: #2ecc8f;
  --success-soft: rgba(46, 204, 143, 0.12);
  --danger: #ff5d7a;
  --danger-soft: rgba(255, 93, 122, 0.12);
  --warn: #ffb547;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Layout do app (dashboard) ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav a:hover { background: var(--card); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: #cabeff; }

.nav .icon { width: 18px; height: 18px; display:inline-flex; align-items:center; justify-content:center; }
.icon svg, .tab-btn svg, .product-row-title svg, .func-icon svg, .empty-state .icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.empty-state .icon svg { width: 34px; height: 34px; }
.func-icon { display:inline-flex; align-items:center; justify-content:center; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: #cabeff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.user-meta { min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.logout-link {
  display: block;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 8px;
}
.logout-link:hover { color: var(--danger); }

.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1160px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.page-subtitle { color: var(--text-dim); font-size: 14px; margin: 0; }

/* ---------- Botões ---------- */

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: #3a4058; }
.btn-danger-ghost { background: var(--danger-soft); color: #ff8fa4; border: 1px solid transparent; }
.btn-danger-ghost:hover { background: rgba(255, 93, 122, 0.2); }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cards / Tabelas ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.015);
}
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.015); }

.mono { font-family: "SF Mono", "JetBrains Mono", Menlo, monospace; font-size: 12.5px; color: var(--text-dim); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-success .badge-dot { background: var(--success); }
.badge-warn { background: rgba(255,181,71,0.12); color: var(--warn); }
.badge-warn .badge-dot { background: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-danger .badge-dot { background: var(--danger); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.field input, .field select, .field textarea {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.password-wrap { position: relative; display: flex; align-items: center; }
.password-wrap input { width: 100%; padding-right: 74px; }
.password-toggle {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  border: 1px solid var(--border); background: rgba(255,255,255,0.04); color: var(--text-dim);
  border-radius: 7px; padding: 5px 8px; font-family: inherit; font-size: 12px; font-weight: 700;
  cursor: pointer;
}
.password-toggle:hover { color: var(--text); border-color: #3a4058; }
.field-hint { font-size: 12px; color: var(--text-dim); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* ---------- Toggle switch ---------- */

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #383e56; border-radius: 999px; transition: background 0.2s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(8, 9, 14, 0.6);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 460px; padding: 24px; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal p.modal-sub { margin: 0 0 18px; color: var(--text-dim); font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Toast ---------- */

.toast-stack {
  position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200;
}
.toast {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; font-size: 13.5px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px; min-width: 240px;
  animation: toast-in 0.2s ease-out;
}
.toast.success { border-color: rgba(46,204,143,0.4); }
.toast.error { border-color: rgba(255,93,122,0.4); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Grid de funções ---------- */

.func-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.func-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.func-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.func-icon {
  width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 17px; background: var(--primary-soft); flex-shrink: 0;
}
.func-title { font-size: 14.5px; font-weight: 700; margin: 0 0 3px; }
.func-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; margin: 0; }
.func-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 4px; }
.func-tag { font-size: 11px; color: var(--text-dim); font-family: "SF Mono", Menlo, monospace; }

/* ---------- Utilities ---------- */

.stack-h { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }
.text-dim { color: var(--text-dim); }
.mt-24 { margin-top: 24px; }
