/* ==========================================================================
   Maleektech Business System — stylesheet
   Brand tokens: primary green #0E7C3A, deep green #075C2A, tint #E7F4EA
   ========================================================================== */

:root {
  --primary: #0E7C3A;
  --primary-dark: #075C2A;
  --tint: #E7F4EA;
  --page: #F6F8F6;
  --white: #FFFFFF;
  --ink: #16221A;
  --ink-soft: #4C5A50;
  --border: #DCE6DF;
  --amber: #B8760A;
  --amber-bg: #FBF0DD;
  --amber-border: #EFD9AE;
  --red: #B3261E;
  --red-bg: #FBEAE9;
  --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  --radius: 8px;
  --sidebar-w: 216px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--page);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; }
a { color: var(--primary-dark); }

.hidden { display: none !important; }

/* ---------------------------------------------------------------------- */
/* Login screen                                                           */
/* ---------------------------------------------------------------------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
}
.login-mark {
  width: 160px; max-width: 60%; height: auto; object-fit: contain;
  display: block; margin-bottom: 16px;
}
.login-card h1 { font-size: 19px; margin: 0 0 2px; }
.login-card p.sub { font-size: 13px; color: var(--ink-soft); margin: 0 0 22px; }
.login-error {
  background: var(--red-bg); color: var(--red); border-radius: 6px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 14px; display: none;
}
.login-error.show { display: block; }
.login-footnote { font-size: 11.5px; color: var(--ink-soft); margin-top: 18px; line-height: 1.5; }

/* ---------------------------------------------------------------------- */
/* App shell                                                              */
/* ---------------------------------------------------------------------- */
#app-shell { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--primary-dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px 20px; }
.brand-mark {
  width: 34px; height: 34px; object-fit: contain; border-radius: 4px;
  background: var(--white); padding: 2px; flex-shrink: 0;
}
.brand-text { font-size: 13.5px; font-weight: 700; line-height: 1.25; }
.brand-text small { display: block; font-size: 10.5px; font-weight: 400; opacity: .75; }

nav.nav { display: flex; flex-direction: column; gap: 2px; }
nav.nav button {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px; border-radius: 6px; border: none;
  background: transparent; color: var(--white);
  font-size: 13.5px; font-weight: 500; cursor: pointer; text-align: left;
}
nav.nav button svg { flex-shrink: 0; }
nav.nav button.active { background: rgba(255,255,255,.16); font-weight: 700; }
nav.nav button:hover:not(.active) { background: rgba(255,255,255,.08); }

.sidebar-foot {
  margin-top: auto; padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.15);
}
.sidebar-foot .name { font-size: 12.5px; font-weight: 600; }
.sidebar-foot .role { font-size: 11px; opacity: .75; text-transform: capitalize; margin-bottom: 10px; }
.sidebar-foot button {
  display: flex; align-items: center; gap: 6px; background: transparent; border: none;
  color: rgba(255,255,255,.85); font-size: 12.5px; cursor: pointer; padding: 0;
}

#main { flex: 1; padding: 26px 30px; min-width: 0; }
.view { display: none; }
.view.active { display: block; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.page-head h2 { font-size: 19px; margin: 0 0 2px; }
.page-head p { font-size: 12.5px; color: var(--ink-soft); margin: 0; }

/* ---------------------------------------------------------------------- */
/* Shared components                                                      */
/* ---------------------------------------------------------------------- */
.btn {
  font-size: 13.5px; font-weight: 600; padding: 8px 14px; border-radius: 6px;
  cursor: pointer; border: 1px solid transparent; display: inline-flex;
  align-items: center; gap: 6px; background: transparent; color: var(--ink-soft);
  white-space: nowrap;
}
.btn svg { flex-shrink: 0; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: var(--white); color: var(--primary-dark); border-color: var(--border); }
.btn-outline:hover { background: var(--tint); }
.btn-danger { background: var(--white); color: var(--red); border-color: var(--red-bg); }
.btn-danger:hover { background: var(--red-bg); }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.btn:disabled { opacity: .5; cursor: default; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.field input, .field select, .field textarea {
  font-size: 13.5px; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); outline: none; color: var(--ink); background: var(--white);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

.card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,34,22,0.04); }
.card-pad { padding: 16px; }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; flex: 1 1 160px; min-width: 160px; box-shadow: 0 1px 2px rgba(16,34,22,0.04);
}
.stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; margin-bottom: 6px; }
.stat-value { font-family: var(--font-mono); font-size: 22px; font-weight: 700; }
.stat-value.up { color: var(--primary); }
.stat-value.down { color: var(--red); }
.stat-sub { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .4px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
th.right, td.right { text-align: right; }
td {
  font-size: 13.5px; padding: 9px 12px; border-bottom: 1px solid var(--border);
}
td.mono, th.mono { font-family: var(--font-mono); }
.table-wrap { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
tbody tr:last-child td { border-bottom: none; }

.badge {
  font-family: var(--font-mono); padding: 2px 8px; border-radius: 10px; font-size: 12.5px;
  background: var(--tint); color: var(--primary-dark); display: inline-block;
}
.badge.low { background: var(--red-bg); color: var(--red); }

.chip {
  cursor: pointer; font-size: 12.5px; background: var(--tint); color: var(--primary-dark);
  padding: 5px 10px; border-radius: 14px; display: inline-flex; align-items: center; gap: 6px;
  border: none;
}

.alert-warning {
  background: var(--amber-bg); border: 1px solid var(--amber-border); border-radius: var(--radius);
  padding: 12px 16px;
}
.alert-warning .head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--amber); margin-bottom: 8px; }
.alert-warning .items { display: flex; flex-wrap: wrap; gap: 8px; }
.alert-warning .items span {
  font-family: var(--font-mono); font-size: 12px; background: var(--white);
  border: 1px solid var(--amber-border); border-radius: 5px; padding: 3px 8px;
}

.section-title { font-size: 13.5px; font-weight: 700; margin: 0 0 10px; }

.period-tabs { display: flex; gap: 4px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.period-tabs button {
  font-size: 12.5px; font-weight: 600; padding: 6px 12px; border-radius: 6px; border: none;
  background: transparent; color: var(--ink-soft); cursor: pointer;
}
.period-tabs button.active { background: var(--white); color: var(--primary-dark); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.muted { color: var(--ink-soft); }
.error-text { color: var(--red); font-size: 12.5px; margin-top: 8px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(22,34,26,.4); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: var(--white); border-radius: 10px; width: 480px; max-width: 100%;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 12px 36px rgba(0,0,0,.2);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head button { background: none; border: none; cursor: pointer; color: var(--ink-soft); }
.modal-body { padding: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Sales POS */
.pos-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; align-items: start; }
.pos-search { position: relative; margin-bottom: 8px; }
.pos-search input { width: 100%; padding-left: 32px; }
.pos-search svg { position: absolute; left: 10px; top: 10px; color: var(--ink-soft); }

.pos-product-list {
  max-height: 260px; overflow-y: auto; background: var(--white);
  border: 1px solid var(--border); border-radius: 8px;
}
.pos-product-list .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border);
}
.pos-product-list .row:last-child { border-bottom: none; }
.pos-product-list .row:hover:not(.disabled) { background: var(--tint); }
.pos-product-list .row.disabled { cursor: default; opacity: .5; }
.pos-product-list .name { display: flex; align-items: center; gap: 8px; }
.pos-product-list .stock-note { font-size: 11px; }
.pos-product-list .stock-note.low { color: var(--amber); font-weight: 600; }
.pos-product-list .stock-note.out { color: var(--red); font-weight: 600; }

#toast-root { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--white); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 6px; padding: 10px 14px; font-size: 13px; box-shadow: 0 8px 20px rgba(0,0,0,.12);
  max-width: 320px; animation: toast-in .18s ease-out;
}
.toast.warning { border-left-color: var(--amber); }
.toast.danger { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.nav-badge {
  background: var(--red); color: var(--white); font-size: 10.5px; font-weight: 700;
  border-radius: 9px; padding: 1px 6px; margin-left: auto;
}
.notif-row { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.notif-row:last-child { border-bottom: none; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; background: var(--primary); }
.notif-dot.expenses { background: #8A5CB8; }
.notif-dot.settings { background: var(--ink-soft); }
.notif-dot.inventory-warn { background: var(--amber); }
.notif-dot.inventory-out { background: var(--red); }
.notif-text { font-size: 13.5px; }
.notif-time { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.pos-total-box {
  border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px;
  display: flex; justify-content: space-between; align-items: baseline;
}
.pos-total-box .amount { font-family: var(--font-mono); font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.qty-input { width: 56px; text-align: right; padding: 4px 6px !important; }
.price-input { width: 90px; text-align: right; padding: 4px 6px !important; }
.remove-line { background: none; border: none; cursor: pointer; color: var(--red); }

.pnl-row { display: flex; justify-content: space-between; padding: 9px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.pnl-row:last-of-type { border-bottom: none; }
.pnl-row .amt { font-family: var(--font-mono); }
.pnl-row .amt.neg { color: var(--red); }
.pnl-total { display: flex; justify-content: space-between; padding: 12px 16px; }
.pnl-total .amt { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-block { margin-bottom: 24px; }

/* Loading / empty */
.loading-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; color: var(--ink-soft); font-size: 14px; }
.empty-row td { color: var(--ink-soft); }

/* ---------------------------------------------------------------------- */
/* Responsive                                                             */
/* ---------------------------------------------------------------------- */
@media (max-width: 860px) {
  .pos-grid, .two-col, .form-grid { grid-template-columns: 1fr; }
  #activity-period-tabs { flex-wrap: wrap; }
}

@media (max-width: 720px) {
  #app-shell { flex-direction: column; }
  #sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; align-items: center; padding: 10px 12px; gap: 8px;
    overflow-x: auto;
  }
  .brand { padding: 0 10px 0 0; margin-right: 4px; flex-shrink: 0; }
  nav.nav { flex-direction: row; gap: 4px; flex: 1; }
  nav.nav button { padding: 8px 10px; white-space: nowrap; }
  nav.nav button span.nav-label { display: none; }
  nav.nav button .nav-badge { position: absolute; top: 2px; right: 2px; }
  nav.nav button { position: relative; }
  .sidebar-foot { margin-top: 0; padding-top: 0; border-top: none; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
  .sidebar-foot .role { display: none; }
  .sidebar-foot .name #user-name-text { display: none; }
  .sidebar-foot .name { padding: 6px 8px; border-radius: 6px; background: rgba(255,255,255,.1); }
  #main { padding: 14px; }
  .modal { width: 100%; }
  .page-head h2 { font-size: 17px; }
  .stat-card { min-width: 130px; padding: 12px; }
  .stat-value { font-size: 18px; }
  #activity-period-tabs button { padding: 5px 8px; font-size: 11.5px; }
  .card-pad { padding: 12px; }
}

@media (max-width: 420px) {
  .stat-row { gap: 8px; }
  .stat-card { flex: 1 1 100%; }
}
