/* ═══ DASHBOARD — Operate inside the engraving ════════════════════════════════ */

:root {
  --topbar-h: 3.75rem;
  --sidebar-w: 15rem;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "side top" "side main";
  min-height: 100vh;
}

/* ── sidebar ───────────────────────────────────────────────────────────────── */

.sidebar {
  grid-area: side;
  border-right: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper-deep) 70%, var(--paper));
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.9rem 1.2rem;
  gap: 0.6rem;
  position: sticky;
  top: 0;
  height: 100vh;
  box-sizing: border-box;
  overflow-y: auto;
}

.side-wordmark { display: flex; align-items: baseline; gap: 0.6rem; text-decoration: none; color: var(--ink); padding: 0.2rem 0.4rem 0.8rem; border-bottom: 1px solid var(--rule); }
.side-wordmark .name { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; letter-spacing: 0.2em; text-transform: uppercase; }
.side-wordmark .tag { font-family: var(--font-mono); font-size: 0.75rem; color: var(--ink-muted); letter-spacing: 0.06em; }

.side-workspace {
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--rule);
}
.side-workspace .ws-name { font-weight: 700; font-size: 0.95rem; }
.side-workspace .ws-meta { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.35rem; flex-wrap: wrap; }

.side-nav { display: grid; gap: 2px; margin-top: 0.4rem; }
.side-nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.58rem 0.7rem;
  border-radius: 2px;
  text-decoration: none;
  color: var(--ink-muted);
  font-weight: 600;
  font-size: 0.86rem;
  border-left: 2px solid transparent;
  letter-spacing: 0.02em;
}
.side-nav a .nav-glyph { font-family: var(--font-mono); font-size: 0.75rem; opacity: 0.75; }
.side-nav a:hover { background: rgba(29,38,29,.05); color: var(--ink); }
.side-nav a[aria-current="true"] {
  color: var(--green-ink);
  border-left-color: var(--green);
  background: rgba(28,90,60,.07);
}
.side-nav a .lock { font-family: var(--font-mono); font-size: 0.75rem; color: var(--copper-deep); }

.side-foot { margin-top: auto; border-top: 1px solid var(--rule); padding-top: 0.7rem; display: grid; gap: 0.35rem; font-size: 0.82rem; color: var(--ink-muted); }
.side-foot a { color: var(--ink-muted); text-decoration: none; }
.side-foot a:hover { color: var(--ink); }

/* ── topbar ────────────────────────────────────────────────────────────────── */

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.4rem;
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper-ink) 86%, transparent);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .tb-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; letter-spacing: 0.04em; }
.topbar .tb-title .crumb { color: var(--ink-muted); font-weight: 500; }
.topbar .tb-right { display: flex; align-items: center; gap: 0.9rem; }
.topbar .tb-left { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
.side-toggle { display: none; }

.user-chip { display: flex; align-items: center; gap: 0.6rem; }
.user-chip .avatar {
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  border: 1px solid var(--ink);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 0.75rem; font-weight: 700;
  background: radial-gradient(circle at 50% 40%, var(--watermark), var(--paper-deep));
  color: var(--green-ink);
}
.user-chip .u-name { font-weight: 700; font-size: 0.84rem; line-height: 1.2; }
.user-chip .u-mail { display: block; font-size: 0.75rem; color: var(--ink-muted); font-family: var(--font-mono); }

.ws-switch select {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  max-width: 13rem;
}

/* ── main content ──────────────────────────────────────────────────────────── */

.main { grid-area: main; padding: 1.6rem clamp(1rem, 2.6vw, 2.2rem) 3rem; min-width: 0; }
/* Every layout box in the shop must be allowed to shrink below its content.
   Without this, a wide ledger table forces the whole view wider than the
   viewport and `overflow-x: auto` on .table-wrap never engages. */
.main, .view, .gap-grid, .gap-grid > *, .grid-2, .grid-3, .grid-4,
.instrument, .inst-body, .table-wrap, table { min-width: 0; }
.view { display: none; }
.view.active { display: block; }

.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.view-head h1 { font-size: 1.7rem; letter-spacing: 0.005em; }
.view-head .vh-sub { color: var(--ink-muted); font-size: 0.9rem; max-width: var(--measure); }

.gap-grid { display: grid; gap: 1.2rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* meter plates */
.meter .meter-label { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.meter .meter-value { font-family: var(--font-display); font-size: 2.3rem; font-weight: 700; line-height: 1.05; margin-top: 0.25rem; }
.meter .meter-value small { font-family: var(--font-ui); font-size: 0.85rem; color: var(--ink-muted); font-weight: 600; }
.meter .meter-bar { height: 9px; border: 1px solid var(--ink); background: repeating-linear-gradient(90deg, var(--paper-deep) 0 6px, transparent 6px 10px); position: relative; margin: 0.7rem 0 0.45rem; border-radius: 1px; overflow: hidden; }
.meter .meter-bar .fill {
  position: absolute;
  inset: 0;
  /* Compositor-driven: see the press bar. Meter fills carry no text or radius,
     so scaling them is visually identical to animating their width. */
  transform: scaleX(0);
  transform-origin: left center;
  background: var(--green);
  transition: transform var(--dur-slow) var(--ease-out);
}
.meter .meter-bar.empty .fill { background: var(--red); }
.meter .meter-note { font-size: 0.82rem; color: var(--ink-muted); }
.meter .meter-serial { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.05em; color: var(--copper-deep); margin-top: 0.5rem; }

/* chart */
.chart-box { padding: 0; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg .bar-g { cursor: default; }
/* The rhythm draws itself in once, from the real values, left to right. */
.chart-svg .bar-g .bar {
  fill: var(--rule);
  transition: fill var(--dur-fast);
  transform-box: fill-box;
  transform-origin: 50% 100%;
}
.chart-svg[data-drawn="true"] .bar-g .bar { animation: bar-rise var(--dur-slow) var(--ease-out) both; }
@keyframes bar-rise { from { transform: scaleY(0.02); } to { transform: scaleY(1); } }
.chart-svg .bar-g:hover .bar { fill: var(--green); }
.chart-svg .bar-g .bar.today { fill: var(--copper); }
.chart-svg .bar-g text { font-family: var(--font-mono); font-size: 10px; fill: var(--ink-muted); }
.chart-legend { display: flex; gap: 1.2rem; font-size: 0.8rem; color: var(--ink-muted); padding: 0.2rem 1.1rem 1rem; flex-wrap: wrap; }
.chart-legend .lg { display: inline-flex; align-items: center; gap: 0.4rem; }
.chart-legend .sw { width: 9px; height: 9px; border: 1px solid var(--ink); display: inline-block; }
.chart-legend .sw.one { background: var(--green); }
.chart-legend .sw.two { background: var(--copper); }

/* key slip (one-time raw key) */
.key-slip {
  border: 1px dashed var(--ink);
  background: color-mix(in srgb, var(--paper-deep) 60%, transparent);
  padding: 1rem 1.1rem;
  display: grid;
  gap: 0.7rem;
  border-radius: var(--radius);
}
.key-slip .ks-label { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); }
.key-slip .ks-key { font-family: var(--font-mono); font-size: 0.95rem; overflow-wrap: anywhere; user-select: all; }
.key-slip .ks-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

/* the key is minted, then printed: it arrives by measure, one character band
   at a time, the way a struck key lands on the record. Purely presentational —
   the value is already complete and selectable underneath. */
.key-slip[data-printing="true"] .ks-key {
  animation: key-print var(--dur-press) var(--ease-out) both;
}
@keyframes key-print {
  from { clip-path: inset(0 100% 0 0); opacity: 0.2; }
  60%  { opacity: 1; }
  to   { clip-path: inset(0 0 0 0); opacity: 1; }
}
.key-slip .ks-progress {
  height: 2px;
  background: var(--ink);
  transform-origin: 0 50%;
  animation: key-print-rule var(--dur-press) var(--ease-out) both;
}
@keyframes key-print-rule { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .key-slip[data-printing="true"] .ks-key,
  .key-slip .ks-progress { animation: none; clip-path: none; }
}

/* inline confirmation — a destructive act is confirmed in place, not behind a
   modal that interrupts the work it is about to change */
.confirm-inline {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.84rem;
  color: var(--ink);
}
.confirm-inline .ci-text { color: var(--red); font-weight: 600; }
.btn-confirm-yes { border-color: var(--red); color: var(--paper-ink); background: var(--red); }
.btn-confirm-yes:hover { background: #8A251D; }

/* forms/panels */
.panel { /* generic instrument body padding variety */ }
.form-stack { display: grid; gap: 0.9rem; }
.inline-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-top: 0.6rem; }

/* permission chips */
.perms { display: inline-flex; gap: 0.3rem; flex-wrap: wrap; }
.chip[data-perm] { font-size: 0.75rem; }

/* members + tables */
.role-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  letter-spacing: 0.04em;
  border: 1px solid var(--rule);
  padding: 0.16rem 0.45rem;
  border-radius: var(--radius);
}
.role-tag[data-role="OWNER"] { color: var(--green-ink); border-color: rgba(28,90,60,.45); }
.role-tag[data-role="ADMIN"] { color: var(--copper-deep); border-color: rgba(178,90,31,.5); }
.role-tag[data-role="MEMBER"] { color: var(--ink-muted); }

.icon-btn {
  background: none; border: 1px solid var(--rule); border-radius: 2px;
  padding: 0.34rem 0.6rem; min-height: 2rem;
  font-family: var(--font-ui); font-size: 0.8rem; font-weight: 600; color: var(--ink-muted); cursor: pointer;
}
.icon-btn:hover { border-color: var(--ink); color: var(--ink); }
.icon-btn.danger:hover { border-color: var(--red); color: var(--red); background: rgba(161,45,36,.05); }
.icon-btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.row-actions { display: flex; gap: 0.4rem; align-items: center; }

/* empty states */
.empty {
  border: 1px dashed var(--rule);
  padding: 2.2rem 1.4rem;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.9rem;
}
.empty .empty-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--ink); margin-bottom: 0.3rem; }

/* form helpers */
.f-label { display: block; font-weight: 700; font-size: 0.82rem; margin-bottom: 0.4rem; }
.check-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
.check { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.84rem; font-weight: 500; cursor: pointer; }
.check input { accent-color: var(--green); width: 1rem; height: 1rem; }
.vm-sub { font-size: 0.8rem; color: var(--ink-muted); font-family: var(--font-mono); }
table tr.cur td { background: rgba(28,90,60,.06); }

/* generic ledger tables (dashboard) */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
table th {
  text-align: left;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  padding: 0.45rem 0.8rem;
  border-bottom: 2px solid var(--ink);
  white-space: nowrap;
}
table td { padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
table tbody tr:hover { background: rgba(29,38,29,.035); }
code {
  font-family: var(--font-mono);
  font-size: 0.8em;
  background: var(--paper-deep);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  padding: 0.08em 0.34em;
  overflow-wrap: anywhere;
}

/* toasts */
.toast-stack { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: 0.6rem; z-index: 60; max-width: 24rem; }
.toast {
  background: var(--ink); color: var(--paper-ink);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: 0.84rem;
  box-shadow: 0 10px 24px rgba(29,38,29,.25);
  display: flex; gap: 0.7rem; align-items: flex-start;
  animation: ink-in var(--dur-med) var(--ease-out);
}
.toast.ok { border-left: 1px solid var(--green); }
.toast.warn { background: var(--paper-ink); color: var(--ink); border-color: var(--copper); }
.toast.err { background: var(--red); border-color: var(--red); }
.toast.warn { background: var(--paper-ink); color: var(--ink); border-color: var(--copper); }
.toast .close { margin-left: auto; background: none; border: 0; color: inherit; font-size: 1rem; cursor: pointer; line-height: 1; }

/* switch */
.switch { position: relative; display: inline-block; width: 2.5rem; height: 1.25rem; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob { position: absolute; inset: 0; border: 1px solid var(--ink); border-radius: 999px; background: var(--paper-deep); transition: background var(--dur-fast); cursor: pointer; }
.switch .knob::after { content: ''; position: absolute; top: 2px; left: 2px; width: 0.83rem; height: 0.83rem; border-radius: 50%; background: var(--ink-muted); transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast); }
.switch input:checked + .knob { background: var(--green); }
.switch input:checked + .knob::after { transform: translateX(1.15rem); background: var(--paper-ink); }
.switch input:focus-visible + .knob { outline: 2px solid var(--copper); outline-offset: 2px; }

/* ── auth pages ────────────────────────────────────────────────────────────── */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}
.auth-body::before {
  content: '';
  position: fixed;
  inset: -40% -30%;
  background-image: url('/assets/svg/rosette.svg');
  background-size: 70rem;
  background-position: 80% -10%;
  opacity: 0.05;
  pointer-events: none;
  filter: grayscale(1);
}
.auth-card { width: min(28rem, 100%); position: relative; }
.auth-card .ac-body { display: grid; gap: 1rem; padding: 1.4rem 1.3rem 1.6rem; }
.auth-card h1 { font-size: 1.45rem; }
.auth-card .ac-sub { color: var(--ink-muted); font-size: 0.88rem; margin: 0; }
.auth-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.2rem; }
.auth-tabs .tab {
  flex: 1; text-align: center; padding: 0.55rem 0.6rem;
  font-weight: 700; font-size: 0.8rem; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-muted); border: 1px solid transparent; border-bottom-color: var(--rule);
  background: none; cursor: pointer;
}
.auth-tabs .tab[aria-selected="true"] { color: var(--ink); border-color: var(--rule); border-bottom-color: var(--ink); }
.auth-msg { font-size: 0.86rem; }
.auth-msg.ok { color: var(--green-ink); }
.auth-msg.err { color: var(--red); }
.auth-msg.hidden { display: none; }
.auth-alt { font-size: 0.86rem; color: var(--ink-muted); text-align: center; }
.auth-note { margin: 0.9rem 0 0; }
.hint-inline { display: inline; padding-left: 0.3rem; font-weight: 500; text-transform: none; letter-spacing: 0; }

/* ── responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 64rem) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 48rem) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto; grid-template-areas: "top" "main"; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--rule); display: none; }
  .sidebar.open { display: flex; }
  .side-toggle { display: inline-grid; }
  .side-nav { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 1rem; }
  .user-chip .u-mail { display: none; }
  .topbar .ws-switch { display: none; }
}