/* ============================================================
   Tuckshop — visual identity: a village shop ledger.
   Deep shelf-green + hand-priced mustard tags on warm paper.
   ============================================================ */

:root {
  --paper: #F6F2E7;
  --surface: #FFFFFF;
  --ink: #22301C;
  --ink-soft: #5B6555;
  --forest: #2F5233;
  --forest-dark: #223C27;
  --mustard: #E2A63B;
  --mustard-dark: #B9832A;
  --brick: #B54834;
  --line: #DED3B8;
  --radius: 5px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Public Sans', 'Segoe UI', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  color: var(--forest-dark);
  margin: 0 0 .4em;
}

h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

a { color: var(--forest); }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* Mobile top bar — hidden on desktop */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--forest-dark);
  color: #fff;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.1rem;
  flex: 1;
  text-align: center;
}
.topbar-brand span { color: var(--mustard); }
.topbar-spacer { width: 34px; }

.menu-btn {
  background: none;
  border: none;
  padding: 6px;
  width: 34px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

.sidebar-overlay {
  display: none;
}

.sidebar {
  background: var(--forest-dark);
  color: #EFE9D8;
  padding: 22px 0;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  font-family: 'Fraunces', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  padding: 0 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 10px;
}
.sidebar .brand span { color: var(--mustard); }

.sidebar nav { flex: 1; }

.sidebar a.nav-link {
  display: block;
  padding: 10px 20px;
  color: #D9D3BC;
  text-decoration: none;
  border-left: 3px solid transparent;
  font-size: .93rem;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-link.active {
  border-left-color: var(--mustard);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-weight: 600;
}

.sidebar .who {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.12);
  font-size: .82rem;
  color: #C9C2A8;
}
.sidebar .who form { margin-top: 6px; }
.sidebar .who button {
  background: none;
  border: 1px solid rgba(255,255,255,.25);
  color: #EFE9D8;
  padding: 5px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .8rem;
}
.sidebar .who button:hover { background: rgba(255,255,255,.1); }

.main {
  padding: 26px 34px 50px;
  max-width: 1200px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-head p.sub { color: var(--ink-soft); margin: 2px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  background: var(--forest);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { background: var(--forest-dark); }
.btn.secondary { background: transparent; color: var(--forest); border: 1px solid var(--forest); }
.btn.secondary:hover { background: rgba(47,82,51,.08); }
.btn.mustard { background: var(--mustard); color: #2b1f04; }
.btn.mustard:hover { background: var(--mustard-dark); }
.btn.danger { background: var(--brick); }
.btn.danger:hover { background: #93382a; }
.btn.small { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.tile .value { font-family: 'Fraunces', serif; font-size: 1.7rem; color: var(--forest-dark); margin-top: 4px; }
.tile.alert .value { color: var(--brick); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 22px;
}

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
}
th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
tr:hover td { background: rgba(47,82,51,.04); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Forms ---------- */
label { display: block; font-size: .82rem; color: var(--ink-soft); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: .92rem;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--mustard);
  outline-offset: 1px;
  border-color: var(--mustard-dark);
}
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
}
.badge.green { background: rgba(47,82,51,.12); color: var(--forest-dark); }
.badge.mustard { background: rgba(226,166,59,.22); color: var(--mustard-dark); }
.badge.brick { background: rgba(181,72,52,.13); color: var(--brick); }
.badge.grey { background: #EAE4D2; color: var(--ink-soft); }

/* ---------- Alerts / flash ---------- */
.flash {
  padding: 11px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-size: .9rem;
  border: 1px solid transparent;
}
.flash.success { background: rgba(47,82,51,.09); border-color: rgba(47,82,51,.25); color: var(--forest-dark); }
.flash.error { background: rgba(181,72,52,.1); border-color: rgba(181,72,52,.3); color: var(--brick); }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--forest-dark);
}
.login-box {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 36px 34px;
  width: 320px;
  box-shadow: 0 12px 32px rgba(0,0,0,.35);
}
.login-box h1 { text-align: center; }
.login-box .tag { text-align: center; color: var(--ink-soft); margin-bottom: 20px; font-size: .85rem; }
.login-box .btn { width: 100%; margin-top: 6px; }

/* ---------- POS screen ---------- */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}
.pos-search input { font-size: 1rem; padding: 11px 14px; }
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.product-card:hover { border-color: var(--mustard); }
.product-card:disabled { opacity: .4; cursor: not-allowed; }
.product-card .pname { font-weight: 600; font-size: .88rem; margin-bottom: 6px; min-height: 2.4em; }
.product-card .pprice {
  display: inline-block;
  background: var(--mustard);
  color: #2b1f04;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .82rem;
}
.product-card .pstock { display: block; margin-top: 6px; font-size: .74rem; color: var(--ink-soft); }

.cart {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  position: sticky;
  top: 20px;
}
.cart h2 { display: flex; justify-content: space-between; align-items: center; }
.cart-items { max-height: 34vh; overflow-y: auto; margin: 10px 0; border-top: 1px dashed var(--line); }
.cart-item {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  font-size: .86rem;
}
.cart-item .qty-input { width: 48px; padding: 4px; text-align: center; }
.cart-item .rm { background: none; border: none; color: var(--brick); cursor: pointer; font-size: 1rem; }
.cart-empty { color: var(--ink-soft); text-align: center; padding: 20px 0; font-size: .88rem; }

.cart-totals { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.cart-totals .row { display: flex; justify-content: space-between; font-size: .9rem; padding: 3px 0; }
.cart-totals .row.grand { font-family: 'Fraunces', serif; font-size: 1.25rem; color: var(--forest-dark); padding-top: 6px; }

.pay-method { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.pay-method label {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
  padding: 8px 4px;
  cursor: pointer;
  font-size: .82rem;
  color: var(--ink-soft);
}
.pay-method input { display: none; }
.pay-method input:checked + span { color: var(--forest-dark); font-weight: 700; }
.pay-method label:has(input:checked) { border-color: var(--forest); background: rgba(47,82,51,.06); }

/* ---------- Receipt / print ---------- */
.receipt {
  max-width: 340px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  padding: 20px;
  font-family: 'Courier New', monospace;
  font-size: .85rem;
}
.receipt hr { border: none; border-top: 1px dashed #999; margin: 10px 0; }
.receipt .center { text-align: center; }
.receipt .row { display: flex; justify-content: space-between; }

@media print {
  .no-print { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
}

/* ---------- Misc ---------- */
.muted { color: var(--ink-soft); }
.text-right { text-align: right; }
.mt { margin-top: 18px; }
.empty-state { padding: 40px 0; text-align: center; color: var(--ink-soft); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: end; }
.filters .field { margin-bottom: 0; min-width: 150px; }

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

  .topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 250px;
    max-width: 80vw;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 50;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .brand { display: none; } /* topbar already shows the brand on mobile */

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: auto; }

  .main { padding: 18px 16px 40px; max-width: none; }

  .page-head { flex-direction: column; align-items: flex-start; }
  .page-head > div:last-child,
  .page-head > a.btn { width: 100%; }

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

  .pos-layout { grid-template-columns: 1fr; }
  .cart { position: static; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: none; }

  .field-row { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .field { min-width: 0; }

  /* Tables scroll horizontally instead of squeezing columns unreadably */
  .card { padding: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }

  .login-box { width: 88vw; padding: 28px 22px; }

  /* Bigger, easier tap targets on touch screens */
  .btn { padding: 11px 18px; font-size: .95rem; }
  .btn.small { padding: 7px 12px; }
  .sidebar a.nav-link { padding: 13px 20px; font-size: 1rem; }
  .pay-method label { padding: 11px 4px; font-size: .85rem; }
  input, select, textarea { font-size: 1rem; padding: 10px 12px; }
  .product-card { padding: 10px; }
}

@media (max-width: 480px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile .value { font-size: 1.4rem; }
}
