/* ============================================================
   KFER — Componentes: navbar, sidebar, botões, forms, badges,
   tabelas, modais, toasts, etc.
   ============================================================ */

/* ─────────────── navbar / sidebar ─────────────── */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  position: relative;
}
.app-main { grid-column: 2; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface-1);
  backdrop-filter: blur(var(--blur-2)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur-2)) saturate(180%);
  border-right: 1px solid var(--border-1);
  padding: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  overflow-y: auto;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  margin-bottom: var(--s-4);
  border-radius: var(--r-lg);
  background: var(--surface-0);
  border: 1px solid var(--border-1);
}

.brand-mark {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.brand-mark img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  /* A logo KFER é preta no fundo; em nav escuro a gente inverte */
  filter: brightness(0) invert(1);
}
/* fallback se não tiver imagem: letra "K" estilizada */
.brand-mark-fallback {
  width: 38px; height: 38px;
  border-radius: var(--r-md);
  background: var(--grad-primary);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  color: white;
  font-size: 18px;
  box-shadow: var(--shadow-glow);
  position: relative;
}
.brand-mark-fallback::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,.4), transparent 50%);
  pointer-events: none;
}

/* Versão maior da logo (landing, telas amplas) */
.brand-mark-lg {
  height: 56px;
  display: inline-flex; align-items: center;
}
.brand-mark-lg img {
  height: 100%;
  width: auto;
  display: block;
  filter: drop-shadow(0 4px 20px rgba(139, 92, 246, 0.4)) brightness(0) invert(1);
}

.brand-text { line-height: 1.1; }
.brand-text .t1 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-100);
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-text .t2 {
  color: var(--text-40);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 2px;
}

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

.nav-group-title {
  padding: var(--s-3) var(--s-3) var(--s-2);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-20);
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 10px var(--s-3);
  border-radius: var(--r-md);
  color: var(--text-60);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: all var(--t-fast);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  position: relative;
}
.nav-item .icon {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.85;
}
.nav-item:hover {
  background: var(--surface-1);
  color: var(--text-100);
  border-color: var(--border-0);
}
.nav-item.active {
  background: var(--surface-2);
  color: var(--text-100);
  border-color: var(--border-1);
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.2) inset;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -5px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--grad-primary);
  border-radius: var(--r-full);
}

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

.user-card {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-0);
  border: 1px solid var(--border-0);
  margin-bottom: var(--s-2);
}
.user-avatar {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: var(--grad-cool);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 13px;
  flex-shrink: 0;
}
.user-meta { line-height: 1.2; min-width: 0; flex: 1; }
.user-meta .name { color: var(--text-100); font-size: var(--fs-sm); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta .role { color: var(--text-40); font-size: 11px; }

/* ─────────────── topbar ─────────────── */

.topbar {
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 0 var(--s-6);
  background: var(--surface-1);
  backdrop-filter: blur(var(--blur-2));
  -webkit-backdrop-filter: blur(var(--blur-2));
  border-bottom: 1px solid var(--border-1);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text-100);
  font-size: var(--fs-md);
}

.topbar-spacer { flex: 1; }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search input {
  width: 280px;
  padding: 8px 14px 8px 36px;
  background: var(--surface-0);
  border: 1px solid var(--border-0);
  border-radius: var(--r-full);
  color: var(--text-100);
  font-size: var(--fs-sm);
  outline: none;
  transition: all var(--t-fast);
}
.search input::placeholder { color: var(--text-20); }
.search input:focus {
  border-color: var(--primary);
  background: var(--surface-1);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
.search .search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-40);
  pointer-events: none;
}

/* ─────────────── main ─────────────── */

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  flex: 1;
}
.app-content { flex: 1; min-width: 0; width: 100%; }

/* ─────────────── buttons ─────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: all var(--t-fast);
  background: var(--surface-1);
  color: var(--text-100);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5; cursor: not-allowed; pointer-events: none;
}
.btn:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
.btn .icon { width: 16px; height: 16px; }

.btn-primary {
  background: var(--grad-primary);
  color: white;
  border-color: transparent;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 8px 24px rgba(139, 92, 246, 0.35);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 12px 32px rgba(139, 92, 246, 0.45);
}

.btn-ghost {
  background: var(--surface-0);
  border-color: var(--border-1);
  color: var(--text-80);
}
.btn-ghost:hover {
  background: var(--surface-1);
  border-color: var(--border-2);
  color: var(--text-100);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  box-shadow: 0 8px 22px rgba(16, 185, 129, 0.3);
}
.btn-success:hover { transform: translateY(-1px); }

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #1a0e00;
  font-weight: 700;
}
.btn-warning:hover { transform: translateY(-1px); }

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  box-shadow: 0 8px 22px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover { transform: translateY(-1px); }

.btn-sm { padding: 6px 12px; font-size: var(--fs-xs); }
.btn-lg { padding: 14px 24px; font-size: var(--fs-md); }
.btn-icon { padding: 8px; }
.btn-block { width: 100%; }

.btn-link {
  background: transparent;
  color: var(--accent-2);
  padding: 4px 6px;
  font-weight: 600;
  border: none;
}
.btn-link:hover { color: var(--text-100); background: transparent; }

/* ─────────────── forms ─────────────── */

.form-group { margin-bottom: var(--s-4); }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-60);
  margin-bottom: 6px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="url"],
input[type="search"], input[type="date"], input[type="datetime-local"],
textarea, select {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-0);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  color: var(--text-100);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  outline: none;
  transition: all var(--t-fast);
}
input::placeholder, textarea::placeholder { color: var(--text-20); }
input:focus, textarea:focus, select:focus {
  background: var(--surface-1);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}
input[readonly], textarea[readonly] { opacity: 0.7; cursor: default; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-opacity='0.5' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

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

.input-help {
  font-size: var(--fs-xs);
  color: var(--text-40);
  margin-top: 6px;
}

.input-error { color: var(--danger); font-size: var(--fs-xs); margin-top: 6px; }

/* ─────────────── badges ─────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid var(--border-1);
  background: var(--surface-1);
  color: var(--text-80);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
  flex-shrink: 0;
}
.badge-success { color: #34d399; background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.25); }
.badge-warning { color: #fbbf24; background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.25); }
.badge-danger  { color: #f87171; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.25); }
.badge-info    { color: #60a5fa; background: rgba(59, 130, 246, 0.12); border-color: rgba(59, 130, 246, 0.25); }
.badge-primary { color: #10b981; background: rgba(16, 185, 129, 0.15); border-color: rgba(16, 185, 129, 0.30); }
.badge-neutral { color: var(--text-60); background: var(--surface-1); }

/* ─────────────── table ─────────────── */

.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  overflow: hidden;
  backdrop-filter: blur(var(--blur-2));
  -webkit-backdrop-filter: blur(var(--blur-2));
}
.table-scroll { overflow-x: auto; }

table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
table.t thead th {
  text-align: left;
  padding: 14px 18px;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-40);
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border-1);
  white-space: nowrap;
}
table.t tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-0);
  color: var(--text-80);
  vertical-align: middle;
}
table.t tbody tr:last-child td { border-bottom: none; }
table.t tbody tr {
  transition: background var(--t-fast);
}
table.t tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

.table-empty {
  padding: var(--s-12) var(--s-6);
  text-align: center;
  color: var(--text-40);
}
.table-empty .icon { font-size: 40px; margin-bottom: var(--s-3); opacity: 0.5; }

/* ─────────────── stat card ─────────────── */

.stat-card {
  padding: var(--s-5);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  backdrop-filter: blur(var(--blur-2)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur-2)) saturate(180%);
  position: relative;
  overflow: hidden;
  transition: transform var(--t-base), border-color var(--t-base);
}
.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-2);
}
.stat-card::before { display: none; }
.stat-card .stat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-3);
}
.stat-card .stat-label {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-40);
  font-weight: 600;
}
.stat-card .stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-color, var(--primary));
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: var(--fs-4xl);
  font-weight: 700;
  color: var(--text-100);
  line-height: 1;
  letter-spacing: -0.02em;
}
.stat-card .stat-foot {
  margin-top: var(--s-3);
  font-size: var(--fs-xs);
  color: var(--text-40);
  display: flex; align-items: center; gap: 6px;
}
.stat-card .stat-foot .delta {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-weight: 600;
}
.delta-up { color: #34d399; background: rgba(16, 185, 129, 0.12); }
.delta-down { color: #f87171; background: rgba(239, 68, 68, 0.12); }
.delta-flat { color: var(--text-60); background: var(--surface-1); }

/* ─────────────── alerts / toasts ─────────────── */

.flash-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: var(--s-2);
  max-width: 360px;
}
.flash {
  padding: 14px 18px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  backdrop-filter: blur(var(--blur-3));
  -webkit-backdrop-filter: blur(var(--blur-3));
  border: 1px solid var(--border-2);
  color: var(--text-100);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-md);
  animation: slide-in 0.3s var(--ease);
  display: flex; align-items: center; gap: var(--s-3);
}
.flash-success { border-color: rgba(16, 185, 129, 0.4); }
.flash-success::before { content: "✓"; color: #34d399; font-weight: 700; }
.flash-danger { border-color: rgba(239, 68, 68, 0.4); }
.flash-danger::before { content: "✕"; color: #f87171; font-weight: 700; }
.flash-warning { border-color: rgba(245, 158, 11, 0.4); }
.flash-warning::before { content: "⚠"; color: #fbbf24; font-weight: 700; }
.flash-info { border-color: rgba(59, 130, 246, 0.4); }
.flash-info::before { content: "i"; color: #60a5fa; font-weight: 700; }

@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ─────────────── modal ─────────────── */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(7, 9, 26, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--s-4);
}
.modal-backdrop.open { display: flex; animation: fade-in 0.2s var(--ease); }
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-1);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: scale-in 0.2s var(--ease);
}
.modal-header {
  padding: var(--s-5);
  border-bottom: 1px solid var(--border-1);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; }
.modal-close {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  color: var(--text-60);
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text-100); }
.modal-body { padding: var(--s-5); }
.modal-footer {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border-1);
  display: flex; justify-content: flex-end; gap: var(--s-2);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

/* ─────────────── misc ─────────────── */

.divider {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-1), transparent);
  margin: var(--s-6) 0;
}

.kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-xs);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-60);
}

.code-block {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: var(--s-4);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-80);
  overflow-x: auto;
  white-space: pre;
}

.empty-state {
  padding: var(--s-12) var(--s-6);
  text-align: center;
  color: var(--text-40);
}
.empty-state .icon { font-size: 56px; opacity: 0.4; margin-bottom: var(--s-4); }
.empty-state h4 { color: var(--text-80); margin-bottom: var(--s-2); }

/* ─────────────── loading / skeleton ─────────────── */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-1) 0%,
    var(--surface-2) 50%,
    var(--surface-1) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shine 1.4s linear infinite;
  border-radius: var(--r-md);
}
@keyframes skeleton-shine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border-1);
  border-top-color: var(--primary);
  border-radius: var(--r-full);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─────────────── mobile ─────────────── */

.mobile-only { display: none; }
@media (max-width: 960px) {
  :root { --sidebar-w: 0px; }
  .sidebar { position: fixed; left: -100%; width: 264px; transition: left 0.3s var(--ease); }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  .container { padding: 0 var(--s-4); }
  .page { padding: var(--s-5) 0; }
  .page-header { flex-direction: column; align-items: flex-start; }
  h1 { font-size: var(--fs-3xl); }
  .stat-card .stat-value { font-size: var(--fs-3xl); }
  .topbar { padding: 0 var(--s-4); }
  .search input { width: 160px; }
}

.menu-toggle {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  color: var(--text-80);
  width: 38px; height: 38px;
  border-radius: var(--r-md);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.menu-toggle:hover { color: var(--text-100); }

/* ───── grids responsivos específicos ───── */
.grid-charts { grid-template-columns: 2fr 1fr; }
.grid-lists { grid-template-columns: 1fr 1fr; }
@media (max-width: 960px) {
  .grid-charts, .grid-lists { grid-template-columns: 1fr; }
}
