/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #141414;
  --surface:   #1f1f1f;
  --surface2:  #2a2a2a;
  --surface3:  #333;
  --border:    #3a3a3a;
  --text:      #e5e5e5;
  --text-2:    #a3a3a3;
  --text-3:    #6b6b6b;
  --accent:    #6366f1;
  --accent-h:  #4f46e5;
  --green:     #22c55e;
  --red:       #ef4444;
  --red-bg:    #2c1515;
  --radius:    8px;
  --radius-sm: 5px;
  --shadow:    0 4px 16px rgba(0,0,0,.35);
}
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; }
input { font-family: inherit; font-size: inherit; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.hidden { display: none !important; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

/* ── Main ── */
.main { flex: 1; padding: 2rem; display: flex; flex-direction: column; gap: 1.25rem; overflow-x: auto; }

/* ── Page Header ── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.page-header h1 { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.page-subtitle { color: var(--text-2); font-size: 0.85rem; margin-top: 0.2rem; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.user-email { font-size: 0.8rem; color: var(--text-3); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Login (Magic Link) ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-card { max-width: 400px; width: 100%; padding: 2rem; }
.login-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.35rem; }
.login-subtitle { color: var(--text-2); font-size: 0.9rem; margin-bottom: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.btn-primary:disabled { opacity: .65; cursor: not-allowed; }
.login-hint {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.85rem; color: var(--green); margin-top: 0.75rem;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
/* ── Table ── */
#tableWrap { position: relative; }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 0.6rem 1rem;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-3);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
th.num, td.num { text-align: right; }
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody tr.editing { background: rgba(99,102,241,.06); }
td { padding: 0.65rem 1rem; color: var(--text); vertical-align: middle; }
td .qty-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--surface3);
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 600;
}
td .qty-badge.low { background: rgba(239,68,68,.15); color: #fca5a5; }
td .price { font-variant-numeric: tabular-nums; }
td .stock-val { color: var(--text-2); font-size: 0.85rem; }
td .date { color: var(--text-3); font-size: 0.8rem; }
td input[type="text"], td input[type="number"] {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
td input:focus { border-color: var(--accent); }

/* ── Actions ── */
.actions { display: flex; gap: 0.4rem; align-items: center; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background .12s, color .12s, border-color .12s;
}
.btn-icon:hover { background: var(--surface3); color: var(--text); }
.btn-icon.danger { color: #f87171; border-color: transparent; }
.btn-icon.danger:hover { background: var(--red-bg); border-color: #7f1d1d; }
.btn-icon.confirm-del { background: var(--red-bg); border-color: var(--red); color: #fca5a5; }
.btn-icon.confirm-del:hover { background: #3f1818; }
.btn-text {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.82rem;
  transition: background .12s, color .12s;
}
.btn-text:hover { background: var(--surface3); color: var(--text); }
.btn-text.save { border-color: var(--accent); color: var(--accent); }
.btn-text.save:hover { background: rgba(99,102,241,.12); }

/* ── Empty & Loading ── */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.empty-icon { font-size: 2.5rem; }
.loading-state {
  padding: 3rem 1rem;
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  color: var(--text-3);
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ── */
.btn-primary {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  transition: background .15s, opacity .15s;
  border: none;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { opacity: .85; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem;
  background: var(--surface3);
  color: var(--text-2);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  transition: background .15s;
}
.btn-secondary:hover { background: var(--surface2); color: var(--text); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-header h2 { font-size: 1rem; font-weight: 700; }
.modal-form { display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.82rem; color: var(--text-2); font-weight: 500; }
.field input {
  padding: 0.6rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.field input::placeholder { color: var(--text-3); }
.field input:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-top: 0.25rem; }
.btn-danger {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1rem;
  background: none;
  color: #f87171;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.85rem;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.btn-danger:hover { background: var(--red-bg); border-color: #7f1d1d; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  padding: 0.65rem 1rem;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: 280px;
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast.success { border-color: #166534; background: #052e16; color: #86efac; }
.toast.error   { border-color: #7f1d1d; background: #2c0f0f; color: #fca5a5; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .main { padding: 1rem; }
  .field-row { grid-template-columns: 1fr; }
  thead th.date, td.date-col { display: none; }
}
