/* Thamardi Trace — all styles for field / ops / verify surfaces.
   ponytail: one stylesheet, no preprocessor, no framework. */

:root {
  --ruby-900: #3d0c11;
  --ruby-700: #6b1f2a;
  --ruby-500: #9c2726;
  --ruby-100: #f0dfdd;
  --ink: #52514e;
  --ink-strong: #1f1d1b;
  --paper: #f7f4f0;
  --paper-2: #efe9e2;
  --card: #fffdfb;
  --line: #ddd5cb;
  --gold: #b08d57;
  --good: #2f6b46;
  --warn: #8a5a12;
  --bad: #a32b2b;
  --font-sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-ja: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", var(--font-sans);
  --space: 1.5rem;
  --radius: 10px;
  --shadow: 0 1px 3px rgb(61 12 17 / 0.08);
  --shadow-lg: 0 8px 28px rgb(61 12 17 / 0.12);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink-strong);
  line-height: 1.55;
  font-size: 16px;
}

:lang(ja) { font-family: var(--font-ja); }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
a { color: var(--ruby-700); }

:focus-visible {
  outline: 2.5px solid var(--ruby-500);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- app chrome */

.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--ruby-900);
  color: #fff;
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand {
  font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  font-size: 0.82rem; margin-right: auto;
}
.topbar .brand small {
  display: block; letter-spacing: 0.18em; opacity: 0.62;
  font-size: 0.62rem; font-weight: 500;
}
.topbar a, .topbar button { color: #fff; }

.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
  background: var(--paper-2); color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.ok { background: #e7f0ea; color: var(--good); border-color: #c3ddcd; }
.chip.warn { background: #f7edda; color: var(--warn); border-color: #e6d3ab; }
.chip.bad { background: #f6e2e2; color: var(--bad); border-color: #e5c0c0; }
.chip.ruby { background: var(--ruby-100); color: var(--ruby-700); border-color: #e0c3c0; }
.topbar .chip { background: rgb(255 255 255 / 0.14); color: #fff; border-color: rgb(255 255 255 / 0.22); }

main { padding: var(--space) 1rem 5.5rem; max-width: 1180px; margin: 0 auto; }

/* ---------------------------------------------------------------- nav */

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 0.6rem 0.25rem;
  font-size: 0.7rem; color: var(--ink); text-decoration: none;
  min-height: 52px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.tabbar a[aria-current="page"] { color: var(--ruby-700); font-weight: 650; }
.tabbar .ico { font-size: 1.15rem; line-height: 1; }

.sidenav { display: none; }

/* ---------------------------------------------------------------- cards, grids */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
.grid.two { grid-template-columns: 1fr; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--ink); font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }

/* stat callout — gold numeral over tracked label (provenanceproof-style) */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1rem;
}
.stat .n {
  font-size: 1.65rem; font-weight: 300; color: var(--gold);
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.stat .l {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink); margin-top: 0.3rem;
}

/* ---------------------------------------------------------------- forms */

label { display: block; font-size: 0.8rem; font-weight: 600; margin: 0 0 0.3rem; color: var(--ink-strong); }
.field { margin-bottom: 1rem; }
.hint { font-size: 0.75rem; color: var(--ink); margin-top: 0.25rem; }

input, select, textarea {
  width: 100%; padding: 0.7rem 0.75rem; font: inherit; font-size: 1rem;
  background: #fff; color: var(--ink-strong);
  border: 1px solid var(--line); border-radius: 8px; min-height: 44px;
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; margin-right: 0.4rem; }
input:invalid { border-color: var(--bad); }
.err { color: var(--bad); font-size: 0.8rem; margin-top: 0.3rem; font-weight: 600; }

button, .btn {
  font: inherit; font-weight: 650; cursor: pointer;
  padding: 0.7rem 1.1rem; min-height: 44px;
  border-radius: 8px; border: 1px solid transparent;
  background: var(--ruby-700); color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
}
button:hover, .btn:hover { background: var(--ruby-900); }
button.secondary, .btn.secondary { background: transparent; color: var(--ruby-700); border-color: var(--line); }
button.secondary:hover, .btn.secondary:hover { background: var(--paper-2); }
button.ghost { background: transparent; color: var(--ink); border-color: transparent; padding: 0.4rem 0.5rem; }
button.danger { background: var(--bad); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.wide, .btn.wide { width: 100%; }

/* ---------------------------------------------------------------- tables */

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink); font-weight: 700; background: var(--paper-2);
  position: sticky; top: 0;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--paper-2); }
tr.total td { font-weight: 700; background: var(--paper-2); border-top: 2px solid var(--ink-strong); }

/* ---------------------------------------------------------------- lists & timeline */

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  border-bottom: 1px solid var(--line); padding: 0.75rem 0;
  display: flex; gap: 0.75rem; align-items: center;
}
.list li:last-child { border-bottom: 0; }
.list a { text-decoration: none; color: inherit; flex: 1; }
.thumb {
  width: 52px; height: 52px; border-radius: 8px; object-fit: cover;
  background: var(--paper-2); border: 1px solid var(--line); flex: none;
}

.timeline { list-style: none; margin: 0; padding: 0 0 0 1.25rem; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.timeline li { position: relative; padding: 0 0 1rem; }
.timeline li::before {
  content: ""; position: absolute; left: -1.25rem; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ruby-500); border: 2px solid var(--paper);
}
.timeline li.pending::before { background: var(--line); }
.timeline .t-when { font-size: 0.72rem; color: var(--ink); letter-spacing: 0.04em; }
.timeline .t-what { font-weight: 650; }

/* ---------------------------------------------------------------- misc components */

.wizard-steps { display: flex; gap: 0.35rem; margin-bottom: 1rem; }
.wizard-steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.wizard-steps span.done { background: var(--ruby-500); }

.sigpad {
  width: 100%; height: 150px; background: #fff;
  border: 1px dashed var(--line); border-radius: 8px; touch-action: none; display: block;
}

.photobox {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 0.5rem; margin-top: 0.5rem;
}
.photobox img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

.toast {
  position: fixed; left: 50%; bottom: 5rem; transform: translateX(-50%);
  background: var(--ink-strong); color: #fff; padding: 0.7rem 1.1rem;
  border-radius: 999px; z-index: 60; box-shadow: var(--shadow-lg);
  font-size: 0.85rem; max-width: 90vw; text-align: center;
}
.toast.bad { background: var(--bad); }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; max-width: 440px; width: calc(100vw - 2rem);
  box-shadow: var(--shadow-lg); background: var(--card); color: var(--ink-strong);
}
dialog::backdrop { background: rgb(31 29 27 / 0.45); }

.empty { text-align: center; color: var(--ink); padding: 2.5rem 1rem; }
.empty .ico { font-size: 2rem; opacity: 0.35; display: block; margin-bottom: 0.5rem; }

.banner {
  border-left: 4px solid var(--warn); background: #f7edda;
  padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.85rem;
}
.banner.bad { border-left-color: var(--bad); background: #f6e2e2; }
.banner.ok { border-left-color: var(--good); background: #e7f0ea; }

.qr { display: block; width: 100%; max-width: 190px; height: auto; }

video.scanner {
  width: 100%; border-radius: var(--radius); background: #000;
  aspect-ratio: 3/4; object-fit: cover;
}

/* ---------------------------------------------------------------- verify (consumer) */

.v-hero {
  background: var(--ruby-900); color: #fff;
  padding: 2.5rem 1.25rem; text-align: center;
}
.v-hero .brand {
  letter-spacing: 0.28em; text-transform: uppercase; font-size: 0.72rem;
  opacity: 0.8; margin-bottom: 0.75rem;
}
.v-hero h1 { font-size: 1.7rem; font-weight: 300; margin-bottom: 0.35rem; }
.v-hero .verified {
  display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 0.75rem;
  background: rgb(255 255 255 / 0.12); border: 1px solid rgb(255 255 255 / 0.25);
  padding: 0.35rem 0.9rem; border-radius: 999px; font-size: 0.8rem;
}
.v-photo { width: 100%; max-width: 420px; margin: 0 auto; display: block; border-radius: var(--radius); }
.v-section { max-width: 640px; margin: 0 auto; padding: 2rem 1.25rem; }
.v-section h2 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--ink); font-weight: 700; margin-bottom: 1rem;
}
.v-foot {
  border-top: 1px solid var(--line); text-align: center;
  padding: 2rem 1.25rem 3rem; color: var(--ink); font-size: 0.8rem;
}

/* ---------------------------------------------------------------- desktop */

@media (min-width: 760px) {
  main { padding: 2.5rem 2rem 3rem; }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat .n { font-size: 2.1rem; }
  h1 { font-size: 1.85rem; }
  .card { padding: 1.35rem; }
}

/* ops shell gets a sidebar instead of a tabbar on wide screens */
@media (min-width: 1000px) {
  body.ops { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
  body.ops .topbar { grid-column: 1 / -1; }
  body.ops .tabbar { display: none; }
  body.ops .sidenav {
    display: block; background: var(--card); border-right: 1px solid var(--line);
    padding: 1.25rem 0.75rem;
  }
  body.ops .sidenav a {
    display: block; padding: 0.55rem 0.75rem; border-radius: 8px;
    color: var(--ink); text-decoration: none; font-size: 0.88rem; margin-bottom: 2px;
  }
  body.ops .sidenav a:hover { background: var(--paper-2); }
  body.ops .sidenav a[aria-current="page"] {
    background: var(--ruby-100); color: var(--ruby-700); font-weight: 650;
  }
  body.ops main { padding: 2rem 2.5rem 4rem; max-width: none; }
}

/* ---------------------------------------------------------------- print: warranty cards & stone labels */

@media print {
  .topbar, .tabbar, .sidenav, .noprint, button { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }

  .warranty {
    width: 85mm; height: 54mm; border: 1px solid #000; border-radius: 3mm;
    padding: 4mm; display: grid; grid-template-columns: 1fr 26mm;
    gap: 3mm; break-inside: avoid; margin: 0 4mm 4mm 0; float: left;
  }
  .label-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm; }
  .stone-label {
    border: 1px solid #000; border-radius: 2mm; padding: 3mm;
    text-align: center; break-inside: avoid; font-size: 8pt;
  }
  .stone-label .qr { max-width: 24mm; margin: 0 auto 1mm; }
  @page { margin: 10mm; }
}

.warranty {
  width: 85mm; min-height: 54mm; border: 1px solid var(--line); border-radius: 6px;
  padding: 4mm; display: grid; grid-template-columns: 1fr 26mm; gap: 3mm;
  background: #fff; margin-bottom: 1rem;
}
.warranty .brand { letter-spacing: 0.2em; text-transform: uppercase; font-size: 7pt; color: var(--ruby-700); font-weight: 700; }
.warranty dl { margin: 0.5rem 0 0; font-size: 7.5pt; }
.warranty dt { color: var(--ink); font-size: 6.5pt; text-transform: uppercase; letter-spacing: 0.06em; }
.warranty dd { margin: 0 0 0.35rem; font-weight: 600; }

.label-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }
.stone-label {
  border: 1px solid var(--line); border-radius: 6px; padding: 0.6rem;
  text-align: center; background: #fff; font-size: 0.7rem;
}
.stone-label .qr { max-width: 110px; margin: 0 auto 0.35rem; }
.stone-label .id { font-family: ui-monospace, Menlo, monospace; font-size: 0.62rem; word-break: break-all; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------- sign-in */

.authwrap {
  position: fixed; inset: 0; z-index: 100;
  background: var(--paper);
  display: grid; place-items: center;
  padding: 1rem; overflow-y: auto;
}
.authcard {
  width: 100%; max-width: 420px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 1.5rem;
}
.authhead { text-align: center; margin-bottom: 1.25rem; }
.authhead .brand {
  letter-spacing: 0.28em; text-transform: uppercase; font-size: 0.7rem;
  color: var(--ruby-700); font-weight: 700; margin-bottom: 0.75rem;
}
.authhead h1 { font-size: 1.3rem; margin-bottom: 0.25rem; }
.authhead .avatar { margin: 0 auto 0.75rem; }

.avatar {
  display: inline-grid; place-items: center; border-radius: 50%;
  color: #fff; font-weight: 700; flex: none; line-height: 1;
  font-family: var(--font-sans);
}

.authlist { margin-bottom: 1rem; }
.authlist li { border-bottom: 1px solid var(--line); padding: 0; }

/* Whole row is the target — WCAG 2.5.5 asks 44px; rows run taller than that. */
.accountrow {
  display: flex; align-items: center; gap: 0.75rem; width: 100%;
  padding: 0.7rem 0.4rem; min-height: 60px;
  background: none; border: 0; border-radius: 8px;
  color: inherit; text-align: left; font: inherit; font-weight: 400;
}
.accountrow:hover { background: var(--paper-2); }
.accountrow .who { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.accountrow .who strong { font-weight: 650; }
.accountrow .chev { color: var(--muted, #898781); font-size: 1.2rem; }

.authfoot { border-top: 1px solid var(--line); padding-top: 1rem; }
.authfoot button { margin-bottom: 0.5rem; }
.authnote {
  margin: 0.75rem 0 0; line-height: 1.45;
  color: var(--ink); opacity: 0.85;
}

/* PIN entry */
.pindots {
  text-align: center; font-size: 2rem; letter-spacing: 0.5rem;
  font-variant-numeric: tabular-nums; margin: 0.5rem 0 0.75rem;
  min-height: 2.4rem; color: var(--ink-strong);
}
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; margin-top: 0.75rem;
}
.keypad button {
  min-height: 60px; font-size: 1.35rem; font-weight: 500;
  background: var(--paper-2); color: var(--ink-strong); border: 1px solid var(--line);
}
.keypad button:hover { background: var(--line); }
.keypad button.ghost {
  background: transparent; border-color: transparent; font-size: 1rem; color: var(--ink);
}

@media (min-width: 760px) {
  .authcard { padding: 2rem; }
  .keypad button { min-height: 54px; }
}
