﻿@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --ink: #123B63;
  --ink-soft: #52677A;
  --paper: #F4F7FA;
  --card: #FFFFFF;
  --line: #D9E2EA;
  --line-strong: #B7C7D6;
  --teal: #1769AA;
  --teal-dark: #0F4C81;
  --amber: #D98A00;
  --amber-bg: #FFF3D6;
  --red: #C0392B;
  --red-bg: #FDE8E6;
  --radius: 6px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'IBM Plex Mono', monospace; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  font-size: 0.95rem;
}

a { color: inherit; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }

.btn {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn.secondary:hover { background: rgba(0,0,0,0.03); }

.btn.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn.small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 600;
}
.field input, .field select {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(47,111,94,0.15);
}

.error-msg {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
}
.success-msg {
  background: #E4F0EA;
  color: var(--teal-dark);
  border: 1px solid var(--teal);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 0.8rem;
}

/* ---------- Login screen ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    repeating-linear-gradient(180deg, transparent, transparent 27px, var(--line) 28px),
    var(--paper);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 2.2rem 2rem 2rem;
  box-shadow: 0 12px 30px rgba(28, 43, 36, 0.10);
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute;
  top: -1px; left: 24px; right: 24px;
  height: 6px;
  background: repeating-linear-gradient(90deg, var(--teal) 0 10px, transparent 10px 16px);
  border-radius: 0 0 3px 3px;
}
.login-brand-eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-dark);
  margin: 0 0 0.3rem;
}
.login-card h1 {
  font-size: 1.5rem;
  margin: 0 0 0.2rem;
  letter-spacing: -0.01em;
}
.login-card .sub {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0 1.6rem;
}
.login-card form { margin-top: 0.4rem; }
.login-card .btn { width: 100%; margin-top: 0.4rem; padding: 0.7rem; }
.login-hint {
  margin-top: 1.4rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
  border-top: 1px dashed var(--line-strong);
  padding-top: 0.9rem;
}
.login-hint code {
  background: var(--paper);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-family: 'IBM Plex Mono', monospace;
}

/* ---------- App shell ---------- */
#app-screen {
  display: none;
  min-height: 100vh;
  grid-template-columns: 240px 1fr;
}
#app-screen.active { display: grid; }

.sidebar {
  background: var(--ink);
  color: var(--paper);
  padding: 1.4rem 1.1rem;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #9CB2A6;
  margin-bottom: 0.2rem;
}
.sidebar-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 1.6rem;
  letter-spacing: -0.01em;
}

.store-strip {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.6rem;
}
.store-tag {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.6rem;
  border: 1px dashed rgba(255,255,255,0.25);
  border-radius: 3px;
  font-size: 0.72rem;
}
.store-tag .name { font-weight: 600; }
.store-tag .cat { color: #9CB2A6; font-size: 0.65rem; }

nav.main-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}
nav.main-nav button {
  text-align: left;
  background: transparent;
  border: none;
  color: #CBD8CF;
  padding: 0.6rem 0.7rem;
  border-radius: 3px;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
nav.main-nav button:hover { background: rgba(255,255,255,0.06); color: #fff; }
nav.main-nav button.active {
  background: var(--teal);
  color: #fff;
}
nav.main-nav .badge {
  margin-left: auto;
  background: var(--amber);
  color: #2A1B00;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 0.05rem 0.45rem;
}

.sidebar-footer {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255,255,255,0.12);
}
.who {
  font-size: 0.82rem;
  margin-bottom: 0.6rem;
}
.who .role-tag {
  display: inline-block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.1);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  margin-top: 0.15rem;
}

.main-panel {
  padding: 1.8rem 2.4rem 3rem;
  overflow-y: auto;
  max-height: 100vh;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.4rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px dashed var(--line-strong);
}
.panel-header h2 { margin: 0; font-size: 1.4rem; letter-spacing: -0.01em; }
.panel-header .desc { font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.2rem; }

/* ---------- Cards / Stat grid ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.8rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  position: relative;
}
.stat-card .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 600;
}
.stat-card .value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.7rem;
  font-weight: 600;
  margin-top: 0.3rem;
}
.stat-card.alert { border-color: var(--amber); background: var(--amber-bg); }
.stat-card.alert .value { color: #7A4A0F; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  margin-bottom: 1.5rem;
}
.card h3 {
  margin: 0 0 1rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line-strong);
  padding: 0.5rem 0.6rem;
  font-weight: 600;
}
tbody td {
  padding: 0.6rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
tbody tr:hover { background: rgba(47,111,94,0.04); }
.num { font-family: 'IBM Plex Mono', monospace; text-align: right; }
.empty-row td {
  text-align: center;
  color: var(--ink-soft);
  padding: 1.6rem;
  font-style: italic;
}

.pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
}
.pill.ok { background: #E4F0EA; color: var(--teal-dark); }
.pill.low { background: var(--amber-bg); color: #7A4A0F; }
.pill.off { background: var(--red-bg); color: var(--red); }

/* store bin-tag chip, the signature element reused inline */
.bin-chip {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  border: 1px dashed var(--line-strong);
  border-radius: 3px;
  padding: 0.1rem 0.45rem;
  background: var(--paper);
}

/* ---------- Forms row ---------- */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.9rem;
  align-items: end;
}
.filter-row {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.filter-row .field { margin-bottom: 0; min-width: 160px; }

/* ---------- Notification feed ---------- */
.feed-item {
  display: flex;
  gap: 0.8rem;
  padding: 0.7rem 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.85rem;
}
.feed-item:last-child { border-bottom: none; }
.feed-item .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--teal);
  margin-top: 0.35rem;
  flex-shrink: 0;
}
.feed-item.low .dot { background: var(--amber); }
.feed-item .meta { color: var(--ink-soft); font-size: 0.75rem; margin-top: 0.15rem; }

.top-actions { display: flex; gap: 0.6rem; align-items: center; }

.bell-btn {
  position: relative;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}
.bell-btn .dot-alert {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--amber);
  color: #2A1B00;
  font-size: 0.62rem;
  font-weight: 700;
  border-radius: 8px;
  padding: 0.02rem 0.32rem;
}

/* Prevent long content from breaking the layout */

img,
video {
  max-width: 100%;
  height: auto;
}

input,
select,
button {
  max-width: 100%;
}

:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }





/* ---------- Sidebar logout button ---------- */
#logout-btn {
  color: #ffffff;
  border-color: rgba(255,255,255,0.35);
}

#logout-btn:hover {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
}

/* =========================================================
   RESPONSIVE DESIGN — PHONES / TABLETS / LAPTOPS / DESKTOP
   ========================================================= */

/* ---------- General responsive safety ---------- */

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

button,
input,
select,
textarea {
  max-width: 100%;
}

/* ---------- Desktop baseline ---------- */

.main-panel {
  min-width: 0;
}

.card,
.stat-card,
.filter-row {
  min-width: 0;
}

table {
  max-width: 100%;
}

/* ---------- Tablets ---------- */

@media (max-width: 900px) {

  #app-screen {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .sidebar {
    padding: 1rem 0.8rem;
  }

  .sidebar-brand {
    font-size: 0.78rem;
  }

  .sidebar-title {
    font-size: 1.35rem;
  }

  .main-panel {
    padding: 1rem;
  }

  .panel-header {
    gap: 0.75rem;
  }

  .panel-header h2 {
    font-size: 1.35rem;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #overview-stores,
  #overview-feed {
    min-width: 0;
  }

  .card {
    overflow-x: auto;
  }

  table {
    min-width: 650px;
  }

  .form-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- Phones ---------- */

@media (max-width: 600px) {

  body {
    font-size: 14px;
  }

  /* Login */

  #login-screen {
    padding: 1rem;
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    padding: 1.4rem;
  }

  .login-card h1 {
    font-size: 1.7rem;
  }

  /* App layout */

  #app-screen {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: relative;
    width: 100%;
    min-height: auto;
    padding: 0.9rem;
  }

  .sidebar-brand {
    margin-bottom: 0.1rem;
  }

  .sidebar-title {
    margin-bottom: 0.7rem;
  }

  .store-strip {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    padding-bottom: 0.35rem;
  }

  .store-strip > * {
    flex: 0 0 auto;
  }

  .main-nav {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    padding-bottom: 0.45rem;
    -webkit-overflow-scrolling: touch;
  }

  .main-nav button {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }

  .sidebar-footer {
    margin-top: 0.75rem;
  }

  .main-panel {
    padding: 0.9rem;
    width: 100%;
  }

  /* Header */

  .panel-header {
    display: block;
  }

  .panel-header h2 {
    font-size: 1.3rem;
    line-height: 1.25;
  }

  .panel-header .desc {
    margin-top: 0.25rem;
  }

  .top-actions {
    margin-top: 0.75rem;
  }

  /* Overview */

  .stat-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .stat-card {
    width: 100%;
  }

  #overview-stores,
  #overview-feed {
    width: 100%;
  }

  /* Any two-column dashboard grid becomes one column */

  #panel-body > div[style*="grid-template-columns"],
  #overview-stores,
  #overview-feed {
    max-width: 100%;
  }

  /* Forms */

  .form-row {
    grid-template-columns: 1fr;
  }

  .filter-row {
    display: block;
  }

  .filter-row .field {
    width: 100%;
    margin-bottom: 0.75rem;
  }

  input,
  select,
  textarea {
    width: 100%;
    min-height: 42px;
    font-size: 16px;
  }

  button,
  .btn {
    min-height: 42px;
  }

  /* Cards */

  .card {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
  }

  /* Tables remain readable by horizontal scrolling */

  .card table,
  table {
    min-width: 680px;
  }

  .card {
    -webkit-overflow-scrolling: touch;
  }

  /* Make table containers easier to use */

  table {
    font-size: 0.84rem;
  }

  th,
  td {
    padding: 0.55rem 0.5rem;
    white-space: nowrap;
  }

  /* Product editing controls */

  [data-edit-name] {
    min-width: 180px;
  }

  [data-edit-price],
  [data-edit-buying-price],
  [data-edit-selling-price] {
    min-width: 100px;
  }

  [data-edit-stock] {
    min-width: 85px;
  }

  /* Buttons */

  .btn {
    white-space: nowrap;
  }

  .btn.small {
    min-height: 38px;
  }

  /* Sales / stock action buttons */

  [data-delete-sale],
  [data-delete-edit],
  [data-save-edit],
  [data-cancel-edit] {
    margin: 0.15rem;
  }

  /* Notification cards */

  .feed-item {
    gap: 0.55rem;
  }

  /* Store chips */

  .bin-chip,
  .role-tag,
  .pill {
    white-space: nowrap;
  }
}

/* ---------- Very small phones ---------- */

@media (max-width: 380px) {

  .main-panel {
    padding: 0.65rem;
  }

  .sidebar {
    padding: 0.7rem;
  }

  .sidebar-title {
    font-size: 1.2rem;
  }

  .panel-header h2 {
    font-size: 1.15rem;
  }

  .login-card {
    padding: 1.1rem;
  }

  .card {
    padding: 0.75rem;
  }

  table {
    min-width: 620px;
  }
}

/* ---------- Touch devices ---------- */

@media (hover: none) and (pointer: coarse) {

  button,
  .btn,
  select,
  input {
    min-height: 44px;
  }

  .main-nav button {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }
}



/* =========================================================
   MOBILE WIDTH / OVERFLOW CORRECTION
   ========================================================= */

@media (max-width: 600px) {

  html,
  body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow-x: hidden !important;
  }

  #app-screen,
  #login-screen,
  .sidebar,
  .main-panel,
  #panel-body,
  .panel-header,
  .panel-actions,
  .card,
  .filter-row,
  .stat-grid {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #app-screen {
    margin: 0;
    padding: 0;
  }

  .sidebar {
    width: 100%;
    max-width: 100vw;
    margin: 0;
  }

  .main-panel {
    width: 100%;
    max-width: 100vw;
    margin: 0;
  }

  #panel-body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .panel-header {
    width: 100%;
    max-width: 100%;
  }

  /*
     Prevent long text, buttons and chips from
     forcing the entire page wider.
  */

  .sidebar-brand,
  .sidebar-title,
  .panel-header h2,
  .panel-header .desc,
  .card h3,
  .feed-item,
  .meta {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /*
     Navigation scrolls inside itself instead of
     increasing the page width.
  */

  .main-nav,
  .store-strip {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  /*
     Dashboard grids must never create a wider
     child than the phone.
  */

  #panel-body > div[style*="grid-template-columns"] {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    display: block !important;
  }

  #overview-stores,
  #overview-feed {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /*
     Cards themselves stay inside the blue area.
  */

  .card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  /*
     Tables may scroll, but the TABLE must not
     force the PAGE itself to scroll.
  */

  .card {
    overflow-x: auto;
    overflow-y: visible;
  }

  /*
     Prevent fixed/minimum widths on common elements
     from pushing the page outward.
  */

  .field,
  .field input,
  .field select,
  .field textarea,
  .form-row {
    max-width: 100%;
    min-width: 0;
  }

  /*
     Login card must remain centered inside viewport.
  */

  #login-screen {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    overflow-x: hidden;
  }

  .login-card {
    width: calc(100% - 2rem);
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
  }
}


/* =========================================================
   LOGIN / APP SCREEN VISIBILITY
   One screen at a time on every device.
   ========================================================= */

#login-screen {
  display: none;
  width: 100%;
  min-width: 0;
  max-width: 100vw;
}

#app-screen {
  display: none;
  width: 100%;
  min-width: 0;
  max-width: 100vw;
}

/* JavaScript-controlled states */

body.logged-out #login-screen {
  display: flex;
}

body.logged-out #app-screen {
  display: none;
}

body.logged-in #login-screen {
  display: none;
}

body.logged-in #app-screen {
  display: flex;
}

/* Mobile: never allow the two screens to appear together */

@media (max-width: 600px) {

  body.logged-out #login-screen {
    display: flex !important;
  }

  body.logged-out #app-screen {
    display: none !important;
  }

  body.logged-in #login-screen {
    display: none !important;
  }

  body.logged-in #app-screen {
    display: block !important;
  }
}

