:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --ink: #23201d;
  --muted: #857c72;
  --line: #e6e0d7;
  --terracotta: #c8613b;
  --teal: #2a9d8f;
  --rust: #a3352a;
  --amber: #e9a23b;
  --shadow: 0 1px 3px rgba(40,30,20,.08), 0 8px 24px rgba(40,30,20,.05);
  --radius: 14px;
}
* { box-sizing: border-box; }
/* Ensure hidden elements are always hidden, even when an author rule sets a
   display value (e.g. .login-wrap uses display:grid, which would otherwise
   override the [hidden] attribute and keep the login screen visible). */
[hidden] { display: none !important; }
body {
  margin: 0; font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: #efe9df; padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 50% -10%, #f7d9b8 0%, var(--bg) 60%);
}
.login-card {
  background: var(--panel); width: 100%; max-width: 400px; padding: 32px;
  border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand h1 { font-size: 19px; font-weight: 800; }
/* Centered logo layout on the sign-in card */
.brand-login { flex-direction: column; text-align: center; gap: 6px; margin-bottom: 28px; }
.brand-login h1 { font-size: 21px; }
.brand-login .muted { margin: 0; }
.brand-logo {
  width: 92px; height: 92px; border-radius: 20px; margin-bottom: 8px;
  box-shadow: var(--shadow); object-fit: cover;
}
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, var(--terracotta), var(--rust));
  color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 18px;
}
.brand-mark.small { width: 34px; height: 34px; font-size: 14px; border-radius: 9px; }
.brand-mark-img { width: 36px; height: 36px; border-radius: 9px; object-fit: cover; flex: none; }
#login-form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
input {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; background: #fbfaf7;
}
input:focus { outline: 2px solid var(--terracotta); border-color: transparent; }
button {
  cursor: pointer; font-family: inherit; font-weight: 600; border: none; border-radius: 10px;
}
#login-btn {
  padding: 12px; background: var(--terracotta); color: #fff; font-size: 15px; margin-top: 4px;
}
#login-btn:hover { background: #b5542f; }
#login-btn:disabled { opacity: .6; cursor: default; }
.error { color: var(--rust); font-size: 13px; margin: 0; font-weight: 600; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fbfaf7;
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.ghost {
  padding: 8px 12px; background: transparent; border: 1px solid var(--line);
  color: var(--ink); font-size: 13px;
}
.ghost:hover { background: #f0ebe3; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 22px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 61px; z-index: 15;
}
.tab {
  background: transparent; border: none; padding: 13px 18px; font-size: 14px;
  font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  border-radius: 0; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--terracotta); border-bottom-color: var(--terracotta); }

/* ---------- stock page ---------- */
.stock-head { flex-wrap: wrap; gap: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters .select { min-width: 130px; }
#stock-search { min-width: 210px; }
.status-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.status-badge.reorder { background: #fdeceb; color: var(--rust); }
.status-badge.low { background: #fff5e6; color: #b5771a; }
.status-badge.ok { background: #e7f5f1; color: #1f7a6e; }
.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable:hover { color: var(--ink); }
.sort-arrow { opacity: .5; font-size: 10px; }
.stock-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.stock-tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; padding: 9px 10px; border-bottom: 2px solid var(--line);
  position: sticky; top: 0; background: var(--panel);
}
.stock-tbl td { padding: 10px; border-bottom: 1px solid #f2ede5; }
.stock-tbl tr:hover td { background: #faf7f2; }
.stock-tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.stock-empty { padding: 30px; text-align: center; color: var(--muted); }
.qbar { height: 5px; border-radius: 3px; background: #eee5da; margin-top: 4px; overflow: hidden; }
.qbar > span { display: block; height: 100%; border-radius: 3px; }

/* ---------- content ---------- */
.content { max-width: 1180px; margin: 0 auto; padding: 22px; }
.loading {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 14px; color: var(--muted); font-size: 14px;
}
.spinner {
  width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--terracotta);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi-value { font-size: 27px; font-weight: 800; margin: 4px 0 2px; }
.kpi-warn { border-color: var(--amber); background: linear-gradient(180deg, #fff8ee, #fff); }
.kpi-warn .kpi-value { color: var(--rust); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; font-weight: 700; }
.panel-body { padding: 16px 18px; }
.pill {
  background: var(--rust); color: #fff; font-weight: 700; font-size: 12px;
  padding: 2px 10px; border-radius: 999px; min-width: 24px; text-align: center;
}
.alert-panel { border-left: 4px solid var(--amber); }
.alert-panel.ok { border-left-color: var(--teal); }
.alert-panel.ok .pill { background: var(--teal); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-box { position: relative; height: 240px; margin-bottom: 12px; }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 8px; border-bottom: 1px solid #f2ede5; vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.danger { color: var(--rust); font-weight: 700; }
.mini-head { margin: 4px 0 6px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; }

/* ---------- activity ---------- */
.activity { display: flex; flex-direction: column; }
.act-row { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid #f2ede5; }
.act-row:last-child { border-bottom: none; }
.act-badge {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center;
  font-weight: 800; color: #fff; font-size: 16px;
}
.act-badge.add { background: var(--teal); }
.act-badge.remove { background: var(--rust); }
.act-badge.set { background: var(--terracotta); }
.act-main { flex: 1; min-width: 0; }
.act-time { flex: none; white-space: nowrap; }
.tag { background: #efe9df; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }

.foot { text-align: center; padding: 8px 0 20px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
