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

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #b45309;
  --primary-dark: #92400e;
  --primary-soft: #fef3c7;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== TOPBAR ===== */
.topbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  font-size: 28px;
  background: rgba(255,255,255,.15);
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
}
.brand h1 { font-size: 20px; font-weight: 700; }
.brand p { font-size: 13px; opacity: .85; }

.tabs { display: flex; gap: 6px; background: rgba(255,255,255,.12); padding: 5px; border-radius: 10px; }
.tab {
  border: none; background: transparent; color: #fff;
  padding: 8px 18px; border-radius: 7px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.tab:hover { background: rgba(255,255,255,.15); }
.tab.active { background: #fff; color: var(--primary-dark); }

/* ===== MAIN ===== */
main { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===== CARDS ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.cards-small { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card-label { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.card-value { font-size: 28px; font-weight: 700; }
.card-value.green { color: var(--green); }
.card-value.red { color: var(--red); }
.card-value.warn { color: var(--primary); }

/* ===== PANELS ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel h2 { font-size: 16px; color: var(--text); }

/* ===== TOOLBAR ===== */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.toolbar input[type=text], .toolbar select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--text);
}
.toolbar input[type=text] { flex: 1; min-width: 220px; }
.toolbar input:focus, .toolbar select:focus, .toolbar input[type=number]:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent;
}
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 10px 12px; background: var(--primary-soft);
  color: var(--primary-dark); font-size: 12px; text-transform: uppercase;
  letter-spacing: .5px; white-space: nowrap; border-bottom: 2px solid #fcd34d;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag-entrada { background: var(--green-soft); color: var(--green); }
.tag-saida { background: var(--red-soft); color: var(--red); }
.tag-baixo { background: var(--red-soft); color: var(--red); }
.tag-ok { background: var(--green-soft); color: var(--green); }

.qtd { font-weight: 700; }

.actions { display: flex; gap: 6px; flex-wrap: nowrap; }
.actions button, .row-actions button {
  border: 1px solid var(--border); background: #fff; border-radius: 7px;
  padding: 5px 10px; font-size: 12px; cursor: pointer; transition: all .15s;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  min-width: 30px;
}
.actions button:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.actions button.danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }

.count-info { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* ===== BUTTONS ===== */
.btn {
  border: none; border-radius: 8px; padding: 10px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: all .15s;
  touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary-dark); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); animation: pop .18s ease;
}
.modal-sm { max-width: 440px; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }
.modal-close {
  border: none; background: transparent; font-size: 24px; cursor: pointer;
  color: var(--muted); line-height: 1;
}
.modal-close:hover { color: var(--red); }
.modal form { padding: 20px; }
.modal form label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
.modal form input, .modal form select {
  width: 100%; margin-top: 6px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; color: var(--text);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.margem { color: var(--green); font-weight: 700; margin-left: 6px; font-size: 14px; }
.estoque-atual { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.form-error {
  background: var(--red-soft); color: var(--red); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; font-weight: 600; margin-top: 12px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.3); z-index: 100;
  transition: opacity .25s, transform .25s;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

.hidden { display: none !important; }

/* ===== LOGIN ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(135deg, #1f2937, #111827);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--surface); border-radius: 16px; padding: 34px 30px;
  width: 100%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.4);
  text-align: center;
}
.login-icon {
  font-size: 40px; width: 72px; height: 72px; margin: 0 auto 14px;
  background: var(--primary-soft); border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
}
.login-card h2 { font-size: 20px; color: var(--text); }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card form { text-align: left; }
.login-card form label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
.login-card form input {
  width: 100%; margin-top: 6px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 9px; font-size: 15px; background: #fff; color: var(--text);
}
.login-card form input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
#login-user[readonly] {
  background: var(--bg); color: var(--muted); cursor: default; font-weight: 600;
}
#login-user[readonly]:focus { outline: none; border-color: var(--border); }
.btn-login { width: 100%; padding: 12px; font-size: 15px; margin-top: 6px; }

.btn-logout {
  border: 1px solid rgba(255,255,255,.6); background: transparent; color: #fff;
  padding: 8px 14px; border-radius: 7px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; margin-left: 4px; touch-action: manipulation;
}
.btn-logout:hover { background: rgba(255,255,255,.18); }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .topbar-inner { flex-direction: column; align-items: flex-start; }
  .tabs { width: 100%; }
  .tab { flex: 1; text-align: center; padding: 10px 6px; }
  .card-value { font-size: 24px; }
  tbody td { padding: 12px 8px; }
  .actions { gap: 8px; }
  .actions button, .row-actions button {
    padding: 12px 16px; font-size: 16px; min-width: 44px; min-height: 44px;
    border-radius: 10px;
  }
}
