/* Apollo — companion app styles.
   The Giorgetti MATRIX register (Italo Lupi): paper-white ground, ink-black
   type, hairline rules, italic Fraunces titles sitting ON a hard hairline
   (never text-underline), Karla for UI text, Sometype Mono for eyebrows and
   figures. Color appears ONLY as tiny chips of Apollo amber and IKB blue.
   Colors come from the storefront's tokens.css verbatim; --amber is the one
   app-local addition (the storefront never tokenized its brand amber). */

:root {
  --mono: 'Sometype Mono', ui-monospace, monospace;
  --sans: 'Karla', system-ui, sans-serif;
  --serif: 'Fraunces', serif;
  --amber: #eb9f37;

  --rail-w: 3.25rem;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sal: env(safe-area-inset-left, 0px);
  /* visualViewport-driven height; main.js keeps it current so the messenger
     composer stays glued above the keyboard. */
  --vvh: 100dvh;
}

* { box-sizing: border-box; }

/* The screens/sign-in set display:flex|grid, which would otherwise defeat the
   hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  font: 15px/1.5 var(--sans);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

em { font-family: var(--serif); font-style: italic; } /* Karla has no italic */

h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

/* ---- shared vocabulary ---- */

.kicker {
  display: block;
  font: 500 10px/1.3 var(--mono);
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--ikb);
  margin-bottom: 10px;
}

.rule { height: 1px; background: var(--line-dark); border: 0; margin: 0; }

.screen-head {
  padding: calc(var(--sat) + 18px) 20px 12px calc(var(--sal) + 20px);
  border-bottom: 1px solid var(--line-dark);
  background: var(--paper);
}
.screen-head h1 {
  margin: 0;
  font: italic 350 34px/1.02 var(--serif);
  letter-spacing: -.015em;
}
.screen-head .head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.eyebrow-note { font: 10px/1.4 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint); }

.btn {
  display: inline-block;
  padding: 10px 20px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  font: 500 12px/1.2 var(--mono);
  letter-spacing: .18em;
  text-indent: .18em;
  text-transform: uppercase;
  text-align: center;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-dark); }
.btn.danger { background: var(--red); }
.btn.small { padding: 7px 14px; font-size: 10px; }
.btn:disabled { opacity: .4; }

input, textarea, select {
  font: 16px/1.4 var(--sans); /* ≥16px: no iOS focus zoom */
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 10px 12px;
  width: 100%;
  appearance: none;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--ink); }
label.field { display: block; margin: 0 0 12px; }
label.field > span {
  display: block;
  font: 10px/1.4 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 5px;
}

/* Tiny chips — the only color in the app. */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; vertical-align: 1px; }
.dot.ikb { background: var(--ikb); }
.dot.amber { background: var(--amber); }

/* Status vocabulary rhymes with the desktop panel; re-voiced as ink-on-paper
   pills with a colored chip instead of tinted backgrounds. */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: 11px/1 var(--mono);
  letter-spacing: .06em;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
  color: var(--ink-dim);
}
.tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); }
.tag.paid::before, .tag.delivered::before, .tag.completed::before, .tag.active::before, .tag.unused::before { background: var(--green); }
.tag.printing::before, .tag.busy::before, .tag.shipped::before, .tag.label_created::before, .tag.printed::before, .tag.sliced::before, .tag.assigned::before { background: var(--ikb); }
.tag.pending::before, .tag.authorized::before, .tag.awaiting_clearance::before, .tag.paused::before, .tag.queued::before { background: var(--amber); }
.tag.failed::before, .tag.error::before, .tag.offline::before, .tag.refunded::before, .tag.cancelled::before, .tag.expired::before, .tag.revoked::before, .tag.aborting::before { background: var(--red); }

.mono { font-family: var(--mono); }
.dim { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }
.num { font-variant-numeric: tabular-nums; }

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

#signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--sat) + 24px) 24px calc(var(--sab) + 24px);
}
.signin-inner { max-width: 21rem; }
.signin-mark { width: 74px; color: var(--ink); margin-bottom: 26px; }
#signin h1 { margin: 0 0 14px; font: italic 350 56px/.98 var(--serif); letter-spacing: -.03em; }
#signin .rule { margin-bottom: 16px; }
.signin-copy { margin: 0 0 26px; color: var(--ink-dim); }
.signin-fine { margin: 18px 0 0; font-size: 12px; color: var(--ink-faint); }

/* ---- shell: screens + rail ---- */

#screens { position: fixed; inset: 0; right: calc(var(--rail-w) + var(--sar)); }
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.screen-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px calc(var(--sab) + 24px) calc(var(--sal) + 20px);
}

/* The thumb rail: five fixed hairline cells occupying the upper right edge —
   the natural right-thumb arc — with the vertical rule running the full
   height of the page as structure. */
#rail {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: calc(var(--rail-w) + var(--sar));
  padding-top: calc(var(--sat) + 14px);
  padding-right: var(--sar);
  border-left: 1px solid var(--line-dark);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.rail-btn {
  position: relative;
  height: 3.4rem;
  display: grid;
  place-items: center;
  border-bottom: 1px solid var(--line-dark);
  color: var(--ink);
}
.rail-btn:first-child { border-top: 1px solid var(--line-dark); }
.rail-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.rail-btn--admin svg { width: 22px; height: 22px; stroke-width: 11; }
.rail-btn--admin .rail-sun { fill: currentColor; stroke: none; }
.rail-btn[aria-current="true"] { color: var(--ikb); }
.rail-btn[aria-current="true"]::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: -1px;
  width: 2px;
  background: var(--ikb);
}
.rail-btn:active svg { transform: scale(.9); }
.rail-chip {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ikb);
}
.rail-chip.amber { background: var(--amber); }

/* ---- generic list rows (hairline-separated, editorial) ---- */

.rows { margin: 0; padding: 0; list-style: none; }
.row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line);
}
.row:active { background: color-mix(in oklab, var(--ink) 4%, transparent); }
.row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.row-title { font-weight: 700; }
.row-sub { color: var(--ink-dim); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.row-when { font: 11px/1.4 var(--mono); color: var(--ink-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty {
  padding: 44px 8px;
  text-align: center;
  color: var(--ink-faint);
}
.empty .kicker { color: var(--ink-faint); }

.section-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 26px 0 4px;
  font: 500 10px/1.3 var(--mono);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---- messenger ---- */

#screen-messenger { height: var(--vvh); position: absolute; inset: 0; }
.msg-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 20px 8px calc(var(--sal) + 20px); }
.msg {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font: 10px/1.4 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 3px;
}
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg.pending { opacity: .45; }
.msg.queued .msg-meta::after { content: 'queued — will retry'; color: var(--amber); letter-spacing: .08em; }
.msg-photos { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }
.msg-photos img {
  width: 108px; height: 108px; object-fit: cover;
  border: 1px solid var(--line);
  background: var(--panel);
}
.composer {
  border-top: 1px solid var(--line-dark);
  background: var(--paper);
  padding: 8px 12px calc(var(--sab) + 8px) calc(var(--sal) + 12px);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel);
  resize: none;
  max-height: 7.5rem;
  padding: 9px 12px;
}
.composer .icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--ink);
  flex-shrink: 0;
}
.composer .icon-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.composer .send-btn { color: var(--paper); background: var(--ink); border-radius: 50%; }
.composer .send-btn:disabled { opacity: .35; }
.compose-previews { display: flex; gap: 6px; padding: 6px 12px 0 calc(var(--sal) + 12px); background: var(--paper); }
.compose-previews:empty { display: none; }
.compose-previews .pv { position: relative; }
.compose-previews img { width: 52px; height: 52px; object-fit: cover; border: 1px solid var(--line-dark); }
.compose-previews button {
  position: absolute; top: -7px; right: -7px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  font-size: 11px; line-height: 1;
}

.photo-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: var(--paper);
  display: grid; place-items: center;
  padding: calc(var(--sat) + 16px) 16px calc(var(--sab) + 16px);
}
.photo-overlay img { max-width: 100%; max-height: 100%; border: 1px solid var(--line-dark); }
.photo-overlay .close-x { position: absolute; top: calc(var(--sat) + 10px); right: 14px; font: 22px/1 var(--sans); padding: 10px; }

/* ---- subviews (thread, order detail, project…) ---- */

.subview {
  position: absolute;
  inset: 0;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.subview-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--sat) + 8px) 14px 8px calc(var(--sal) + 6px);
  border-bottom: 1px solid var(--line-dark);
}
.subview-head .back {
  padding: 9px 10px;
  font: 500 11px/1 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ikb);
}
.subview-head .sv-title {
  flex: 1;
  font: italic 350 19px/1.1 var(--serif);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subview-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 20px calc(var(--sab) + 24px) calc(var(--sal) + 20px); }

/* ---- inbox ---- */

.mail-row.unread .row-title::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ikb); margin-right: 7px; vertical-align: 1px; }
.mail-msg { border-bottom: 1px solid var(--line); padding: 12px 0; }
.mail-msg-head { font: 11px/1.5 var(--mono); color: var(--ink-dim); margin-bottom: 6px; word-break: break-word; }
.mail-frame { width: 100%; border: 0; background: var(--panel); }
.mail-text { white-space: pre-wrap; word-wrap: break-word; }
.reply-box { border-top: 1px solid var(--line-dark); padding: 10px 0 0; }
.reply-box textarea { min-height: 5.5rem; margin-bottom: 8px; }
.banner {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-dark);
  padding: 10px 12px;
  margin: 14px 0 0;
  font-size: 13px;
}
.banner .dot { flex-shrink: 0; }

/* ---- calendar ---- */

.cal-nav { display: flex; align-items: baseline; justify-content: space-between; margin: 14px 0 8px; }
.cal-nav .cal-title { font: italic 350 20px/1 var(--serif); }
.cal-nav button { font: 500 12px/1 var(--mono); letter-spacing: .1em; padding: 8px 12px; color: var(--ikb); }
.cal-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-grid th {
  font: 500 9px/1 var(--mono);
  letter-spacing: .18em;
  color: var(--ink-faint);
  text-transform: uppercase;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-dark);
}
.cal-grid td {
  height: 3.1rem;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  padding: 3px 0 0;
  text-align: center;
}
.cal-day { display: inline-grid; place-items: center; width: 26px; height: 26px; font: 12px/1 var(--mono); font-variant-numeric: tabular-nums; }
.cal-day.today { background: var(--ink); color: var(--paper); border-radius: 50%; }
.cal-day.selected:not(.today) { box-shadow: inset 0 0 0 1px var(--ink); border-radius: 50%; }
.cal-td.other { color: var(--ink-faint); }
.cal-dots { display: flex; gap: 3px; justify-content: center; margin-top: 2px; min-height: 5px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; }
.cal-dots i.ev { background: var(--ikb); }
.cal-dots i.tk { background: var(--amber); }

/* ---- tracker ---- */

.task {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.task-check {
  width: 22px; height: 22px;
  border: 1px solid var(--line-dark);
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
  display: grid; place-items: center;
  color: transparent;
}
.task.done .task-check { color: var(--ink); }
.task.done .task-title { color: var(--ink-faint); text-decoration: line-through; text-decoration-thickness: 1px; }
.task-check svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.task-main { flex: 1; min-width: 0; }
.task-meta { font: 10px/1.5 var(--mono); letter-spacing: .08em; color: var(--ink-faint); display: flex; gap: 10px; flex-wrap: wrap; }
.task-meta .overdue { color: var(--red); }
.add-inline { display: flex; gap: 8px; margin: 14px 0; }
.add-inline input { flex: 1; }

/* ---- admin ---- */

.hub-row { display: flex; align-items: center; gap: 12px; }
.hub-row .row-title { font-size: 17px; }
.hub-row.disabled { color: var(--ink-faint); }
.hub-row.disabled .row-title { color: var(--ink-faint); font-weight: 400; }
.hub-note { margin-left: auto; font: 10px/1.4 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); }

.stat-strip { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line-dark); }
.stat-strip .stat { padding: 12px 4px 12px 0; border-right: 1px solid var(--line); }
.stat-strip .stat:last-child { border-right: 0; }
.stat .stat-n { font: 600 20px/1 var(--sans); font-variant-numeric: tabular-nums; }
.stat .stat-l { font: 9px/1.3 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); margin-top: 4px; }

.filter-row { display: flex; gap: 8px; margin: 14px 0 4px; }
.filter-row select { flex: 1; }

.swatch { display: inline-block; width: 13px; height: 13px; border-radius: 50%; border: 1px solid var(--line-dark); vertical-align: -2px; }

.preview-wrap { position: relative; margin: 14px 0; border: 1px solid var(--line); background: var(--panel); }
.preview-wrap canvas { display: block; width: 100%; height: 300px; touch-action: none; }
.preview-note { position: absolute; bottom: 6px; right: 8px; font: 9px/1 var(--mono); letter-spacing: .12em; color: var(--ink-faint); text-transform: uppercase; }

.kv { margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv dt { font: 10px/1.6 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-faint); }
.kv dd { margin: 0; text-align: right; word-break: break-word; }

.action-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }

.pcard { border: 1px solid var(--line); padding: 12px; margin: 0 0 10px; background: var(--panel); }
.pcard.attention { border-color: var(--red); }
.pcard.offline { opacity: .6; }
.pcard-top { display: flex; align-items: center; gap: 8px; }
.pcard-name { font-weight: 700; }
.pcard-tags { margin-left: auto; display: flex; gap: 5px; }
.pbar { height: 4px; background: var(--line); margin: 10px 0 4px; }
.pbar > span { display: block; height: 100%; background: var(--ikb); }
.pcard-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.warn-block { border: 1px solid var(--red); padding: 12px; margin: 14px 0; }
.warn-block .kicker { color: var(--red); }

/* ---- toast ---- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sab) + 22px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font: 500 11px/1.3 var(--mono);
  letter-spacing: .1em;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 100;
  max-width: 84vw;
  text-align: center;
}

.spin {
  margin: 34px auto;
  width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 1.6s; }
  .rail-btn:active svg, .btn:active { transform: none; }
}
