/* ============================================================
   Esavi — Painel de monitoramento de estoque
   Temas: claro (padrão) e escuro via [data-theme="dark"]
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  /* base clara */
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #dde3ec;
  --ink: #141b26;
  --ink-soft: #5a6577;
  --ink-faint: #8b95a7;

  /* marca e estados */
  --brand: #3d5af1;
  --brand-ink: #ffffff;
  --ok: #1f9e5f;
  --warn: #d98a06;
  --warn-bg: #fdf3e0;
  --danger: #d43a42;
  --danger-bg: #fbe9ea;
  --ok-bg: #e4f5ec;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);

  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="dark"] {
  --bg: #0d1220;
  --surface: #161d2f;
  --surface-2: #1c2439;
  --border: #28324c;
  --ink: #e8ecf4;
  --ink-soft: #9aa5bd;
  --ink-faint: #66718c;

  --brand: #6c83ff;
  --brand-ink: #0d1220;
  --ok: #3ecf8e;
  --warn: #f5b040;
  --warn-bg: #33280f;
  --danger: #ff6b72;
  --danger-bg: #3a1b1e;
  --ok-bg: #12301f;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.55;
  transition: background .25s, color .25s;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }

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

/* Espaço reservado para a futura logo do sistema */
.logo-slot {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px; border-bottom: 1px solid var(--border);
}
.logo-slot .logo-img {
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 17px;
}
.logo-slot .logo-img img { width: 100%; height: 100%; object-fit: contain; border-radius: 9px; }
.logo-slot .logo-name {
  font-family: var(--font-display); font-weight: 700; font-size: 16px; letter-spacing: .01em;
}
.logo-slot .logo-name span { color: var(--brand); }

.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin: 2px 0; border-radius: 8px;
  color: var(--ink-soft); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--brand); color: var(--brand-ink); }
.nav a .badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 20px; padding: 1px 7px;
}
.nav .nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint); padding: 14px 12px 4px;
}

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); font-size: 13px; }
.sidebar-footer .user-name { font-weight: 600; }
.sidebar-footer .user-role { color: var(--ink-faint); font-size: 12px; }
.sidebar-footer button {
  margin-top: 8px; width: 100%; background: none;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; color: var(--ink-soft);
}
.sidebar-footer button:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- Menu minimizável ---------- */
.sidebar { transition: width .18s ease; }
.nav-toggle {
  position: absolute; top: 24px; right: -12px; z-index: 6;
  width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-soft); font-size: 11px; line-height: 1;
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.nav-toggle:hover { color: var(--brand); border-color: var(--brand); }
.nav a { position: relative; }
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .logo-name,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .user-name,
.sidebar.collapsed .user-role { display: none; }
.sidebar.collapsed .logo-slot { justify-content: center; padding: 18px 8px; }
.sidebar.collapsed .nav a { justify-content: center; padding: 10px 8px; }
.sidebar.collapsed .nav a .badge {
  position: absolute; top: 3px; right: 6px; margin: 0;
  font-size: 10px; padding: 0 5px;
}
.sidebar.collapsed .sidebar-footer { padding: 10px 8px; }
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ---------- Faixa do modo teste (entrar como outro usuário) ---------- */
.impersonation-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 28px; font-size: 13px;
  background: var(--warn-bg); color: var(--warn);
  border-bottom: 1px solid var(--border);
}
.impersonation-bar .btn { flex-shrink: 0; }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-family: var(--font-display); font-size: 19px; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle, .icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; width: 36px; height: 36px;
  display: grid; place-items: center; font-size: 16px; color: var(--ink);
  position: relative;
}
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger);
}

.content { padding: 24px 28px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------- Componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 18px;
}
.card h2 { font-family: var(--font-display); font-size: 15px; font-weight: 700; margin-bottom: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 500; }
.stat .stat-value {
  font-family: var(--font-mono); font-weight: 700; font-size: 28px; margin-top: 2px;
}
.stat.warn .stat-value { color: var(--warn); }
.stat.danger .stat-value { color: var(--danger); }
.stat.ok .stat-value { color: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* quantidades de estoque — assinatura visual do sistema */
.qty {
  font-family: var(--font-mono); font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.qty::before { content: ''; width: 8px; height: 8px; border-radius: 50%; }
.qty.ok::before { background: var(--ok); }
.qty.warn::before { background: var(--warn); }
.qty.danger::before { background: var(--danger); }
.qty.none { color: var(--ink-faint); }
.qty.none::before { background: var(--ink-faint); }

.pill {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px;
}
.pill.ok     { background: var(--ok-bg); color: var(--ok); }
.pill.warn   { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill.muted  { background: var(--surface-2); color: var(--ink-soft); }

.mono { font-family: var(--font-mono); font-size: 12.5px; }
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; }

/* ---------- Botões e formulários ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); border-radius: 8px; padding: 8px 14px;
  font-weight: 600; font-size: 13.5px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger-outline { color: var(--danger); }
.btn.danger-outline:hover { border-color: var(--danger); background: var(--danger-bg); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
input, select {
  width: 100%; padding: 9px 12px; font: inherit;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 24, .55);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 24px;
}
.modal h2 { font-family: var(--font-display); font-size: 17px; margin-bottom: 16px; }

/* ---------- Alertas / toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand);
  border-radius: 10px; box-shadow: var(--shadow); padding: 12px 16px;
  max-width: 380px; font-size: 13.5px; animation: slideIn .2s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.notif-item {
  display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--surface-2); border-radius: 8px; padding: 12px; }
.notif-icon { font-size: 18px; }

/* ---------- Login ---------- */
.login-wrap {
  width: 100%; flex: 1;
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(1000px 500px at 85% -10%, color-mix(in srgb, var(--brand) 14%, transparent), transparent),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 32px;
}
.login-card .logo-slot { border: none; padding: 0 0 20px; }
.login-card h1 { font-family: var(--font-display); font-size: 20px; margin-bottom: 4px; }
.login-card p { color: var(--ink-soft); font-size: 13px; margin-bottom: 20px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; padding: 11px; }

.empty { text-align: center; color: var(--ink-faint); padding: 32px 10px; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button {
  background: none; border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 14px; color: var(--ink-soft); font-weight: 600; font-size: 13px;
}
.tabs button.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }

.log-filters {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border);
}
.log-filters > div { min-width: 170px; }
.log-filters .btn { margin-bottom: 1px; }
.flex-between h2 { margin-bottom: 0; }

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  #app { flex-direction: column; }
  .sidebar, .sidebar.collapsed { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .nav-toggle { display: none; }
  .sidebar.collapsed .nav-label, .sidebar.collapsed .logo-name,
  .sidebar.collapsed .user-name, .sidebar.collapsed .user-role { display: block; }
  .impersonation-bar { padding: 9px 16px; flex-wrap: wrap; }
  .nav { display: flex; padding: 6px; }
  .nav .nav-section { display: none; }
  .sidebar-footer { border: none; white-space: nowrap; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
