/* Import desk. The look borrows from shipping labels: heavy ink rules on white
   stock, condensed sort-code lettering, a barcode that scans while work runs. */

:root {
  --ink: #14213A;        /* harbour navy: text, rules, the user's messages */
  --paper: #F1F3EF;      /* the desk */
  --sheet: #FFFFFF;      /* label stock */
  --tide: #0E6B78;       /* links, focus, quiet actions */
  --signal: #F2B705;     /* hazard yellow: the one thing to press, work in progress */
  --oxide: #B4432B;      /* container red: failures, missing weight */
  --pass: #2B7A57;       /* finished */
  --rule: #CDD3CD;
  --muted: #566176;

  --body: "Instrument Sans", "Noto Sans KR", system-ui, sans-serif;
  --display: "Bricolage Grotesque", "Noto Sans KR", system-ui, sans-serif;

  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: 1.9375rem;
  --step-5: 3.05rem;

  --rail: 17rem;
  --measure: 46rem;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--tide); text-underline-offset: 0.15em; }
:focus-visible { outline: 3px solid var(--tide); outline-offset: 2px; }

.visually-hidden, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip:focus { position: fixed; top: 0.5rem; left: 0.5rem; z-index: 20; background: var(--sheet); padding: 0.5rem 0.75rem; }

/* Condensed lettering for codes and figures, the way a sort code is set on a label. */
.code {
  font-family: var(--display);
  font-stretch: 75%;
  font-variation-settings: "wdth" 75;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* ---- frame ------------------------------------------------------------------ */
.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); height: 100dvh; }

.rail {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--ink); color: #E9EDF2;
  padding: 1.25rem 1rem 1rem;
}
.brand { display: flex; align-items: center; gap: 0.65rem; margin-bottom: 1.5rem; }
.brand img { border: 1.5px solid rgba(255, 255, 255, 0.25); border-radius: 4px; }
.brand-name { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.0625rem; line-height: 1.15; }
.brand-name span { display: block; font-family: var(--body); font-weight: 400; font-size: var(--step--1); opacity: 0.7; }

.rail-new {
  width: 100%; text-align: left;
  background: var(--signal); color: var(--ink);
  border: 0; border-radius: 3px; padding: 0.6rem 0.8rem;
  font-weight: 600;
}
.rail-new:hover { background: #FFC81F; }
.rail-new:focus-visible, .rail .link-button:focus-visible, .rail-list button:focus-visible { outline-color: var(--signal); }

.rail-list { flex: 1; min-height: 0; overflow-y: auto; margin: 1.25rem -0.5rem 0; padding: 0 0.5rem; }
.rail-list ul { list-style: none; margin: 0; padding: 0; }
.rail-list li { position: relative; }
.rail-list .chat-link {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; border-left: 3px solid transparent;
  padding: 0.5rem 2rem 0.5rem 0.65rem;
  color: inherit; font-size: 0.9375rem; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-list .chat-link:hover { background: rgba(255, 255, 255, 0.07); }
.rail-list .chat-link[aria-current="true"] { border-left-color: var(--signal); background: rgba(255, 255, 255, 0.1); font-weight: 600; }
.rail-list .chat-delete {
  position: absolute; right: 0.1rem; top: 50%; transform: translateY(-50%);
  width: 1.75rem; height: 1.75rem; border: 0; border-radius: 3px; background: none; color: inherit;
  opacity: 0; font-size: 1.1rem; line-height: 1;
}
.rail-list li:hover .chat-delete, .rail-list .chat-delete:focus-visible { opacity: 0.75; }
.rail-list .chat-delete:hover { opacity: 1; background: rgba(255, 255, 255, 0.14); }
.rail-empty { margin: 0.25rem 0.65rem; font-size: var(--step--1); opacity: 0.65; }

.rail-foot { border-top: 1px solid rgba(255, 255, 255, 0.16); padding-top: 0.85rem; font-size: var(--step--1); }
.sp-state { margin: 0 0 0.6rem; padding-left: 1.05rem; position: relative; line-height: 1.4; }
.sp-state::before {
  content: ""; position: absolute; left: 0; top: 0.42em; width: 0.55rem; height: 0.55rem; border-radius: 50%;
  background: var(--signal);
}
.sp-state.is-ok::before { background: #5FD0A0; }
.sp-state.is-missing::before { background: #FF8A6B; }
.link-button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; text-underline-offset: 0.15em; opacity: 0.8; }
.link-button:hover { opacity: 1; }

.desk { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.desk-head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1.5px solid var(--ink);
}
.desk-head h1 {
  margin: 0; min-width: 0; font: 600 var(--step-0)/1.3 var(--body);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-toggle { display: none; background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 3px; padding: 0.3rem 0.65rem; font-weight: 600; }
.scrim { position: fixed; inset: 0; background: rgba(20, 33, 58, 0.45); z-index: 5; }

/* ---- thread ----------------------------------------------------------------- */
.thread { overflow-y: auto; scroll-behavior: smooth; }
.thread-inner { max-width: var(--measure); margin: 0 auto; padding: 1.75rem clamp(1rem, 4vw, 2.5rem) 2rem; }
.thread-inner > * + * { margin-top: 1.25rem; }

.welcome { padding-top: clamp(1rem, 9vh, 5.5rem); }
.welcome h2 {
  margin: 0 0 1rem; max-width: 12ch;
  font-family: var(--display); font-weight: 800; font-size: clamp(2.2rem, 6vw, var(--step-5));
  font-stretch: 75%; font-variation-settings: "wdth" 75; line-height: 0.98; letter-spacing: -0.01em;
}
.welcome p { margin: 0; max-width: 34rem; font-size: var(--step-1); line-height: 1.45; color: var(--muted); }
.starters { list-style: none; margin: 2.25rem 0 0; padding: 0; border-top: 1.5px solid var(--ink); max-width: 34rem; }
.starters li { border-bottom: 1px solid var(--rule); }
.starters button {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  width: 100%; text-align: left; background: none; border: 0; padding: 0.8rem 0.25rem; font-weight: 500;
}
.starters button::after {
  content: ""; flex: none; width: 0.55rem; height: 0.55rem;
  border-top: 2px solid var(--ink); border-right: 2px solid var(--ink); transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.starters button:hover { background: var(--sheet); }
.starters button:hover::after { transform: translateX(0.25rem) rotate(45deg); }

.msg-user {
  margin-left: auto; width: fit-content; max-width: min(85%, 36rem);
  background: var(--ink); color: #F4F6F9;
  padding: 0.7rem 0.95rem; border-radius: 3px 3px 0 3px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-user a { color: inherit; }

.msg-ai { max-width: 40rem; overflow-wrap: anywhere; }
.msg-ai > :first-child { margin-top: 0; }
.msg-ai > :last-child { margin-bottom: 0; }
.msg-ai p, .msg-ai ul, .msg-ai ol { margin: 0 0 0.8rem; }
.msg-ai ul, .msg-ai ol { padding-left: 1.3rem; }
.msg-ai li + li { margin-top: 0.25rem; }
.msg-ai h3, .msg-ai h4 { margin: 1.4rem 0 0.5rem; font-family: var(--display); font-weight: 700; line-height: 1.2; }
.msg-ai h3 { font-size: var(--step-1); }
.msg-ai h4 { font-size: 1.0625rem; }
.msg-ai code { background: rgba(20, 33, 58, 0.08); border-radius: 2px; padding: 0.05em 0.3em; font-size: 0.92em; }
.msg-ai pre { background: var(--sheet); border: 1px solid var(--rule); padding: 0.75rem; overflow-x: auto; font-size: var(--step--1); }
.msg-ai pre code { background: none; padding: 0; }
.table-wrap { overflow-x: auto; margin: 0 0 0.9rem; max-width: calc(100vw - 2rem); }
.msg-ai table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; background: var(--sheet); border-top: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); }
.msg-ai th { text-align: left; font-weight: 600; border-bottom: 1.5px solid var(--ink); }
.msg-ai th, .msg-ai td { padding: 0.45rem 0.7rem; vertical-align: top; }
.msg-ai td { border-bottom: 1px solid var(--rule); }
.msg-ai tr:last-child td { border-bottom: 0; }

.notice {
  border-left: 4px solid var(--oxide); background: var(--sheet);
  padding: 0.7rem 0.9rem; max-width: 40rem;
}
.notice strong { display: block; }
.working { color: var(--muted); font-size: 0.9375rem; }

/* ---- the label: one tool action ------------------------------------------- */
.label {
  display: grid; grid-template-columns: 6.25rem minmax(0, 1fr) 5.75rem;
  background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 3px;
  max-width: 40rem;
}
.label-code {
  display: flex; align-items: center; padding: 0.6rem 0.7rem;
  border-right: 1.5px solid var(--ink);
  font-size: var(--step-2); line-height: 1; text-transform: none;
}
.label-body { padding: 0.55rem 0.8rem; min-width: 0; align-self: center; }
.label-what { margin: 0; font-weight: 500; line-height: 1.35; }
.label-meta { margin: 0.1rem 0 0; font-size: var(--step--1); color: var(--muted); }
.label-scan {
  position: relative; overflow: hidden;
  border-left: 1.5px dashed var(--ink);        /* the tear-off stub */
  display: grid; place-items: center;
}
.label-bars {
  position: absolute; inset: 0.55rem 0.6rem;
  background:
    linear-gradient(90deg,
      var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 9px,
      var(--ink) 9px 12px, transparent 12px 14px, var(--ink) 14px 15px, transparent 15px 17px,
      var(--ink) 17px 19px, transparent 19px 23px, var(--ink) 23px 24px, transparent 24px 26px,
      var(--ink) 26px 29px, transparent 29px 31px) 0 0 / 31px 100% repeat-x;
}
.label-stamp {
  position: relative; z-index: 1; display: none;
  background: var(--sheet); border: 2px solid currentColor; border-radius: 2px;
  padding: 0.05rem 0.45rem; transform: rotate(-4deg);
  font-size: 1.0625rem; line-height: 1.3;
}
.label.is-running .label-scan::after {
  content: ""; position: absolute; top: 0.3rem; bottom: 0.3rem; left: 0; width: 3px;
  background: var(--signal); box-shadow: 0 0 0 1px rgba(20, 33, 58, 0.25);
  animation: scan 1.5s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
@keyframes scan { from { transform: translateX(0.5rem); } to { transform: translateX(4.9rem); } }
.label.is-done .label-stamp, .label.is-failed .label-stamp, .label.is-declined .label-stamp, .label.is-waiting .label-stamp { display: block; }
.label.is-done .label-stamp { color: var(--pass); }
.label.is-failed .label-stamp { color: var(--oxide); }
.label.is-declined .label-stamp, .label.is-waiting .label-stamp { color: var(--muted); }
.label.is-done .label-bars, .label.is-failed .label-bars, .label.is-declined .label-bars, .label.is-waiting .label-bars { opacity: 0.2; }
.label.is-failed { border-color: var(--oxide); }
.label.is-failed .label-code, .label.is-failed .label-scan { border-color: var(--oxide); }

.label-detail { grid-column: 1 / -1; border-top: 1.5px solid var(--ink); }
.label-detail summary { padding: 0.4rem 0.8rem; font-size: var(--step--1); font-weight: 600; cursor: pointer; }
.label-detail summary:hover { background: var(--paper); }
.label-detail[open] summary { border-bottom: 1px solid var(--rule); }
.label-raw { margin: 0; padding: 0.7rem 0.8rem; max-height: 18rem; overflow: auto; font: 400 var(--step--1)/1.5 var(--body); white-space: pre-wrap; overflow-wrap: anywhere; }
.label-problem { margin: 0; padding: 0.55rem 0.8rem; grid-column: 1 / -1; border-top: 1.5px solid var(--oxide); color: var(--oxide); font-weight: 500; }

/* Rows inside a label: products read from the supplier, or waiting in 셀러픽. */
.manifest { list-style: none; margin: 0; padding: 0; max-height: 26rem; overflow: auto; }
.manifest li { padding: 0.65rem 0.8rem; }
.manifest li + li { border-top: 1px solid var(--rule); }
.manifest-title { margin: 0; font-weight: 500; line-height: 1.35; }
.manifest-title a { color: inherit; }
.manifest-facts { display: flex; flex-wrap: wrap; gap: 0.15rem 1.1rem; margin: 0.25rem 0 0; font-size: 1.125rem; line-height: 1.3; }
.manifest-facts small { font: 400 var(--step--1)/1 var(--body); color: var(--muted); margin-left: 0.25rem; }
.manifest-facts .no-weight { color: var(--oxide); }
.manifest-sub { margin: 0.2rem 0 0; font-size: var(--step--1); color: var(--muted); overflow-wrap: anywhere; }
.chip { display: inline-block; border: 1.5px solid currentColor; border-radius: 2px; padding: 0 0.35rem; font-size: 0.9375rem; line-height: 1.35; }
.chip.is-done { color: var(--pass); }
.chip.is-failed { color: var(--oxide); }
.chip.is-new, .chip.is-collecting, .chip.is-skipped { color: var(--ink); }

/* ---- confirm ---------------------------------------------------------------- */
.confirm {
  position: relative; max-width: 40rem;
  background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 3px;
  padding: 0.9rem 1rem 1rem 1.85rem;
}
.confirm::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 0.85rem;
  background: repeating-linear-gradient(135deg, var(--signal) 0 8px, var(--ink) 8px 16px);
  border-right: 1.5px solid var(--ink);
}
.confirm h3 { margin: 0; font: 700 var(--step-1)/1.25 var(--display); }
.confirm p { margin: 0.35rem 0 0; color: var(--muted); }
.confirm ul { margin: 0.6rem 0 0; padding: 0; list-style: none; max-height: 9rem; overflow: auto; font-size: 0.9375rem; }
.confirm li { padding: 0.15rem 0; overflow-wrap: anywhere; }
.confirm-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.9rem; }
.btn-go, .btn-quiet { border-radius: 3px; padding: 0.5rem 0.95rem; font-weight: 600; border: 1.5px solid var(--ink); }
.btn-go { background: var(--signal); }
.btn-go:hover { background: #FFC81F; }
.btn-quiet { background: var(--sheet); }
.btn-quiet:hover { background: var(--paper); }
.confirm button:disabled { opacity: 0.55; cursor: default; }

/* ---- composer --------------------------------------------------------------- */
.composer { padding: 0.5rem clamp(1rem, 4vw, 2.5rem) 0.9rem; }
.composer-box {
  display: flex; align-items: flex-end; gap: 0.5rem;
  max-width: var(--measure); margin: 0 auto;
  background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 3px;
  padding: 0.45rem 0.45rem 0.45rem 0.9rem;
  box-shadow: 4px 4px 0 var(--ink);
}
.composer-box:focus-within { box-shadow: 4px 4px 0 var(--tide); border-color: var(--tide); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; background: none; outline: none;
  padding: 0.4rem 0; max-height: 12rem; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.composer button {
  flex: none; background: var(--signal); border: 1.5px solid var(--ink); border-radius: 3px;
  padding: 0.45rem 1.05rem; font-weight: 600;
}
.composer button:hover:not(:disabled) { background: #FFC81F; }
.composer button:disabled { background: var(--paper); color: var(--muted); cursor: default; }
.composer-note { max-width: var(--measure); margin: 0.65rem auto 0; font-size: var(--step--1); color: var(--muted); }
.composer-note.is-warning { color: var(--oxide); }

/* ---- sign-in ---------------------------------------------------------------- */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 1.25rem; }
.login { width: min(100%, 25rem); }
.login-label { background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 3px; box-shadow: 6px 6px 0 var(--ink); }
.login-head { display: flex; align-items: center; gap: 0.7rem; padding: 0.9rem 1.25rem; border-bottom: 1.5px solid var(--ink); }
.login-form { padding: 1.4rem 1.25rem 1.5rem; }
.login-form h1 { margin: 0; font: 800 var(--step-3)/1 var(--display); font-stretch: 75%; font-variation-settings: "wdth" 75; }
.login-form p { margin: 0.5rem 0 1.2rem; color: var(--muted); }
.login-form .login-error { color: var(--oxide); font-weight: 600; border-left: 4px solid var(--oxide); padding-left: 0.6rem; }
.login-form label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.login-form input { width: 100%; border: 1.5px solid var(--ink); border-radius: 3px; padding: 0.6rem 0.7rem; background: var(--sheet); }
.login-form button { margin-top: 1rem; width: 100%; background: var(--signal); border: 1.5px solid var(--ink); border-radius: 3px; padding: 0.65rem; font-weight: 600; }
.login-form button:hover { background: #FFC81F; }
.login-bars {
  height: 2.4rem; margin: 0 1.25rem 1.1rem; border-top: 1.5px dashed var(--ink); padding-top: 0.6rem; background-clip: content-box;
  background-image: linear-gradient(90deg,
      var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 9px,
      var(--ink) 9px 12px, transparent 12px 14px, var(--ink) 14px 15px, transparent 15px 17px,
      var(--ink) 17px 19px, transparent 19px 23px, var(--ink) 23px 24px, transparent 24px 26px,
      var(--ink) 26px 29px, transparent 29px 31px);
  background-size: 31px 100%; background-repeat: repeat-x; background-origin: content-box;
}

/* ---- small screens ---------------------------------------------------------- */
@media (max-width: 52rem) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; inset: 0 auto 0 0; width: min(var(--rail), 84vw); z-index: 10;
    transform: translateX(-100%); transition: transform 0.2s ease; visibility: hidden;
  }
  .app.rail-open .rail { transform: none; visibility: visible; }
  .rail-toggle { display: block; }
  .rail-list .chat-delete { opacity: 0.6; }
  .label { grid-template-columns: 4.6rem minmax(0, 1fr) 4.4rem; }
  .label-code { font-size: var(--step-1); padding: 0.5rem; }
  @keyframes scan { from { transform: translateX(0.4rem); } to { transform: translateX(3.6rem); } }
}

@media (prefers-reduced-motion: reduce) {
  .thread { scroll-behavior: auto; }
  .label.is-running .label-scan::after { animation: none; left: 50%; }
  .starters button::after, .rail { transition: none; }
}
