/* ==========================================================================
   Filamentory — domain specific UI
   ========================================================================== */

/* --- Spool visual ------------------------------------------------------- */
.spool-visual {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--bg-content) 0 26%, transparent 26.5%),
    conic-gradient(var(--spool-color) calc(var(--pct) * 1%), var(--bg-inset) 0);
  box-shadow: inset 0 0 0 1px var(--label-quaternary);
  width: var(--size, 54px);
  height: var(--size, 54px);
  transition: background var(--dur-slow) var(--ease-ios);
}

.spool-visual--dual {
  background:
    radial-gradient(circle at 50% 50%, var(--bg-content) 0 26%, transparent 26.5%),
    conic-gradient(from 0deg,
      var(--spool-color) 0 calc(var(--pct) * 0.5%),
      var(--spool-color2, var(--spool-color)) calc(var(--pct) * 0.5%) calc(var(--pct) * 1%),
      var(--bg-inset) 0);
}

.spool-visual__core {
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: var(--bg-content);
  display: grid;
  place-items: center;
  font: 600 calc(var(--size, 54px) * 0.2) / 1 var(--font-ui);
  font-variant-numeric: tabular-nums;
  color: var(--label-secondary);
}

.spool-visual.is-empty { opacity: 0.5; }

/* --- Spool card (grid layout) --------------------------------------------- */
.spool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--bg-content);
  box-shadow: var(--shadow-sm);
  text-align: left;
  color: var(--label);
  overflow: hidden;
  transition: transform var(--dur-fast) var(--ease-ios), box-shadow var(--dur-base) var(--ease-ios);
}

.spool-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--spool-stripe, linear-gradient(90deg, var(--spool-color), var(--spool-color2, var(--spool-color))));
  opacity: 0.9;
}

@media (hover: hover) { .spool-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); } }
.spool-card:active { transform: scale(0.985); }

.spool-card__top { display: flex; align-items: flex-start; gap: var(--sp-3); }
.spool-card__info { flex: 1; min-width: 0; }
.spool-card__brand {
  font: var(--t-caption2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--label-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spool-card__name {
  font: var(--t-headline);
  letter-spacing: -0.01em;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.spool-card__meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.spool-card__stats {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  font-variant-numeric: tabular-nums;
}
.spool-card__grams { font: var(--t-title3); letter-spacing: -0.02em; }
.spool-card__grams small { font: var(--t-footnote); color: var(--label-secondary); margin-left: 2px; }
.spool-card__pct { font: var(--t-footnote); color: var(--label-secondary); }
.spool-card__fav { position: absolute; top: var(--sp-3); right: var(--sp-3); color: var(--sys-orange); }
.spool-card__fav svg { width: 15px; height: 15px; }

/* --- Progress bar ------------------------------------------------------------ */
.meter {
  position: relative;
  height: 7px;
  border-radius: var(--r-full);
  background: var(--bg-inset);
  overflow: hidden;
}
.meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: var(--r-full);
  background: var(--spool-stripe, linear-gradient(90deg, var(--spool-color), var(--spool-color2, var(--spool-color))));
  /* Very dark or very light filaments would vanish into the track otherwise. */
  box-shadow: inset 0 0 0 1px var(--label-tertiary);
  transition: width var(--dur-slow) var(--ease-ios);
  min-width: 6px;
}
.meter--lg { height: 12px; }
.meter--low .meter__fill { background: var(--sys-orange); }
.meter--critical .meter__fill { background: var(--sys-red); }

/* --- Spool row (list layout) --------------------------------------------------- */
.spool-row { align-items: center; gap: var(--sp-3); }
.spool-row .spool-visual { --size: 42px; }
.spool-row__main { flex: 1; min-width: 0; }
.spool-row__title { font: var(--t-body); letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spool-row__sub { display: flex; align-items: center; gap: 6px; margin-top: 3px; font: var(--t-footnote); color: var(--label-secondary); }
.spool-row__meter { margin-top: 6px; max-width: 220px; }
.spool-row__right { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.spool-row__grams { font: var(--t-callout); font-weight: 500; }
.spool-row__pct { font: var(--t-caption); color: var(--label-tertiary); }

/* --- Detail header ---------------------------------------------------------------- */
.detail-hero {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-4);
  border-radius: var(--r-xl);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--spool-color) 22%, transparent), transparent 62%),
    var(--bg-content);
  box-shadow: var(--shadow-sm);
}
.detail-hero .spool-visual { --size: 96px; }
.detail-hero__info { flex: 1; min-width: 0; }
.detail-hero__brand { font: var(--t-caption2); text-transform: uppercase; letter-spacing: 0.06em; color: var(--label-secondary); }
.detail-hero__name { font: var(--t-title2); letter-spacing: -0.02em; margin-top: 3px; }
.detail-hero__meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: var(--sp-2); }

@media (max-width: 480px) {
  .detail-hero { flex-direction: column; align-items: flex-start; }
  .detail-hero .spool-visual { --size: 86px; }
}

/* --- Quick action tiles ------------------------------------------------------------ */
.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: var(--sp-2);
}
.action-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--sp-3) var(--sp-2);
  border-radius: var(--r-md);
  background: var(--bg-content);
  color: var(--label);
  font: var(--t-caption);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease-ios), background var(--dur-fast);
}
@media (hover: hover) { .action-tile:hover { background: var(--bg-content-alt); } }
.action-tile:active { transform: scale(0.95); }
.action-tile svg { width: 22px; height: 22px; color: var(--accent); }
.action-tile--destructive svg { color: var(--sys-red); }

/* --- Stat tiles ------------------------------------------------------------------- */
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  background: var(--bg-content);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.stat-tile__label {
  font: var(--t-caption2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--label-tertiary);
  display: flex;
  align-items: center;
  gap: 5px;
}
.stat-tile__label svg { width: 13px; height: 13px; }
.stat-tile__value {
  font: 700 clamp(22px, 3vw, 28px)/1.1 var(--font-ui);
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.stat-tile__value small { font: var(--t-subhead); color: var(--label-secondary); font-weight: 500; margin-left: 3px; }
.stat-tile__hint { font: var(--t-caption); color: var(--label-secondary); margin-top: 2px; }
.stat-tile--accent { background: var(--accent); color: var(--accent-text); }
.stat-tile--accent .stat-tile__label,
.stat-tile--accent .stat-tile__hint,
.stat-tile--accent .stat-tile__value small { color: color-mix(in srgb, var(--accent-text) 76%, transparent); }

/* --- Charts -------------------------------------------------------------------------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 148px; padding-top: var(--sp-3); }
.bars__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; height: 100%; }
.bars__bar {
  width: 100%;
  max-width: 40px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 62%, transparent));
  min-height: 3px;
  transition: height var(--dur-slow) var(--ease-ios);
  position: relative;
}
.bars__bar:hover::after {
  content: attr(data-value);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 8px;
  border-radius: var(--r-xs);
  background: var(--glass-bar-solid);
  box-shadow: var(--shadow-md);
  font: var(--t-caption2);
  white-space: nowrap;
  z-index: 2;
}
.bars__label {
  font: var(--t-caption2);
  color: var(--label-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.donut {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  position: relative;
  background: var(--donut-gradient, var(--bg-inset));
}
.donut::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: var(--bg-content);
}
.donut__center { position: relative; z-index: 1; text-align: center; }
.donut__value { font: var(--t-title3); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.donut__label { font: var(--t-caption); color: var(--label-secondary); }

.legend { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.legend__item { display: flex; align-items: center; gap: var(--sp-2); font: var(--t-subhead); min-width: 0; }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend__value { color: var(--label-secondary); font-variant-numeric: tabular-nums; flex: none; }

/* --- Colour dot inline ------------------------------------------------------------------- */
.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.22);
}
.dot--dual { background: linear-gradient(135deg, var(--c1) 0 50%, var(--c2) 50% 100%) !important; }

/* --- Scanner ------------------------------------------------------------------------------ */
.scanner {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 62dvh;
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #000;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner__frame {
  position: absolute;
  inset: 16%;
  border-radius: var(--r-lg);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
}
.scanner__frame::before, .scanner__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
  border: 2.5px solid rgba(255, 255, 255, 0.9);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
}
.scanner__line {
  position: absolute;
  left: 16%;
  right: 16%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanline 2.4s var(--ease-in-out) infinite;
}
@keyframes scanline { 0%, 100% { top: 18%; } 50% { top: 80%; } }

/* --- Labels / print ------------------------------------------------------------------------- */
@media print {
  body { background: #fff; }
  .navbar, .tabbar, .sidebar, .fab, .toasts, .no-print { display: none !important; }
  .scroller { padding: 0 !important; overflow: visible !important; }
  /* Label page size and grid come from labels.js (depends on the format). */
  .page { max-width: none; }
}

/* --- Timeline ------------------------------------------------------------------------------- */
.timeline { position: relative; padding-left: var(--sp-5); }
.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--separator);
}
.timeline__item { position: relative; padding: var(--sp-2) 0; }
.timeline__dot {
  position: absolute;
  left: calc(-1 * var(--sp-5) + 2px);
  top: 15px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--bg-content);
}
.timeline__item--out .timeline__dot { background: var(--sys-orange); }
.timeline__item--in .timeline__dot { background: var(--sys-green); }
.timeline__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.timeline__title { font: var(--t-callout); font-weight: 500; }
.timeline__value { font: var(--t-callout); font-variant-numeric: tabular-nums; color: var(--label-secondary); }
.timeline__sub { font: var(--t-caption); color: var(--label-tertiary); margin-top: 1px; }

/* --- Login ------------------------------------------------------------------------------------ */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background:
    radial-gradient(1000px 700px at 12% -10%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 60%),
    radial-gradient(800px 600px at 108% 108%, color-mix(in srgb, var(--sys-teal) 20%, transparent), transparent 62%),
    var(--bg-base);
}
.auth__card {
  width: min(400px, 100%);
  padding: var(--sp-6);
  border-radius: var(--r-xl);
  background: var(--glass-panel);
  -webkit-backdrop-filter: var(--glass-blur-strong);
  backdrop-filter: var(--glass-blur-strong);
  box-shadow: var(--shadow-lg), inset 0 0 0 0.5px var(--border-glass);
  text-align: center;
}
.auth__logo { width: 68px; height: 68px; margin: 0 auto var(--sp-4); border-radius: var(--r-lg); box-shadow: var(--shadow-md); }
.auth__title { font: var(--t-title1); letter-spacing: -0.02em; }
.auth__sub { font: var(--t-callout); color: var(--label-secondary); margin-top: var(--sp-1); }
.auth__field {
  width: 100%;
  margin-top: var(--sp-5);
  padding: 13px var(--sp-4);
  border-radius: var(--r-md);
  border: 0.5px solid var(--separator);
  background: var(--bg-content);
  color: var(--label);
  font: var(--t-body);
  outline: none;
  text-align: center;
}
.auth__field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth__error { margin-top: var(--sp-3); font: var(--t-footnote); color: var(--sys-red); min-height: 18px; }

/* --- Colour picker grid --------------------------------------------------------------------- */
.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: var(--sp-2);
}
.color-cell {
  aspect-ratio: 1;
  border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.2);
  transition: transform var(--dur-fast) var(--ease-ios);
  position: relative;
}
.color-cell.is-active::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: var(--r-md);
  border: 2.5px solid var(--accent);
}
.color-cell:active { transform: scale(0.9); }

/* --- Offline banner --------------------------------------------------------------------------- */
.offline-banner {
  position: fixed;
  z-index: 90;
  left: 50%;
  top: calc(var(--safe-top) + var(--sp-2));
  transform: translateX(-50%);
  padding: 6px var(--sp-3);
  border-radius: var(--r-full);
  background: var(--sys-orange);
  color: #000;
  font: var(--t-caption2);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- Drop zone ---------------------------------------------------------------------------------- */
.dropzone {
  border: 2px dashed var(--separator-opaque);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  text-align: center;
  color: var(--label-secondary);
  transition: border-color var(--dur-fast), background var(--dur-fast);
  cursor: pointer;
}
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
