* {
  box-sizing: border-box;
}

:root {
  --ink: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --bg: #fafaf9;
  --card: #ffffff;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --bad: #b42318;
  --bad-soft: #fef3f2;
  --good: #067647;
  --good-soft: #ecfdf3;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

/* Keep focused fields and scrolled-to content clear of the sticky header. */
html {
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  min-height: 100dvh;
}

.app {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h3 {
  margin: 28px 0 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- header ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(250, 250, 249, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.brand.home {
  font: inherit;
  font-weight: 700;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.brand.big {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  font-size: 0.95rem;
}

.brand.big .mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 1.3rem;
}

.pill {
  font: inherit;
  font-size: 0.85rem;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}

/* ---------- forms and buttons ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 6px;
}

label .muted {
  font-weight: 400;
}

input {
  font: inherit;
  font-size: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 100%;
  background: var(--card);
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

input[aria-invalid="true"] {
  border-color: var(--bad);
  background: var(--bad-soft);
}

/* A unit inside the box: "₹ 395", "62.75 Mts". */
.affix {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.affix .prefix,
.affix .suffix {
  position: absolute;
  color: var(--muted);
  pointer-events: none;
}

.affix .prefix {
  left: 14px;
}

.affix .suffix {
  right: 14px;
  font-size: 0.9rem;
}

.affix .prefix + input {
  padding-left: 30px;
}

#f-weightTo {
  padding-left: 40px;
}

.affix input:has(+ .suffix) {
  padding-right: 52px;
}

.link-btn {
  font: inherit;
  font-size: 0.9rem;
  justify-self: start;
  align-self: center;
  padding: 10px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.field-hint {
  font-size: 0.82rem;
  color: var(--muted);
}

.field-hint:empty {
  display: none;
}

.field-error {
  font-size: 0.85rem;
}

fieldset.field {
  border: 0;
  margin: 0;
  padding: 0;
}

fieldset.field legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0;
  margin: 6px 0 6px;
}

fieldset.field legend .muted {
  font-weight: 400;
}

.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.btn:active,
.tile:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.btn.big {
  padding: 18px;
  font-size: 1.1rem;
  margin-top: 12px;
}

.btn.ghost {
  border-color: transparent;
  background: none;
  color: var(--muted);
}

.back {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 12px -6px;
  padding: 6px;
  border: 0;
  background: none;
  color: var(--muted);
}

.error {
  color: var(--bad);
  font-size: 0.95rem;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 10px;
}

/* ---------- login ---------- */

.login {
  padding-top: 18vh;
}

/* ---------- scan ---------- */

.viewfinder {
  position: relative;
  aspect-ratio: 1;
  background: #0b0b0c;
  border-radius: 24px;
  overflow: hidden;
}

.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.corners {
  position: absolute;
  inset: 20%;
}

.corners span {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid #fff;
}

.corners span:nth-child(1) {
  top: 0;
  left: 0;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 14px;
}

.corners span:nth-child(2) {
  top: 0;
  right: 0;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 14px;
}

.corners span:nth-child(3) {
  bottom: 0;
  left: 0;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 14px;
}

.corners span:nth-child(4) {
  bottom: 0;
  right: 0;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 14px;
}

.sweep {
  position: absolute;
  left: 22%;
  right: 22%;
  top: 22%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #a5b4fc, transparent);
  animation: sweep 2.2s ease-in-out infinite alternate;
}

@keyframes sweep {
  to {
    top: 78%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sweep {
    animation: none;
    top: 50%;
  }
}

.hint {
  text-align: center;
  color: var(--muted);
  margin: 14px 0 18px;
}

.manual {
  display: flex;
  gap: 8px;
}

.manual .btn {
  width: auto;
  padding: 14px 20px;
}

/* ---------- fabric card ---------- */

.fabric {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.fabric .name {
  font-size: 1.5rem;
  font-weight: 750;
  line-height: 1.2;
}

.fabric .color {
  font-size: 1.1rem;
  margin-top: 4px;
}

.fabric .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.tag {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: #f4f4f5;
  color: #3f3f46;
}

.tag.warn {
  background: var(--bad-soft);
  color: var(--bad);
  font-family: inherit;
  font-weight: 600;
}

/* ---------- choice ---------- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 14px 0 6px;
}

.tile {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 150px;
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.tile .icon {
  width: 30px;
  height: 30px;
  margin-bottom: auto;
}

.tile.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.tile-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.tile-sub {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* ---------- notices ---------- */

.notice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.notice .icon {
  width: 24px;
  height: 24px;
  margin-top: 2px;
}

.notice h2 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.notice.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.notice.bad p {
  color: #7a271a;
}

.notice.good {
  background: var(--good-soft);
  color: var(--good);
}

.notice.good p {
  color: #05603a;
}

/* ---------- label ---------- */

/* Same frame as the draft and saved label, so the label looks identical on every screen. */
.label-preview {
  margin: 0 -8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

.label-preview canvas {
  display: block;
  width: 100%;
  aspect-ratio: 70 / 25;
}

.small {
  font-size: 0.85rem;
  margin: 8px 2px 14px;
}





.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  padding: 4px 2px;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  padding: 0;
  margin: 0;
  accent-color: var(--ink);
}

.more {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--card);
}

.more summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.more summary::-webkit-details-marker {
  display: none;
}

.more summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
}

.more[open] summary::after {
  transform: rotate(-135deg) translate(-2px, 0);
}

.more[open] {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  vertical-align: 1px;
  background: #f4f4f5;
  color: var(--muted);
}

.badge.shared {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.printed {
  background: #fff7ed;
  color: #c2410c;
}

.badge.applied {
  background: var(--good-soft);
  color: var(--good);
}

.badge.voided {
  background: var(--bad-soft);
  color: var(--bad);
  text-decoration: line-through;
}

.big-badge {
  margin: 0;
  font-size: 0.9rem;
  padding: 4px 12px;
}

.bar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ghost-pill {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-pill:empty {
  display: none;
}

.label-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.label-id {
  font-family: ui-monospace, Menlo, "Roboto Mono", monospace;
  font-size: 1.35rem;
  font-weight: 700;
}


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

select {
  font: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
}

.timeline {
  list-style: none;
  margin: 0 0 16px;
  padding: 0 0 0 14px;
  border-left: 2px solid var(--line);
}

.timeline li {
  position: relative;
  padding: 0 0 14px 14px;
}

.timeline li::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--muted);
}

.timeline li.applied::before {
  border-color: var(--good);
  background: var(--good);
}

.timeline li.voided::before {
  border-color: var(--bad);
  background: var(--bad);
}

.timeline .what {
  font-weight: 600;
}

.timeline .sub {
  color: var(--muted);
  font-size: 0.88rem;
}

/* Draft and saved label: one vertical rhythm, the label as wide as the phone allows. */
#screen-draft,
#screen-printed {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#screen-draft > *,
#screen-printed > * {
  margin: 0;
}

#screen-draft .back {
  align-self: flex-start;
  margin: -4px 0 -8px -6px;
}

#screen-draft .label-image,
#screen-printed .label-image {
  width: calc(100% + 16px);
  margin: 4px -8px;
  border-radius: 10px;
}

#screen-draft .btn.ghost,
#screen-printed .btn.ghost {
  margin-top: -8px;
}

#draft-status,
#printed-status {
  margin-top: -8px;
}

.menu,
.section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.menu > summary,
.section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.menu > summary::-webkit-details-marker,
.section > summary::-webkit-details-marker {
  display: none;
}

.menu > summary::after,
.section > summary::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
}

.menu[open] > summary::after,
.section[open] > summary::after {
  transform: rotate(-135deg) translate(-2px, 0);
}

.section > summary .muted {
  font-weight: 400;
  margin-right: auto;
}

.menu-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.menu-item {
  font: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:first-child {
  border-top: 0;
}

.menu-item[hidden] + .menu-item {
  border-top: 0;
}

.menu-item.bad {
  color: var(--bad);
}

.void-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  background: var(--bad-soft);
  border-radius: 0 0 12px 12px;
}

.void-form label {
  margin: 0;
}

.section .timeline {
  margin: 0 16px 16px 24px;
}

.section .timeline li:last-child {
  padding-bottom: 0;
}

a.btn {
  text-decoration: none;
}

.label-image {
  display: block;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

/* ---------- info ---------- */

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.fact {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.fact .k {
  font-size: 0.78rem;
  color: var(--muted);
}

.fact .v {
  font-size: 1.05rem;
  font-weight: 650;
  margin-top: 2px;
  word-break: break-word;
}

.fields {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.fields div {
  display: grid;
  grid-template-columns: minmax(110px, 42%) 1fr;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.fields div:first-child {
  border-top: 0;
}

.fields dt {
  color: var(--muted);
}

.fields dd {
  margin: 0;
  word-break: break-word;
}

.history {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.history .when {
  font-weight: 600;
}

.history .sub {
  font-size: 0.9rem;
  color: var(--muted);
}

.history .changed {
  font-size: 0.88rem;
  color: var(--bad);
  margin-top: 2px;
}

.history .pill {
  flex: none;
}

.sticky {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
  margin: 20px -16px -32px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
