/* =====================================================================
   Sistema de Estoque & Compras — Design System
   ===================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e5e9f0;
  --border-strong: #d5dbe6;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef2ff;
  --ok: #059669;
  --danger: #e11d48;
  --warn: #d97706;
  --sidebar-bg: #111827;
  --sidebar-bg2: #1f2937;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
  --shadow-md: 0 4px 16px rgba(15,23,42,.08);
  --shadow-lg: 0 24px 60px rgba(15,23,42,.25);
}

/* ---------- TEMA ESCURO ---------- */
.theme-dark {
  --bg: #0b1120;
  --card: #151d2e;
  --border: #263248;
  --border-strong: #38455e;
  --text: #e7ecf3;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-soft: #1e1b4b;
  --sidebar-bg: #0a0f1c;
  --sidebar-bg2: #111827;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.6);
}
.theme-dark .table th { background: #1b2436; }
.theme-dark .table tbody tr:hover { background: #1b2436; }
.theme-dark .pedido-box { background: #1a2233; }
.theme-dark input, .theme-dark select, .theme-dark textarea { background: #0f1626; color: var(--text); }
.theme-dark input:disabled { background: #1b2436; }
.theme-dark input:focus, .theme-dark select:focus, .theme-dark textarea:focus { box-shadow: 0 0 0 3px rgba(99,102,241,.3); }
.theme-dark .modal-close:hover { background: #263248; color: var(--text); }
.theme-dark code { background: #1e1b4b; color: #c7d2fe; }
.theme-dark .row-alert { background: #3a1f2a !important; }
.theme-dark .toast-ok { background: #4f46e5; }
.theme-dark label { color: #cbd5e1; }

* { box-sizing: border-box; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .88rem; }
.error { color: var(--danger); }
.warning { color: var(--warn); }

/* ---------- LOGIN ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 20% -10%, #6366f1 0%, transparent 55%),
              radial-gradient(1000px 500px at 100% 100%, #0ea5e9 0%, transparent 50%),
              linear-gradient(135deg, #1e1b4b, #312e81);
  padding: 1rem;
}
.login-card {
  background: var(--card); padding: 2.6rem 2.4rem; border-radius: 18px;
  box-shadow: var(--shadow-lg); width: 100%; max-width: 400px;
  animation: pop .35s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.login-logo { width: 64px; height: 64px; display: block; margin: 0 auto 1.1rem; }
.login-card h1 { font-size: 1.5rem; font-weight: 800; margin: 0 0 .35rem; letter-spacing: -.02em; text-align: center; }
.login-card .login-sub { text-align: center; }
.login-sub { color: var(--muted); margin: 0 0 1.6rem; font-size: .92rem; }
#submit-btn, .login-btn {
  width: 100%; padding: .8rem; margin-top: .8rem; border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--primary), #6366f1); color: #fff; font-size: 1rem;
  font-weight: 700; cursor: pointer; box-shadow: 0 4px 14px rgba(79,70,229,.4);
  transition: transform .1s, box-shadow .15s, filter .15s;
}
#submit-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,70,229,.5); filter: brightness(1.05); }
#submit-btn:disabled { opacity: .7; cursor: wait; }

/* ---------- LAYOUT APP ---------- */
.app-layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 248px; flex-shrink: 0; height: 100vh; color: #cbd5e1;
  background: linear-gradient(180deg, var(--sidebar-bg), #0b1220);
  display: flex; flex-direction: column; padding: 1.3rem 0;
  border-right: 1px solid rgba(255,255,255,.05);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 10px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.25); }
.brand {
  display: flex; align-items: center; gap: .6rem; color: #fff;
  font-weight: 700; padding: 0 1.3rem 1.1rem; font-size: 1.08rem; letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand .brand-logo {
  width: 52px; height: 52px; flex-shrink: 0; object-fit: cover;
  border-radius: 9px;
}
#nav-menu { flex: 1 1 auto; padding: 1rem .7rem; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  color: #94a3b8; text-decoration: none; padding: .62rem .8rem; font-size: .92rem; font-weight: 500;
  border-radius: 9px; transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.4); }
.nav-item.active svg { opacity: 1; }
.nav-item .nav-badge { margin-left: auto; font-size: .75rem; background: rgba(255,255,255,.15); padding: .1rem .4rem; border-radius: 99px; color: inherit; }
.nav-item.active .nav-badge { background: rgba(255,255,255,.25); }
.nav-section { padding: .7rem 1.2rem .2rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.45); font-weight: 700; }

.sidebar-footer {
  flex-shrink: 0; margin-top: auto; padding: .9rem 1rem 0; margin: auto .7rem 0;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip { display: flex; align-items: center; gap: .65rem; padding: .6rem .4rem; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem;
}
.user-meta { line-height: 1.25; min-width: 0; }
.user-meta strong { color: #fff; font-size: .88rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { color: #94a3b8; font-size: .76rem; }
.footer-btn {
  width: 100%; color: #cbd5e1; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: .55rem; font-size: .88rem;
  padding: .55rem .5rem; border-radius: 8px; font-weight: 500; font-family: inherit;
}
.footer-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
#logout-btn {
  width: 100%; margin-top: .1rem; color: #fca5a5; background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: .55rem; font-size: .88rem;
  padding: .55rem .5rem; border-radius: 8px; font-weight: 500; font-family: inherit;
}
#logout-btn:hover { background: rgba(239,68,68,.12); text-decoration: none; }

/* Botão flutuante de tema (tela de login) */
.theme-fab {
  position: fixed; top: 1.2rem; right: 1.2rem; z-index: 10;
  width: 42px; height: 42px; border-radius: 50%; cursor: pointer;
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.25); color: #fff;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px);
  transition: background .15s;
}
.theme-fab:hover { background: rgba(255,255,255,.28); }

.content { flex: 1; padding: 2rem 2.4rem; overflow-y: auto; height: 100vh; }
.view { max-width: 1040px; margin: 0 auto; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.page-header { margin-bottom: 1.5rem; }
.page-header h2 { margin: 0; font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.page-header .muted { margin: .25rem 0 0; }

/* ---------- CARDS ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.4rem 1.5rem; margin-bottom: 1.5rem; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; gap: 1rem; }
.card-head h3 { margin: 0; font-size: 1.08rem; font-weight: 700; }

/* ---------- FORMS ---------- */
label { display: block; margin-bottom: .9rem; font-size: .85rem; font-weight: 600; color: #334155; }
input, select, textarea {
  width: 100%; padding: .6rem .75rem; margin-top: .3rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: .95rem; font-family: inherit; color: var(--text); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
input[type="radio"]:focus, input[type="checkbox"]:focus, .cotacao-opt:focus-within { outline: none; box-shadow: none; }
input:disabled { background: #f8fafc; color: var(--muted); }

.inline-form { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.inline-form label { flex: 1; min-width: 160px; margin-bottom: 0; }
.inline-form button { flex-shrink: 0; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  background: var(--primary); color: #fff; border: none; padding: .62rem 1.15rem;
  border-radius: var(--radius-sm); font-size: .92rem; cursor: pointer; font-weight: 600;
  transition: background .15s, transform .05s, box-shadow .15s; box-shadow: 0 1px 2px rgba(79,70,229,.3);
}
.btn:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(79,70,229,.35); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn-ok { background: var(--ok); box-shadow: 0 1px 2px rgba(5,150,105,.3); }
.btn-ok:hover { background: #047857; box-shadow: 0 4px 12px rgba(5,150,105,.35); }
.btn-danger { background: var(--danger); box-shadow: 0 1px 2px rgba(225,29,72,.3); }
.btn-danger:hover { background: #be123c; box-shadow: 0 4px 12px rgba(225,29,72,.35); }
.btn-outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); box-shadow: none; }
.btn-outline:hover { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.25); }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: .88rem; padding: 0; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

.login-card .btn { width: 100%; margin-top: .6rem; padding: .7rem; font-size: .98rem; }

/* ---------- TABLES ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--border); }
.table th {
  color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em; background: #f8fafc;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f8fafc; }
.table tr:last-child td { border-bottom: none; }
.row-alert { background: #fff1f2 !important; }
.row-muted { opacity: .5; }

/* ---------- PEDIDOS ---------- */
.pedido-box {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem; background: #fbfcfe;
}
.pedido-box:hover { border-color: var(--border-strong); }
.pedido-top { margin-bottom: .5rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.pedido-itens { margin: .45rem 0; }
.actions { margin-top: .9rem; display: flex; gap: .7rem; }
.item-row { margin-bottom: .75rem; padding: .8rem; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.item-grid { display: grid; grid-template-columns: 1.8fr 1.4fr 90px 32px; gap: .6rem; align-items: end; }
.item-grid label { font-size: .8rem; color: var(--muted); margin-bottom: .15rem; display: block; }
.item-grid select, .item-grid input { margin-top: .15rem; width: 100%; }
.item-grid .remove-item { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: var(--danger); font-size: 1.3rem; line-height: 1; }
.item-grid .remove-item:hover { background: rgba(225,29,72,.1); }

/* ---------- BADGES ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .6rem;
  border-radius: 999px; font-size: .74rem; font-weight: 600; line-height: 1;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-solicitado { background: #eef2ff; color: #4338ca; }
.badge-em_cotacao { background: #fef3c7; color: #92400e; }
.badge-aguardando_diretoria { background: #ffedd5; color: #9a3412; }
.badge-aprovado { background: #dcfce7; color: #15803d; }
.badge-rejeitado { background: #ffe4e6; color: #be123c; }
.badge-pago { background: #cffafe; color: #0e7490; }
.badge-recebido { background: #dcfce7; color: #166534; }
.badge-conferido { background: #dbeafe; color: #1d4ed8; }
.badge-insert { background: #dcfce7; color: #166534; }
.badge-update { background: #fef3c7; color: #92400e; }
.badge-delete { background: #ffe4e6; color: #be123c; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 1.6rem; right: 1.6rem; padding: .85rem 1.25rem;
  border-radius: 10px; color: #fff; font-size: .9rem; font-weight: 500; opacity: 0;
  transform: translateY(12px); transition: all .25s; pointer-events: none; z-index: 2000;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: #0f172a; }
.toast-error { background: var(--danger); }

code { background: #eef2ff; color: #4338ca; padding: .12rem .4rem; border-radius: 5px; font-size: .85em; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 1500; padding: 1rem;
  animation: fade .15s ease;
}
.modal {
  background: var(--card); border-radius: 16px; padding: 1.6rem 1.7rem;
  width: 100%; max-width: 440px; box-shadow: var(--shadow-lg); animation: pop .2s ease;
}
.modal h3 { margin: 0 0 1.2rem; font-size: 1.2rem; font-weight: 700; }
.modal-wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-head h3 { margin: 0; }
.modal-close {
  background: none; border: none; font-size: 1.7rem; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 0 .3rem; border-radius: 8px;
}
.modal-close:hover { color: var(--text); background: #f1f5f9; }
.modal-body { max-height: 70vh; overflow-y: auto; }
.modal-form label { display: block; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 1.1rem; align-items: center; margin-top: 1.2rem; }

/* ---------- DASHBOARD ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1.1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem 1.3rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary);
}
.stat-card .num { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.stat-card .lbl { color: var(--muted); font-size: .82rem; margin-top: .25rem; font-weight: 500; }
.stat-card.clickable { cursor: pointer; transition: transform .12s, box-shadow .15s, border-color .15s; }
.stat-card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.stat-card.clickable::after {
  content: "›"; position: absolute; right: 1rem; top: .9rem; color: var(--muted);
  font-size: 1.3rem; line-height: 1; opacity: 0; transition: opacity .15s;
}
.stat-card.clickable:hover::after { opacity: .7; }

.filters { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1.1rem; }
.filters label { margin-bottom: 0; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 720px) {
  .sidebar { width: 68px; }
  .brand span, .nav-item span, .user-meta, #logout-btn span { display: none; }
  .nav-item { justify-content: center; padding: .7rem; }
  .content { padding: 1.2rem; }
}
