/* LabelFlow app styles: base, native feel, controls and overlays.
   Colours, radii, spacing and motion come from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
:root { --bar-h: 60px; --dock-bottom: 0px; --kb-inset: 0px; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font: 400 var(--fs-body)/var(--lh) var(--font-ui);
  color: var(--text);
  background: var(--bg-app);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea, select, [contenteditable], .selectable { user-select: text; -webkit-user-select: text; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: default; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
kbd { font: inherit; font-family: var(--font-ui); }
code { font-family: var(--font-mono); font-size: 0.92em; background: var(--bg-sunken); padding: 1px 4px; border-radius: 4px; }
svg.icon { flex: none; display: block; }
.num { font-variant-numeric: tabular-nums; }
.spacer { flex: 1 1 auto; min-width: 0; }

#app { position: fixed; inset: 0; }
#overlay-root { position: relative; z-index: 50; }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }
input:focus-visible, textarea:focus-visible, select:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

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

/* Screens ---------------------------------------------------------------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg-app); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.screen-center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.ed-skeleton { position: absolute; inset: 0; background: var(--bg-app); }

/* Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--btn-h); padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--bg-panel); color: var(--text);
  font-size: var(--fs-body); font-weight: 500; line-height: 1; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--bg-hover); }
.btn:active { background: var(--bg-active); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); font-weight: 600; }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--primary:active { background: var(--accent-hover); }
.btn--quiet { border-color: transparent; background: transparent; }
.btn--danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 45%, var(--border)); }
.btn--danger:hover { background: var(--error-soft); }
.btn--block { width: 100%; }
.btn--compact .btn-label { display: none; }
.btn--compact { padding: 0 12px; }
.btn:disabled, .btn.is-disabled, .icon-btn:disabled, .icon-btn.is-disabled { opacity: 0.4; pointer-events: none; }
.btn-label { overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--icon-btn); height: var(--icon-btn); padding: 0;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { background: var(--bg-active); }
.icon-btn.is-active, .icon-btn[aria-pressed="true"] { background: var(--bg-active); color: var(--text); }
.icon-btn.is-on { color: var(--text); }

.tool-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 44px; min-height: 44px; padding: 4px 2px; border: 0; background: transparent; color: var(--text-2);
  font-size: 11px; font-weight: 500; line-height: 1.1; border-radius: var(--r-sm);
}
.tool-btn:active { background: var(--bg-active); }
.tool-btn[aria-pressed="true"] { color: var(--accent); }
.tool-btn.is-dim { color: var(--text-3); }

/* Inputs ------------------------------------------------------------------- */
.input, .select {
  width: 100%; height: var(--input-h); padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-panel);
  font-size: var(--fs-input); line-height: 1.2;
  transition: border-color var(--t-fast) var(--ease);
}
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-3); }
.textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.4; }
.mono { font-family: var(--font-mono); font-size: 13px; }
.search-input { padding-left: 34px; }
input[type="search"]::-webkit-search-cancel-button { appearance: none; }

.select-wrap { position: relative; display: block; width: 100%; }
.select { appearance: none; -webkit-appearance: none; padding-right: 30px; text-overflow: ellipsis; }
.select-wrap > .icon { position: absolute; right: 8px; top: 50%; margin-top: -8px; pointer-events: none; color: var(--text-3); }

.field-stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label, .pl { font-size: var(--fs-label); font-weight: 500; color: var(--text-2); }
.help { font-size: var(--fs-help); color: var(--text-2); line-height: 1.4; }

/* Number field */
.nf {
  display: flex; align-items: center; height: var(--input-h); min-width: 0;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-panel);
  transition: border-color var(--t-fast) var(--ease);
}
.nf:hover { border-color: var(--border-strong); }
.nf:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.nf-input { flex: 1; min-width: 0; width: 100%; height: 100%; border: 0; background: transparent; padding: 0 0 0 10px; font-size: var(--fs-input); font-variant-numeric: tabular-nums; box-shadow: none !important; }
.nf-input::placeholder { color: var(--text-3); }
.nf-suffix { flex: none; padding: 0 10px 0 4px; font-size: var(--fs-help); color: var(--text-3); min-width: 14px; text-align: right; }
.nf:not(.has-suffix) .nf-input { padding-right: 10px; }
.pl.is-scrub { cursor: ew-resize; }
body.is-scrubbing, body.is-scrubbing * { cursor: ew-resize !important; }
body.is-resizing, body.is-resizing * { cursor: col-resize !important; user-select: none; }

/* Segmented */
.seg { display: flex; gap: 2px; padding: 2px; background: var(--bg-sunken); border-radius: var(--r-sm); min-width: 0; }
.seg-btn {
  flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: calc(var(--input-h) - 6px); padding: 0 10px; border: 0; border-radius: 4px; background: transparent; color: var(--text-2);
  font-size: var(--fs-label); font-weight: 500; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-on { background: var(--bg-panel); color: var(--text); box-shadow: var(--shadow-1), 0 0 0 1px var(--border); }
.seg-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.seg--icons .seg-btn { padding: 0; }
.seg-label { overflow: hidden; text-overflow: ellipsis; }

/* Switch */
.switch { position: relative; flex: none; width: 38px; height: 22px; padding: 0; border: 0; border-radius: 11px; background: var(--border-strong); transition: background var(--t-state) var(--ease); }
.switch::after { content: ''; position: absolute; inset: -11px -4px; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); transition: transform var(--t-state) var(--ease); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(16px); }
@media (pointer: coarse) { .switch { width: 46px; height: 28px; border-radius: 14px; } .switch-thumb { width: 24px; height: 24px; } .switch[aria-checked="true"] .switch-thumb { transform: translateX(18px); } }

/* Colour field */
.cf { display: flex; align-items: center; gap: 8px; width: 100%; height: var(--input-h); padding: 0 8px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-panel); text-align: left; }
.cf:hover { border-color: var(--border-strong); }
.cf .icon { margin-left: auto; color: var(--text-3); }
.cf-text { font-size: var(--fs-label); }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--border-strong); flex: none; }
.swatch.is-none, .swatch-btn.is-none { background: linear-gradient(135deg, transparent 46%, var(--error) 46%, var(--error) 54%, transparent 54%), var(--bg-panel); }
.popover--colors { padding: 12px; width: 232px; }
.swatch-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.swatch-btn { height: 40px; border-radius: var(--r-sm); border: 1px solid var(--border-strong); display: flex; align-items: center; justify-content: center; color: #fff; mix-blend-mode: normal; padding: 0; }
.swatch-btn[style*="FFFFFF"] { color: #000; }
.swatch-btn[aria-selected="true"] { box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 4px var(--accent); }
.swatch-custom { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--fs-label); color: var(--text-2); }
.color-native { width: 44px; height: 32px; padding: 0; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: none; }

/* Progress */
.progress { height: 6px; border-radius: 3px; background: var(--bg-sunken); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width var(--t-fast) linear; }
.progress.is-indeterminate .progress-fill { width: 35%; animation: indet 1.2s var(--ease) infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

/* Status chip and text */
.status { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-help); color: var(--text-2); white-space: nowrap; }
.status[data-state="error"] { color: var(--error); }
.status-icon { display: inline-flex; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--r-sm); background: transparent; font-size: var(--fs-help); color: var(--text-2); white-space: nowrap; }
.chip:hover { background: var(--bg-hover); }
.chip-sync[data-status="synced"], .chip-sync[data-status="idle"] { color: var(--success); }
.chip-sync[data-status="error"] { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, var(--border)); }
.chip-sync[data-status="conflict"], .chip-sync[data-status="waiting"] { color: var(--warning); }
.chip-icon { display: inline-flex; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--text-2); }
.badge[data-status="synced"], .badge[data-status="idle"] { color: var(--success); }
.badge[data-status="error"] { color: var(--error); }
.badge[data-status="conflict"], .badge[data-status="waiting"] { color: var(--warning); }

/* Empty / validation / notes -------------------------------------------------- */
.empty { max-width: 460px; margin: 0 auto; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; color: var(--text-2); }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-text { max-width: 38ch; }
.empty-actions { display: flex; gap: 8px; margin-top: 8px; }
.empty-sub { margin-top: 24px; font-size: var(--fs-section); font-weight: 600; color: var(--text-2); align-self: stretch; text-align: left; }
.validation { display: flex; align-items: flex-start; gap: 6px; font-size: var(--fs-help); color: var(--success); line-height: 1.35; }
.validation.is-error { color: var(--error); }
.validation .icon { margin-top: 1px; }

/* Menus, popovers, tooltips ----------------------------------------------------- */
.popover {
  position: fixed; left: 0; top: 0; z-index: 60; min-width: 160px; max-width: min(360px, calc(100vw - 16px)); overflow: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
.popover.is-open { opacity: 1; }
.popover--menu { padding: 4px; min-width: 200px; }
.menu { display: flex; flex-direction: column; }
.menu-item { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 8px; border: 0; border-radius: 4px; background: transparent; text-align: left; font-size: var(--fs-body); white-space: nowrap; }
.menu-item:hover, .menu-item:focus { background: var(--bg-hover); box-shadow: none; }
.menu-item:disabled { color: var(--text-3); pointer-events: none; }
.menu-item.is-danger { color: var(--error); }
.menu-icon { display: inline-flex; width: 18px; color: var(--text-2); flex: none; }
.menu-label { flex: 1; }
.menu-kbd { margin-left: 24px; color: var(--text-3); font-size: var(--fs-help); }
.menu-sep { height: 1px; background: var(--divider); margin: 4px -4px; }
.menu-heading { padding: 6px 8px; font-size: var(--fs-help); color: var(--text-3); white-space: normal; max-width: 240px; }
@media (pointer: coarse) { .menu-item { min-height: 44px; } }

.tooltip { position: fixed; left: 0; top: 0; z-index: 90; pointer-events: none; display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 6px; background: #18232D; color: #F0F3F5; font-size: 12px; line-height: 1.3; box-shadow: var(--shadow-pop); }
.tooltip kbd { color: #AAB7C1; font-size: 11.5px; }
:root[data-theme="dark"] .tooltip { background: #F0F3F5; color: #18232D; }
:root[data-theme="dark"] .tooltip kbd { color: #596875; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tooltip { background: #F0F3F5; color: #18232D; } :root:not([data-theme="light"]) .tooltip kbd { color: #596875; } }

/* Dialog --------------------------------------------------------------------------- */
dialog.dlg {
  width: min(var(--dlg-w, 400px), calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; margin: auto;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-panel); color: var(--text);
  box-shadow: var(--shadow-pop); display: flex; flex-direction: column; overflow: hidden;
  opacity: 0; transform: translateY(6px); transition: opacity var(--t-state) var(--ease), transform var(--t-state) var(--ease);
}
dialog.dlg[open] { display: flex; }
dialog.dlg.is-open { opacity: 1; transform: none; }
dialog.dlg::backdrop { background: var(--bg-overlay); }
.dlg-title { font-size: 16px; font-weight: 600; padding: 16px 16px 8px; }
.dlg-body { padding: 4px 16px 16px; overflow: auto; overscroll-behavior: contain; user-select: text; -webkit-user-select: text; }
.dlg-text { color: var(--text-2); line-height: 1.5; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--divider); }
.dlg--new .dlg-body { padding: 0; }

/* Snackbar ---------------------------------------------------------------------------- */
.snackbar {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom) + var(--dock-bottom, 0px)); z-index: 80;
  display: flex; align-items: center; gap: 12px; max-width: min(520px, calc(100vw - 32px)); padding: 6px 6px 6px 16px; min-height: 44px;
  background: #18232D; color: #F0F3F5; border-radius: var(--r-md); box-shadow: var(--shadow-pop); font-size: 13.5px;
  opacity: 0; transform: translate(-50%, 8px); transition: opacity var(--t-state) var(--ease), transform var(--t-state) var(--ease);
}
.snackbar.is-in { opacity: 1; transform: translate(-50%, 0); }
.snackbar--error { background: #6B1F1F; }
:root[data-theme="dark"] .snackbar { background: #F0F3F5; color: #18232D; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .snackbar { background: #F0F3F5; color: #18232D; } }
.snackbar-msg { flex: 1; }
.snackbar-action { height: 32px; padding: 0 12px; border: 0; border-radius: var(--r-sm); background: transparent; color: #7FD6CC; font-weight: 600; font-size: 13.5px; }
:root[data-theme="dark"] .snackbar-action { color: #087F79; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .snackbar-action { color: #087F79; } }
.snackbar-action:hover { background: rgb(255 255 255 / 0.1); }
.snackbar-close { width: 32px; height: 32px; border: 0; border-radius: var(--r-sm); background: transparent; color: inherit; opacity: 0.7; display: inline-flex; align-items: center; justify-content: center; }
.snackbar-close:hover { opacity: 1; background: rgb(255 255 255 / 0.1); }
@media (pointer: coarse) { .snackbar-action, .snackbar-close { min-height: 44px; min-width: 44px; } }

/* Sheets ---------------------------------------------------------------------------------- */
.sheet-root { position: fixed; left: 0; right: 0; z-index: 40; pointer-events: none; }
.sheet-root.is-modal { inset: 0; display: flex; flex-direction: column; justify-content: flex-end; pointer-events: auto; z-index: 70; padding-bottom: var(--kb-inset, 0px); }
.sheet-root.is-docked { bottom: max(var(--kb-inset, 0px), var(--dock-bottom, 0px)); }
.sheet-scrim { position: absolute; inset: 0; background: var(--bg-overlay); opacity: 0; transition: opacity var(--t-sheet) var(--ease); }
.sheet-root.is-open .sheet-scrim { opacity: 1; }
.sheet {
  position: relative; display: flex; flex-direction: column; width: 100%; max-height: 100%; overflow: hidden; pointer-events: auto;
  background: var(--bg-panel); border-radius: var(--r-sheet) var(--r-sheet) 0 0; box-shadow: var(--shadow-sheet);
  border: 1px solid var(--border); border-bottom: 0;
  transform: translateY(100%); transition: transform var(--t-sheet) var(--ease-out), height var(--t-sheet) var(--ease);
}
.sheet.no-anim { transition: transform var(--t-sheet) var(--ease-out); }
.sheet-root.is-open .sheet { transform: none; }
.sheet:focus { box-shadow: var(--shadow-sheet); }
.sheet-drag { flex: none; touch-action: none; cursor: grab; user-select: none; }
.sheet-grab { height: 20px; display: flex; align-items: center; justify-content: center; }
.sheet-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); }
.sheet-head { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 8px 0 16px; }
.sheet-title { flex: 1; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.sheet-root.is-docked .sheet-body { padding-bottom: 16px; }
.sheet-body--flex { display: flex; flex-direction: column; overflow: hidden; padding: 0 !important; }
.sheet--form .sheet-body { padding: 0; }
.action-list { display: flex; flex-direction: column; margin: 0 -8px; }
.action-item { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px; border: 0; background: transparent; text-align: left; font-size: 16px; border-radius: var(--r-sm); }
.action-item:active { background: var(--bg-active); }
.action-item.is-danger { color: var(--error); }
.action-label { flex: 1; }
.action-icon-gap { width: 22px; }
.action-list .menu-sep { margin: 4px 0; }
.action-list .menu-heading { padding: 8px 16px; }
.sheet-note { display: flex; gap: 8px; align-items: flex-start; margin: 0 16px 4px; padding: 8px 10px; border-radius: var(--r-sm); background: var(--bg-sunken); color: var(--text-2); font-size: var(--fs-help); }
.sheet-note .icon { margin-top: 1px; }

/* Scanner ---------------------------------------------------------------------------------- */
.scanner { position: fixed; inset: 0; z-index: 95; background: #000; color: #fff; display: flex; flex-direction: column; }
.scan-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 50%; top: 45%; width: min(78vw, 360px); height: min(40vw, 200px); transform: translate(-50%, -50%); border: 2px solid #fff; border-radius: var(--r-md); box-shadow: 0 0 0 9999px rgb(0 0 0 / 0.45); }
.scan-top { position: relative; display: flex; align-items: center; justify-content: space-between; padding: calc(8px + env(safe-area-inset-top)) 8px 8px 16px; background: linear-gradient(#000a, transparent); }
.scan-x { color: #fff; }
.scan-bottom { position: relative; margin-top: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; align-items: center; background: linear-gradient(transparent, #000b); }
.scan-status.is-error { color: #FFB4B4; }
.canvas-missing { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; color: var(--text-2); }

.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[data-form="phone"] #app[data-screen="print"] ~ #overlay-root .snackbar { bottom: calc(88px + env(safe-area-inset-bottom)); }
