:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --bg: #f4f5f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

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

/* ---------- Navbar ---------- */

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 2rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand .logo-dot {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.9rem;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover { color: var(--text); background: var(--bg); }
.nav-links a.active { color: var(--primary); background: var(--primary-light); }

/* ---------- Layout ---------- */

.container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 2rem 0 0.85rem;
  color: var(--text);
}
p.subtitle { color: var(--muted); margin: 0.2rem 0 0; font-size: 0.92rem; }

/* ---------- Flash messages ---------- */

.flash {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-light); color: #166534; border-color: #bbf7d0; }
.flash-danger { background: var(--danger-light); color: #991b1b; border-color: #fecaca; }

/* ---------- Stat cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}

.card .label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card .value {
  font-size: 1.6rem;
  font-weight: 800;
  margin-top: 0.35rem;
  letter-spacing: -0.02em;
}
.card .value.profit { color: var(--success); }
.card .value.warn { color: var(--danger); }

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  background: #fafafb;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafafe; }
tr.low-stock td { background: var(--danger-light); }
tr.low-stock:hover td { background: #fde8e8; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 0.4rem;
}
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-success { background: #dcfce7; color: #166534; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  border: none;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f9fafb; }

/* ---------- Toolbar / filters ---------- */

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar select {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.88rem;
}

/* ---------- Forms ---------- */

form.card { max-width: 560px; }

.form-row { margin-bottom: 1.05rem; }
.form-row label {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}
.form-row input, .form-row select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-row input:focus, .form-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.form-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ---------- Sale line builder ---------- */

.sale-line {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.6rem;
  align-items: end;
  margin-bottom: 0.75rem;
  padding: 0.85rem;
  background: #fafafb;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sale-line label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  display: block;
  margin-bottom: 0.25rem;
}
.sale-line select,
.sale-line input {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  background: white;
  color: var(--text);
  height: 2.6rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sale-line select:focus,
.sale-line input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.sale-line .remove-line {
  height: 2.6rem;
  width: 2.6rem;
  padding: 0;
  justify-content: center;
}

/* ---------- Misc ---------- */

.muted { color: var(--muted); font-size: 0.85rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

/* ---------- Item images ---------- */

.item-name-cell {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.thumb {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.thumb-placeholder {
  background: var(--bg);
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.image-preview img {
  width: 4rem;
  height: 4rem;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}
.checkbox-row input { width: auto; }

/* ---------- New sale (POS-style picker) ---------- */

.pos-layout {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 860px) {
  .pos-layout { grid-template-columns: 1fr; }
}

.product-search {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  margin-bottom: 1rem;
  background: white;
}
.product-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.product-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.4rem;
  padding: 0.85rem 0.6rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, transform 0.05s, box-shadow 0.15s;
}
.product-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}
.product-card:active { transform: scale(0.97); }

.product-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
}

.product-card-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.6rem;
}

.product-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.25;
}

.product-card-stock {
  font-size: 0.75rem;
  color: var(--muted);
}

.cart-card {
  max-width: none;
  position: sticky;
  top: 5.5rem;
}

.cart-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.6rem;
  background: #fafafb;
}
.cart-line-info { flex: 1; min-width: 0; }

.cart-line-amount {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 3.5rem;
  text-align: right;
}

.cart-summary {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  padding: 0.3rem 0;
  color: var(--muted);
}

.cart-total-row-final {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  padding-top: 0.5rem;
  margin-top: 0.3rem;
  border-top: 1px dashed var(--border);
}

.cart-discount-input {
  width: 6.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: right;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
/* ---------- Reports ---------- */

.report-filter {
  align-items: flex-end;
  gap: 0.75rem;
}

.filter-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
}

.report-filter input[type="date"] {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
}

.quick-ranges {
  display: flex;
  gap: 0.4rem;
  margin-left: 0.25rem;
}
.quick-ranges a {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
}
.quick-ranges a:hover { border-color: var(--primary); color: var(--primary); }

.chart-card {
  padding: 1.25rem 1rem 0.75rem;
}

.chart-legend {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 0.5rem;
  padding-left: 0.5rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}
.legend-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  display: inline-block;
}

#trend-chart {
  width: 100%;
  height: 220px;
  display: block;
}

/* ---------- Settings / danger zone ---------- */

.danger-zone {
  max-width: 480px;
  border-color: #fecaca;
}
.danger-zone h3 { color: var(--danger); font-size: 1rem; }
.danger-zone code {
  background: var(--danger-light);
  color: var(--danger);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 700;
}

.login-brand .logo-dot {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.cart-line-info { min-width: 0; }
.cart-line-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-unit {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  background: white;
}

.cart-qty {
  width: 4.2rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}
