:root{
  --bg: #F1EAD9;
  --surface: #FFFFFF;
  --surface-alt: #FAFAFB;
  --border: #E9E2D0;
  --text: #16181D;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --teal: #0B4A5F;
  --teal-dark: #062E3B;
  --teal-light: #E6EEF1;
  --marigold: #D99A1B;
  --marigold-dark: #93670F;
  --red: #C43D3D;
  --red-light: #FCEBEC;
  --positive: #16A34A;
  --money-green: #2F6B3E;
  --money-green-light: #E7F0E8;
  --radius-card: 16px;
  --radius-md: 10px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(16,24,40,0.04), 0 4px 12px rgba(16,24,40,0.06);
  --shadow-card-hover: 0 2px 4px rgba(16,24,40,0.06), 0 8px 20px rgba(16,24,40,0.09);
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Consolas', 'Menlo', monospace;
}
*{ box-sizing: border-box; }
body{
  margin:0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); line-height: 1.55; padding: 0 0 4rem;
  -webkit-font-smoothing: antialiased;
}
.wrap{ max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }
.hidden{ display:none !important; }

header.shopHeader{
  padding: 1.1rem 1.5rem; margin: 0 -1.5rem 1.8rem; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display:flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem;
  position: sticky; top:0; z-index:20;
}
.shopName{ font-size: 1.3rem; font-weight: 700; color: var(--text); letter-spacing: -0.2px; margin: 0; }
.shopTag{ font-size: 0.82rem; color: var(--text-secondary); margin-top: 0.1rem; }
.headerRight{ text-align:right; display:flex; align-items:center; gap:1rem; }
.userBadge{ text-align:right; }
.userName{ font-size:0.92rem; color: var(--text); font-weight:600; }
.roleTag{ display:inline-block; font-size:0.66rem; text-transform:uppercase; letter-spacing:0.5px; background: var(--teal-light); color: var(--teal); border-radius: var(--radius-pill); padding:2px 9px; margin-top:2px; font-weight:600; }
.logoutBtn{ background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-pill); padding:0.5rem 1rem; font-size:0.82rem; color:var(--text-secondary); cursor:pointer; font-weight:500; }
.logoutBtn:hover{ background: var(--border); color: var(--text); }
.headerLogo{ width:44px; height:44px; border-radius: var(--radius-md); object-fit:cover; border:1px solid var(--border); flex-shrink:0; }
.headerBrand{ display:flex; align-items:center; gap:0.75rem; }

.layout{ display:grid; grid-template-columns: 1.15fr 0.85fr; gap: 1.4rem; align-items:start; }
@media (max-width: 880px){ .layout{ grid-template-columns: 1fr; } }

.card{ background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 1.5rem 1.6rem; box-shadow: var(--shadow-card); }
.cardTitle{ font-size: 1.05rem; font-weight:700; color: var(--text); margin: 0 0 1.2rem; padding-bottom: 0.8rem; border-bottom: 1px solid var(--border); }

.section{ margin-bottom: 1.7rem; }
.sectionHead{ display:flex; align-items:center; gap:0.6rem; margin-bottom: 0.8rem; }
.sectionNum{ width: 24px; height: 24px; border-radius:50%; background: var(--teal-light); color: var(--teal); font-size: 0.72rem; font-weight:700; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.sectionName{ font-weight:700; font-size:0.94rem; color: var(--text); }
.sectionNote{ font-size:0.78rem; color: var(--text-secondary); margin: -0.4rem 0 0.8rem 2.1rem; }

.fieldRow{ display:grid; grid-template-columns: repeat(2, 1fr); gap: 0.8rem 0.9rem; }
.field label{ display:block; font-size:0.74rem; color:var(--text-secondary); font-weight:600; letter-spacing:0.1px; margin-bottom:0.3rem; }
.field .fieldHint{ display:block; font-size:0.7rem; color:var(--text-muted); font-weight:400; margin-top:0.2rem; }
.field input[type=number], .field input[type=text], .field input[type=password], .field input[type=date], .field select{
  width:100%; padding:0.55rem 0.7rem; font-family: var(--font-mono);
  font-size:0.94rem; border:1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-alt); color: var(--text);
}
.field select{ font-family: var(--font-sans); }
.field input[type=file]{ width:100%; padding:0.4rem; border:1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-alt); font-size:0.85rem; }
.field input:focus, .field select:focus{ outline:none; border-color: var(--teal); background: var(--surface); box-shadow: 0 0 0 3px var(--teal-light); }

.computed{ margin-top:0.8rem; background: var(--teal-light); border-radius: var(--radius-md); padding:0.6rem 0.9rem; display:flex; justify-content:space-between; align-items:center; font-size:0.85rem; }
.computed .val{ font-family: var(--font-mono); font-weight:700; color: var(--teal-dark); }

.otherRow{ display:grid; grid-template-columns: 1fr 130px 34px; gap:0.5rem; margin-bottom:0.5rem; }
.otherRow input{ padding:0.45rem 0.55rem; border:1px solid var(--border); border-radius: var(--radius-md); font-size:0.88rem; font-family: var(--font-sans); background: var(--surface-alt); }
.otherRow input[type=number]{ font-family: var(--font-mono); }
.rmBtn{ background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-md); color:var(--red); cursor:pointer; font-size:0.9rem; }
.rmBtn:hover{ background: var(--red-light); border-color: var(--red); }
.addItemBtn{ background: var(--surface-alt); border:1px dashed var(--border); border-radius: var(--radius-md); color:var(--teal); font-size:0.82rem; padding:0.5rem 0.8rem; cursor:pointer; font-weight:600; }
.addItemBtn:hover{ background: var(--teal-light); border-color: var(--teal); }

.dateField{ margin-bottom:1.4rem; }
.dateField label{ font-size:0.75rem; font-weight:600; color:var(--text-secondary); display:block; margin-bottom:0.35rem;}

.formActions{ display:flex; gap:0.7rem; margin-top:1.2rem; align-items:center; flex-wrap:wrap; }
.primaryBtn{ background: var(--teal); color:#fff; border:none; border-radius: var(--radius-pill); padding:0.7rem 1.5rem; font-size:0.9rem; font-weight:600; cursor:pointer; box-shadow: 0 1px 2px rgba(11,74,95,0.25); }
.primaryBtn:hover{ background: var(--teal-dark); }
.primaryBtn:disabled{ opacity:0.6; cursor:not-allowed; }
.ghostBtn{ background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-pill); padding:0.65rem 1.3rem; font-size:0.85rem; color:var(--text-secondary); cursor:pointer; font-weight:600; }
.ghostBtn:hover{ background: var(--surface-alt); color: var(--text); }
.formMsg{ font-size:0.8rem; color: var(--red); margin-top:0.6rem; min-height:1.1em; font-weight:500; }
.formMsg.ok{ color: var(--positive); }

.flagBanner{ background: var(--red-light); border:1px solid var(--red); color:var(--red); border-radius: var(--radius-md); padding:0.7rem 0.9rem; font-size:0.82rem; margin-bottom:1.2rem; }
.backupBanner{ background: var(--teal-light); border:1px solid var(--teal); color:var(--teal-dark); border-radius: var(--radius-md); padding:0.7rem 0.9rem; font-size:0.82rem; margin-bottom:1.2rem; display:flex; justify-content:space-between; align-items:center; gap:1rem; flex-wrap:wrap; }
.backupBanner.stale{ background: var(--red-light); border-color: var(--red); color: var(--red); }

.metricGrid{ display:grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap:0.9rem; margin-bottom:1.6rem; }
.metricCard{ background: var(--surface); border:1px solid var(--border); border-left:4px solid var(--money-green); border-radius:10px; padding:0.9rem 1rem; box-shadow: var(--shadow-card); display:flex; flex-direction:column; gap:0.5rem; }
.metricCard.accent-amber{ border-left-color: var(--marigold); }
.metricCard.accent-red{ border-left-color: var(--red); }
.metricLabel{ font-size:0.66rem; font-weight:700; letter-spacing:0.4px; text-transform:uppercase; color: var(--text-secondary); }
.metricValue{ font-family: var(--font-mono); font-size:1.28rem; font-weight:700; color: var(--text); }
.metricCard.accent-amber .metricValue{ color: var(--marigold-dark); }
.metricCard.accent-red .metricValue{ color: var(--red); }

.chartsRow{ display:grid; grid-template-columns: 1.3fr 1fr; gap:1.2rem; margin-bottom:1.6rem; }
@media (max-width: 880px){ .chartsRow{ grid-template-columns: 1fr; } }
.salesChartSvg{ width:100%; height:auto; display:block; }
.salesChartSvg .gridLine{ stroke: var(--border); stroke-width:1; }
.salesChartSvg .axisLabel, .salesChartSvg .dayLabel{ fill: var(--text-muted); font-size:9px; font-family: var(--font-sans); }
.salesChartSvg .salesBar{ fill: var(--marigold); }
.donutWrapInner{ display:flex; flex-direction:column; align-items:center; gap:1rem; padding-top:0.5rem; }
.donutLegend{ display:flex; gap:1.4rem; }
.donutLegendItem{ display:flex; align-items:center; gap:0.4rem; font-size:0.82rem; color: var(--text-secondary); font-weight:600; }
.donutLegendSwatch{ width:10px; height:10px; border-radius:2px; }

.compareCard{ margin-bottom:1.6rem; }
.compareGrid{ display:grid; grid-template-columns: repeat(3, 1fr); gap:1rem; }
.compareItem{ text-align:center; }
.compareItem .lbl{ font-size:0.72rem; color:var(--text-secondary); text-transform:uppercase; font-weight:700; }
.compareItem .cur{ font-family: var(--font-mono); font-size:1.15rem; font-weight:700; margin-top:0.3rem; }
.compareItem .delta{ font-size:0.78rem; margin-top:0.2rem; font-weight:600; }
.compareItem .delta.up{ color: var(--positive); }
.compareItem .delta.down{ color: var(--red); }

.periodPills{ display:flex; gap:0.4rem; margin-bottom:1.1rem; flex-wrap:wrap; }
.periodPill{ background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-pill); padding:0.45rem 1.1rem; font-size:0.82rem; color:var(--text-secondary); cursor:pointer; font-weight:600; }
.periodPill.active{ background: var(--teal); color:#fff; border-color: var(--teal); }
.periodControls{ margin-bottom:1.3rem; display:flex; gap:0.6rem; align-items:center; flex-wrap:wrap; }
.periodControls select, .periodControls input{ padding:0.5rem 0.7rem; border:1px solid var(--border); border-radius: var(--radius-md); font-size:0.85rem; background: var(--surface-alt); }

.dailyDetailGrid{ display:grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap:0.8rem; margin-top:1rem; }
.dailyDetailItem{ background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-md); padding:0.7rem 0.9rem; }
.dailyDetailItem .lbl{ font-size:0.7rem; color:var(--text-muted); font-weight:600; }
.dailyDetailItem .amt{ font-family: var(--font-mono); font-weight:700; color:var(--text); font-size:1.05rem; margin-top:0.2rem; }

.ledgerWrap{ margin-top:1.8rem; }
.ledgerHead{ display:flex; justify-content:space-between; align-items:center; margin-bottom:0.8rem; flex-wrap:wrap; gap:0.6rem; }
.tableScroll{ overflow-x:auto; border:1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card); }
table.ledger{ border-collapse:collapse; width:100%; min-width:1080px; background: var(--surface); }
table.ledger th, table.ledger td{ padding:0.65rem 0.8rem; font-size:0.8rem; text-align:right; white-space:nowrap; border-bottom:1px solid var(--border); }
table.ledger th{ background: var(--surface-alt); color: var(--text-secondary); font-weight:700; text-align:right; position:sticky; top:0; font-size:0.72rem; text-transform:uppercase; letter-spacing:0.3px; }
table.ledger th:first-child, table.ledger td:first-child{ text-align:left; }
table.ledger tbody tr:hover{ background: var(--surface-alt); }
table.ledger td.actions{ text-align:center; white-space:nowrap; }
table.ledger td.actions button{ background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-md); font-size:0.72rem; padding:0.3rem 0.6rem; cursor:pointer; margin:0 2px; color: var(--text-secondary); font-weight:500; }
table.ledger tfoot td{ font-weight:700; background: var(--teal-light); border-top:2px solid var(--teal); border-bottom:none; color: var(--teal-dark); }
.emptyState{ text-align:center; padding:2.4rem; color:var(--text-muted); font-size:0.9rem; }
.rowFlagged{ background: var(--red-light) !important; }

.loginWrap{ max-width:460px; margin: 2.5rem auto; }
.heroLogin{ border-radius: var(--radius-card); overflow:hidden; background: var(--surface); box-shadow: var(--shadow-card-hover); }
.heroPhoto{ height:210px; background-image: url('img/shop-hero.jpg'); background-size:cover; background-position:center 62%; position:relative; }
.heroPhoto::after{ content:""; position:absolute; inset:0; background: linear-gradient(180deg, rgba(6,46,59,0.05) 0%, rgba(6,46,59,0.9) 100%); }
.heroPhotoText{ position:absolute; left:0; right:0; bottom:0; padding:1.2rem 1.4rem; z-index:1; }
.heroPhotoText .shopName{ color:#fff; font-size:1.4rem; font-weight:700; }
.heroPhotoText .shopTag{ color: rgba(255,255,255,0.82); font-size:0.8rem; margin-top:0.2rem; }
.heroChips{ display:flex; gap:0.4rem; margin-top:0.6rem; flex-wrap:wrap; }
.heroChip{ background: rgba(255,255,255,0.16); color:#fff; font-size:0.68rem; font-weight:600; padding:3px 10px; border-radius: var(--radius-pill); border:1px solid rgba(255,255,255,0.25); }
.heroLoginBody{ padding:1.8rem 1.6rem 2rem; }
.loginField{ text-align:left; margin-bottom:1rem; }
.loginField label{ display:block; font-size:0.76rem; font-weight:600; color:var(--text-secondary); margin-bottom:0.35rem; }
.loginField input{ width:100%; padding:0.65rem 0.75rem; border:1px solid var(--border); border-radius: var(--radius-md); font-size:0.95rem; background: var(--surface-alt); }
.loginBtn{ width:100%; margin-top:0.4rem; }
.loginMsg{ font-size:0.8rem; color: var(--red); margin-top:0.8rem; min-height:1.1em; }
.loginHint{ font-size:0.72rem; color:var(--text-muted); margin-top:1.4rem; border-top:1px solid var(--border); padding-top:1rem; }

.tabBar{ display:flex; gap:0.3rem; margin-bottom:1.8rem; background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-pill); padding:0.3rem; width:fit-content; flex-wrap:wrap; }
.tabBtn{ background:none; border:none; padding:0.55rem 1.1rem; font-size:0.84rem; font-weight:600; color: var(--text-secondary); cursor:pointer; border-radius: var(--radius-pill); }
.tabBtn.active{ color: #fff; background: var(--teal); }

.marketEntrySubtitle{ font-size:0.82rem; color: var(--text-secondary); margin: -0.6rem 0 1.2rem; }
.marketTabBar{ display:flex; gap:0.4rem; margin-bottom:1.4rem; flex-wrap:wrap; background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-pill); padding:0.3rem; width:fit-content; }
.marketTabBtn{ background:none; border:none; padding:0.5rem 1rem; font-size:0.84rem; font-weight:600; color: var(--text-secondary); cursor:pointer; border-radius: var(--radius-pill); }
.marketTabBtn.active{ background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }

.photoPreview{ margin-top:0.6rem; display:flex; align-items:center; gap:0.6rem; }
.photoPreview img{ width:56px; height:56px; object-fit:cover; border-radius: var(--radius-md); border:1px solid var(--border); cursor:pointer; }
.photoPreviewNote{ font-size:0.78rem; color: var(--positive); font-weight:600; }

.userRow{ display:grid; grid-template-columns: 1fr 1fr 100px 90px; gap:0.6rem; align-items:center; padding:0.7rem 0; border-bottom:1px solid var(--border); font-size:0.85rem; }
.userRow.headRow{ font-weight:700; color:var(--text-muted); font-size:0.7rem; text-transform:uppercase; letter-spacing:0.4px; border-bottom:2px solid var(--border); }
.userRow .actionsCell{ display:flex; gap:6px; }
.userRow .actionsCell button{ background: var(--surface-alt); border:1px solid var(--border); border-radius: var(--radius-md); font-size:0.72rem; padding:0.3rem 0.6rem; cursor:pointer; color:var(--text-secondary); font-weight:500; }
.addUserForm{ margin-top:1.3rem; padding-top:1.3rem; border-top:1px dashed var(--border); }
.addUserGrid{ display:grid; grid-template-columns: 1fr 1fr; gap:0.7rem 0.9rem; margin-bottom:0.8rem; }

.recentTable{ width:100%; border-collapse:collapse; margin-top:1.5rem; font-size:0.82rem; }
.recentTable th, .recentTable td{ padding:0.55rem 0.6rem; text-align:right; border-bottom:1px solid var(--border); }
.recentTable th{ background: var(--surface-alt); color: var(--text-secondary); font-size:0.7rem; text-transform:uppercase; font-weight:700; }
.recentTable th:first-child, .recentTable td:first-child{ text-align:left; }

.checklistTimestamp{ font-size:0.75rem; color:var(--text-muted); margin-top:0.4rem; }
.attendanceGrid{ display:flex; gap:0.5rem; margin-top:1rem; flex-wrap:wrap; }
.attendanceDay{ flex:1; min-width:70px; text-align:center; padding:0.6rem 0.4rem; border-radius: var(--radius-md); border:1px solid var(--border); }
.attendanceDay.complete{ background: var(--money-green-light); border-color: var(--money-green); }
.attendanceDay.partial{ background: var(--teal-light); }
.attendanceDay.absent{ background: var(--surface-alt); }
.attendanceDay .dLbl{ font-size:0.68rem; color:var(--text-secondary); font-weight:700; }
.attendanceDay .dVal{ font-size:0.9rem; font-weight:700; margin-top:0.2rem; }

.toast{ position:fixed; bottom:24px; left:50%; transform:translateX(-50%); background:var(--text); color:#fff; padding:0.7rem 1.2rem; border-radius: var(--radius-pill); font-size:0.85rem; z-index:9999; box-shadow: var(--shadow-card-hover); max-width:90%; text-align:center; }

.footNote{ text-align:center; font-size:0.76rem; color:var(--text-muted); margin-top:2rem; }

@media print{
  header.shopHeader, .tabBar, .periodPills, .periodControls, .formActions, .logoutBtn, .ledgerWrap, button{ display:none !important; }
  body{ background:#fff; }
  .card{ box-shadow:none; border:1px solid #ccc; }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px){
  body{ padding-bottom: 2rem; }
  .wrap{ padding: 0 0.9rem; }

  header.shopHeader{ padding: 0.8rem 0.9rem; margin: 0 -0.9rem 1.2rem; gap:0.6rem; }
  .shopName{ font-size: 1.05rem; }
  .shopTag{ font-size: 0.74rem; }
  .headerLogo{ width:36px; height:36px; }
  .headerRight{ gap:0.5rem; }
  .userName{ display:none; } /* role pill still shows below; saves horizontal space on small screens */
  .userBadge{ text-align:right; }
  .logoutBtn{ padding:0.45rem 0.8rem; font-size:0.78rem; }

  .card{ padding: 1.1rem 1rem; border-radius: 12px; }
  .cardTitle{ font-size: 0.98rem; }

  /* Tabs scroll horizontally instead of wrapping into a tall stack */
  .tabBar{ width:auto; max-width:100%; overflow-x:auto; flex-wrap:nowrap; -webkit-overflow-scrolling:touch; padding:0.25rem; }
  .tabBar::-webkit-scrollbar{ height:4px; }
  .tabBtn{ flex-shrink:0; padding:0.5rem 0.9rem; font-size:0.8rem; }

  .marketTabBar{ width:auto; max-width:100%; overflow-x:auto; flex-wrap:nowrap; -webkit-overflow-scrolling:touch; }
  .marketTabBtn{ flex-shrink:0; }

  .fieldRow{ grid-template-columns: 1fr; }
  .addUserGrid{ grid-template-columns: 1fr; }

  .metricGrid{ grid-template-columns: repeat(2, 1fr); gap:0.6rem; }
  .metricCard{ padding:0.75rem 0.8rem; }
  .metricValue{ font-size:1.08rem; }

  .compareGrid{ grid-template-columns: 1fr; gap:0.7rem; }

  .userRow{ grid-template-columns: 1fr; gap:0.3rem; padding:0.8rem 0; }
  .userRow.headRow{ display:none; } /* column headers don't make sense once rows stack */
  .userRow .actionsCell{ margin-top:0.3rem; }

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

  .periodPills{ overflow-x:auto; flex-wrap:nowrap; -webkit-overflow-scrolling:touch; padding-bottom:0.2rem; }
  .periodPill{ flex-shrink:0; }
  .periodControls select, .periodControls input{ width:100%; }
  .periodControls{ flex-direction:column; align-items:stretch; }

  .formActions{ flex-direction:column; align-items:stretch; }
  .formActions .primaryBtn, .formActions .ghostBtn{ width:100%; text-align:center; }

  .loginWrap{ margin: 1.2rem auto; max-width: 100%; }
  .heroPhoto{ height:170px; }
  .heroLoginBody{ padding:1.4rem 1.2rem 1.6rem; }

  table.ledger, .recentTable{ min-width:720px; } /* keep readable inside the horizontal scroll rather than crushing columns */
}
