/* Creslane Reports — modern UI. Self-contained: system fonts, no external assets. */

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #059669;
  --accent-2: #10b981;
  --accent-soft: #d1fae5;
  --accent-ink: #ffffff;
  --danger-bg: #fef2f2;
  --danger-ink: #b91c1c;
  --danger-line: #fecaca;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px rgba(15, 23, 42, .08);
  --shadow-lg: 0 4px 12px rgba(15, 23, 42, .10), 0 20px 48px rgba(15, 23, 42, .16);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, Inter, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text-center { text-align: center; }

@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
  margin: .85rem 0;
}

.alert {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  padding: .7rem 1rem;
  margin: .85rem 0;
  font-size: .95rem;
  animation: rise-in .25s ease both;
}

/* ============ Login ============ */

#login-view {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(16, 185, 129, .35), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(5, 150, 105, .28), transparent 55%),
    linear-gradient(160deg, #0f172a 0%, #123c33 55%, #0f172a 100%);
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  padding: 8vh 1.25rem 2rem;
  animation: rise-in .4s ease both;
}

.brand {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0 0 .3rem;
  color: #fff;
}
.brand::before {
  content: "";
  display: block;
  width: 52px;
  height: 52px;
  margin: 0 auto .8rem;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 20px rgba(16, 185, 129, .45);
  /* bar-chart glyph */
  -webkit-mask: none;
  background-image:
    linear-gradient(#fff, #fff), linear-gradient(#fff, #fff), linear-gradient(#fff, #fff),
    linear-gradient(135deg, var(--accent-2), var(--accent));
  background-size: 6px 14px, 6px 22px, 6px 18px, 100% 100%;
  background-position: 14px 30px, 23px 22px, 32px 26px, 0 0;
  background-repeat: no-repeat;
}
.login-wrap .muted { color: #94b8ac; }

#login-view .card {
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow-lg);
  padding: 1.1rem;
}

.pin-display {
  font-size: 1.9rem;
  line-height: 1;
  letter-spacing: .55rem;
  height: 3.6rem;            /* fixed so typing a PIN never resizes the box */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--accent);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: .8rem;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .55rem;
}
/* Stop the browser's double-tap-to-zoom on the keypad area (taps are UI, not content). */
.pin-pad, .pin-pad * { touch-action: manipulation; }

.pin-key {
  font-size: 1.45rem;
  font-weight: 600;
  padding: .8rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .06s ease, background .12s ease;
}
.pin-key:active { transform: scale(.94); background: #e2e8f0; }
.key-muted { color: var(--muted); font-weight: 400; }
.key-go {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
}
.key-go:active { transform: scale(.94); filter: brightness(.92); }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: .9rem;
  padding: .55rem;
}
#login-view .link-btn { color: #7ea99b; }

.field-label { font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; letter-spacing: .02em; }

/* ============ App chrome ============ */

.topbar {
  display: flex;
  align-items: center;
  gap: .8rem;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  padding: .65rem 1.1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-weight: 700; letter-spacing: -.01em; flex: 1; }
.topbar-title::before {
  content: "";
  display: inline-block;
  vertical-align: -4px;
  width: 20px;
  height: 20px;
  margin-right: .55rem;
  border-radius: 6px;
  background-image:
    linear-gradient(#fff, #fff), linear-gradient(#fff, #fff), linear-gradient(#fff, #fff),
    linear-gradient(135deg, var(--accent-2), var(--accent));
  background-size: 2.5px 5px, 2.5px 9px, 2.5px 7px, 100% 100%;
  background-position: 5px 11px, 8.75px 7px, 12.5px 9px, 0 0;
  background-repeat: no-repeat;
}
.topbar-user { display: flex; align-items: center; gap: .35rem; }
.topbar-user #userName {
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: .3rem .8rem;
}
.topbar-user .link-btn { color: var(--muted); }
.back-btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: .38rem .9rem;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  touch-action: manipulation;
}
.back-btn:active { background: #e2e8f0; }

.content { max-width: 1150px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

/* ============ Report catalog ============ */

.report-grid { animation: rise-in .3s ease both; }
.category-title {
  margin: 1.5rem 0 .7rem;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.category-title:first-child { margin-top: .25rem; }
.category-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: .85rem;
}
.report-tile {
  display: flex;
  align-items: flex-start;
  gap: .8rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.report-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: #bbe7d3; }
.report-tile:active { transform: translateY(0); }
.tile-icon {
  flex: none;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border-radius: 12px;
  background: var(--accent-soft);
}
.report-tile h3 { margin: .1rem 0 .3rem; font-size: 1rem; letter-spacing: -.01em; }
.report-tile p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.35; }

/* ============ Parameter form ============ */

#report-screen h2 { margin: .4rem 0 .2rem; font-size: 1.5rem; letter-spacing: -.02em; }
#report-screen > .muted { margin: 0 0 1rem; }

.param-form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1rem .35rem;
  margin: .9rem 0 1.1rem;
}
.param-row { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: .75rem; }
.param-row:empty { display: none; }
.param { display: flex; flex-direction: column; min-width: 160px; }

input, select {
  font-size: 1rem;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--ink);
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); background: #fff; }

.param-check {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  cursor: pointer;
}
.param-check input { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); }

.btn {
  font-size: 1rem;
  font-weight: 600;
  padding: .65rem 1.6rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(5, 150, 105, .35);
  touch-action: manipulation;
  transition: transform .08s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .6; box-shadow: none; }
.btn-run { margin-bottom: .75rem; }

.loading { display: flex; align-items: center; gap: .6rem; color: var(--muted); padding: 1rem 0; }
.loading::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ============ Results ============ */

#results { animation: rise-in .3s ease both; }

.result-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .4rem 1.25rem;
  margin: .6rem 0 .4rem;
}
.result-header .store { font-weight: 700; font-size: 1.05rem; }
.result-header .muted {
  font-size: .85rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .2rem .75rem;
}

.summary-chips { display: flex; flex-wrap: wrap; gap: .6rem; margin: .6rem 0 1.1rem; }
.chip {
  min-width: 130px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-2);
  border-radius: var(--radius-sm);
  padding: .55rem .85rem;
  box-shadow: var(--shadow-sm);
}
.chip .chip-label {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .15rem;
}
.chip .chip-value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

.section-title {
  margin: 1.4rem 0 .5rem;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.csv-btn {
  order: 2;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: .22rem .7rem;
  cursor: pointer;
  color: var(--muted);
  transition: color .12s ease, border-color .12s ease;
}
.csv-btn:hover { color: var(--accent); border-color: var(--accent-2); }

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: .55rem .8rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th {
  background: #f8fafc;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  position: sticky;
  top: 0;
}
td { color: var(--ink-soft); }
td:first-child { font-weight: 600; color: var(--ink); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:nth-child(even) td { background: #fbfcfe; }
tbody tr:hover td { background: #ecfdf5; }
tr:last-child td { border-bottom: none; }

.kv-table td:first-child { color: var(--muted); font-weight: 500; width: 40%; }
.kv-table td.num { font-weight: 600; color: var(--ink); }

.empty-note { color: var(--muted); font-style: italic; padding: .5rem 0; }

/* ============ Product lookup ============ */

.lookup-param { flex: 1 1 260px; }
.scan-field {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  padding: .65rem .8rem;
}

.lookup-param { position: relative; }
.search-pop {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  z-index: 40;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 340px;
  overflow-y: auto;
  animation: rise-in .12s ease both;
}
.search-hit {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: .55rem .8rem;
  cursor: pointer;
  touch-action: manipulation;
}
.search-hit:last-child { border-bottom: none; }
.search-hit:hover, .search-hit:focus { background: var(--accent-soft); outline: none; }
.hit-main { flex: 1; min-width: 0; }
.hit-desc { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hit-desc.hit-inactive { color: var(--muted); text-decoration: line-through; }
.hit-sub { display: flex; gap: .6rem; font-size: .74rem; color: var(--muted); }
.hit-upc { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.hit-off { color: var(--danger-ink); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.hit-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.search-empty { padding: .7rem .9rem; color: var(--muted); font-style: italic; }

.product-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.1rem 1.2rem .6rem;
  margin: .6rem 0 1rem;
}
.prod-desc { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; }
.prod-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; margin: .45rem 0 .3rem; }
.prod-upc {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .95rem;
  color: var(--ink-soft);
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .15rem .55rem;
}
.prod-tag {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 999px;
  padding: .22rem .65rem;
}
.prod-tag.tag-ok { color: var(--accent); background: var(--accent-soft); }
.prod-tag.tag-off { color: var(--danger-ink); background: var(--danger-bg); }
.prod-chips { margin: .7rem 0 .5rem; }
.chip-stock { border-left-color: #0ea5e9; }

/* ============ Calendar popup ============ */

.date-field { cursor: pointer; caret-color: transparent; }

.cal {
  position: absolute;
  z-index: 50;
  width: 292px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .7rem;
  animation: rise-in .15s ease both;
  touch-action: manipulation;
}
.cal-head { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem; }
.cal-sel {
  flex: 1;
  font-size: .92rem;
  font-weight: 600;
  padding: .4rem .35rem;
  min-width: 0;
}
.cal-sel-year { flex: 0 0 5.2rem; }
.cal-nav {
  width: 2.2rem;
  height: 2.2rem;
  font-size: 1.25rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  color: var(--ink);
  cursor: pointer;
}
.cal-nav:active { background: #e2e8f0; }
.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .25rem;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-day {
  height: 2.35rem;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-size: .92rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  cursor: pointer;
}
.cal-day:hover { background: var(--accent-soft); }
.cal-day:active { transform: scale(.92); }
.cal-day.is-today { box-shadow: inset 0 0 0 1.5px var(--accent-2); }
.cal-day.is-selected {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 700;
}
.cal-foot { display: flex; justify-content: flex-end; margin-top: .45rem; }
.cal-today {
  font-size: .8rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: .3rem .5rem;
}

@media (max-width: 480px) {
  .content { padding: .9rem .75rem 3rem; }
  .category-grid { grid-template-columns: 1fr; }
  .param { flex: 1 1 46%; min-width: 0; }
  .chip { flex: 1 1 44%; min-width: 0; }
  .topbar-user #userName { display: none; }
}

@media print {
  .topbar, .param-form, .csv-btn, .back-btn { display: none !important; }
  body { background: #fff; }
  .table-wrap, .chip { box-shadow: none; }
}
