:root {
  --green: #1f8a4c;
  --green-dark: #166a39;
  --green-light: #e6f4ea;
  --red: #d64545;
  --orange: #e08a1e;
  --bg: #f4f6f5;
  --text: #1c2b22;
  --muted: #6b7a72;
  --card: #ffffff;
  --border: #dde4e0;
  --radius: 12px;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--green);
  color: #fff;
  font-weight: 600;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--green-dark); }
button:active { transform: scale(.98); }
button.secondary { background: #eef2f0; color: var(--text); }
button.secondary:hover { background: #dfe6e2; }
button.danger { background: var(--red); }
button.danger:hover { background: #b83636; }
button.small { padding: 6px 10px; font-size: .85rem; }
button.big { width: 100%; padding: 14px; font-size: 1.05rem; }

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
input:focus, select:focus {
  outline: 2px solid var(--green);
  border-color: transparent;
}

label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin: 12px 0 4px;
  color: var(--muted);
}

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: linear-gradient(135deg, var(--green) 0%, #0f4d29 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  padding: 32px 28px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.login-card .logo {
  font-size: 2.6rem;
  text-align: center;
}
.login-card h1 {
  text-align: center;
  font-size: 1.5rem;
  margin: 6px 0 2px;
}
.login-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 18px;
}
.pw-row { position: relative; }
.pw-row button {
  position: absolute;
  right: 4px;
  top: 4px;
  padding: 6px 10px;
  font-size: .8rem;
}
.error {
  background: #fdeaea;
  color: var(--red);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: .9rem;
  margin-top: 14px;
  display: none;
}
.hint {
  margin-top: 18px;
  padding: 10px 12px;
  background: var(--green-light);
  border-radius: 8px;
  font-size: .82rem;
  color: var(--green-dark);
}
.login-card button[type=submit] { margin-top: 20px; }

/* ---------- App layout (dark sidebar) ---------- */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  width: 264px;
  background: #0b0f0d;
  color: #e8efe9;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  overflow-y: auto;
  z-index: 40;
  border-right: 1px solid #18211c;
}
.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 18px;
  border-bottom: 1px solid #1a241e;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  flex: none;
}
.brand-text { font-weight: 700; line-height: 1.15; }
.brand-text small {
  display: block;
  font-weight: 500;
  font-size: .7rem;
  color: #7f8e85;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-top: 2px;
}

.owner { text-align: center; padding: 22px 6px 20px; }
.avatar {
  position: relative;
  width: 96px; height: 96px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #18211c;
  border: 3px solid var(--green);
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: #cfe9d8;
  font-size: 2.2rem;
  font-weight: 700;
}
.avatar:hover { background: #18211c; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-edit {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 5px 0 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity .15s;
}
.avatar:hover .avatar-edit, .avatar:focus-visible .avatar-edit { opacity: 1; }
.owner-name { margin-top: 12px; font-weight: 700; font-size: 1.05rem; word-break: break-word; }
.owner-role { color: #7f8e85; font-size: .8rem; margin-top: 2px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: transparent;
  color: #9aa8a0;
  border-radius: 10px;
  text-align: left;
  font-weight: 500;
}
.side-nav button:hover { background: #151c18; color: #fff; }
.side-nav button.active { background: #14261c; color: #fff; }
.side-nav button.active::before {
  content: "";
  position: absolute;
  left: -16px; top: 9px; bottom: 9px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: #2ecc71;
}
.side-nav button.active svg { color: #2ecc71; }
.side-nav svg, .logout svg, .menu-btn svg {
  width: 20px; height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.side-foot { padding-top: 14px; border-top: 1px solid #1a241e; margin-top: 14px; }
.logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: transparent;
  border: 1px solid #2a352e;
  color: #e8efe9;
}
.logout:hover { background: var(--red); border-color: var(--red); }

.content { margin-left: 264px; min-width: 0; }
.mobilebar { display: none; }
.scrim { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
section.page { display: none; }
section.page.active { display: block; }

h2 { font-size: 1.25rem; margin-bottom: 14px; }
h3 { font-size: 1rem; margin-bottom: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; }
.stat.warn .value { color: var(--orange); }
.stat.bad .value { color: var(--red); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge.ok { background: var(--green-light); color: var(--green-dark); }
.badge.low { background: #fff1de; color: var(--orange); }
.badge.out { background: #fdeaea; color: var(--red); }
.badge.cash { background: var(--green-light); color: var(--green-dark); }
.badge.utang { background: #fff1de; color: var(--orange); }

.empty { color: var(--muted); text-align: center; padding: 20px; font-size: .9rem; }

/* ---------- POS ---------- */
.pos {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  align-items: start;
}
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 12px;
  max-height: 520px;
  overflow-y: auto;
  padding: 2px;
}
.product-tile {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  text-align: left;
  padding: 12px;
  border-radius: 10px;
  font-weight: 400;
}
.product-tile:hover { border-color: var(--green); background: var(--green-light); }
.product-tile .name { font-weight: 600; font-size: .92rem; }
.product-tile .price { color: var(--green-dark); font-weight: 700; margin-top: 4px; }
.product-tile .stock { color: var(--muted); font-size: .78rem; }
.product-tile:disabled { opacity: .45; cursor: not-allowed; }

.cart-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item .info { flex: 1; }
.cart-item .info .n { font-weight: 600; font-size: .92rem; }
.cart-item .info .p { color: var(--muted); font-size: .8rem; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { padding: 2px 10px; background: #eef2f0; color: var(--text); }
.qty span { min-width: 20px; text-align: center; font-weight: 600; }
.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: 1.3rem;
  font-weight: 700;
  margin: 14px 0 4px;
}
.change-line {
  display: flex;
  justify-content: space-between;
  color: var(--green-dark);
  font-weight: 600;
  margin: 8px 0;
}

.form-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}
.form-row.two { grid-template-columns: 2fr auto; }
.form-row.settings { grid-template-columns: 1fr 2fr auto auto; }
.stat.good .value { color: var(--green); }
.note { color: var(--muted); font-size: .85rem; margin-bottom: 10px; }
.form-row + .note { margin: -6px 0 0; }
td.actions { white-space: nowrap; }
td.actions button { margin-left: 4px; }
.form-row label { margin-top: 0; }

.scroll { max-height: 440px; overflow-y: auto; }
.cust-card { margin-bottom: 14px; }
.cust-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.cust-head .name { font-size: 1.05rem; font-weight: 700; }
.cust-head .bal { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.cust-head .bal strong { font-size: 1.2rem; }
.cust-actions { display: flex; gap: 6px; }
td.neg { color: var(--green-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1c2b22;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  opacity: 0;
  transition: all .25s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .pos, .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr 1fr; }
  .form-row.two { grid-template-columns: 1fr; }
  .form-row.settings { grid-template-columns: 1fr; }
}

/* ---------- Sales history ---------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-head h2 { margin: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stat .value.sm { font-size: 1.15rem; margin-top: 10px; }


details.month {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
details.month summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  flex-wrap: wrap;
}
details.month summary::-webkit-details-marker { display: none; }
details.month summary:hover { background: #f8faf9; }
.mlabel { font-weight: 700; display: flex; align-items: center; gap: 10px; }
.msum { color: var(--muted); font-size: .88rem; }
.chev {
  width: 8px; height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .15s;
  flex: none;
}
details[open] > summary .chev { transform: rotate(45deg); }
.month-body { padding: 0 18px 14px; border-top: 1px solid var(--border); }

/* ---------- Small screens: sidebar slides in ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .content { margin-left: 0; }
  .mobilebar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 20;
    background: #0b0f0d;
    color: #fff;
    padding: 10px 14px;
    font-weight: 700;
  }
  .mobilebar button { background: #18211c; padding: 8px 10px; display: flex; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }
}

/* ---------- Bar chart with numbers ---------- */
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.chart-head h3 { margin: 0; }
.inline-select { width: auto; padding: 6px 10px; }
.chart { padding: 26px 0 0 52px; }
.chart-plot { position: relative; height: 220px; }
.gridline { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed #d9e1dc; }
.gridline span { position: absolute; left: -52px; width: 46px; text-align: right; top: -8px; font-size: .7rem; color: var(--muted); }
.bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 8px; }
.chart .col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.chart .val { flex: none; font-size: .68rem; font-weight: 700; color: var(--text); margin-bottom: 3px; white-space: nowrap; }
.chart .bar { flex: none; width: 100%; max-width: 46px; background: #3aa66a; border-radius: 6px 6px 0 0; }
.chart .col.current .bar { background: var(--green-dark); }
.chart-labels { display: flex; gap: 8px; margin-top: 8px; }
.chart-labels .lbl { flex: 1; text-align: center; font-size: .75rem; color: var(--muted); }
.chart-labels .lbl.current { color: var(--text); font-weight: 700; }

/* ---------- Settings ---------- */
.form-row.profile { grid-template-columns: 2fr 2fr 1fr auto; }
.photo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.side-nav button.push { margin-top: auto; }

@media (max-width: 760px) {
  .form-row.profile { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .chart { padding-left: 40px; }
  .gridline span { left: -40px; width: 34px; }
  .chart .val { font-size: .6rem; }
  .bars, .chart-labels { gap: 3px; }
}

/* ---------- Loading screen, errors, welcome ---------- */
.loading-screen {
  position: fixed; inset: 0;
  background: #0b0f0d; color: #cfe9d8;
  display: grid; place-items: center;
  z-index: 100;
  font-weight: 600; letter-spacing: .02em;
}
.loading-screen.hide { display: none; }
.fatal {
  position: fixed; inset: 0;
  background: rgba(11,15,13,.97); color: #fff;
  display: grid; place-items: center;
  z-index: 110; padding: 24px; text-align: center;
}
.fatal[hidden] { display: none; }
.fatal-box { max-width: 440px; }
.fatal-box h2 { margin-bottom: 8px; }
.fatal-box p { color: #cfd8d2; line-height: 1.5; }
.fatal-box .btn-row { justify-content: center; margin-top: 18px; }
.welcome { border-left: 4px solid var(--green); margin-bottom: 16px; }
