:root {
  --bg: #0c0c0d;
  --panel: #101011;
  --raised: #151516;
  --field: #121213;
  --line: rgba(236, 232, 225, 0.075);
  --line-strong: rgba(236, 232, 225, 0.14);
  --text: #ebe7df;
  --muted: #9b968d;
  --faint: #6b675f;
  --accent: #e9e3d6;
  --accent-ink: #141413;
  --ok: #95b5a0;
  --warn: #cfae7a;
  --bad: #d69486;
  --radius: 10px;
  --radius-small: 7px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul, ol, dl, dd, fieldset, legend { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
img { display: block; max-width: 100%; }
button, input, textarea { font: inherit; color: inherit; }

:focus { outline: none; }
:focus-visible { outline: 2px solid rgba(233, 227, 214, 0.6); outline-offset: 2px; border-radius: var(--radius-small); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.mono { font-family: var(--mono); font-size: 0.93em; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.break { overflow-wrap: anywhere; }

.wordmark { font: 500 13px/1 var(--mono); letter-spacing: 0.02em; color: var(--text); }
.eyebrow { font: 500 11px/1 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--faint); margin-bottom: 12px; }
.title { font: 500 20px/1.25 var(--mono); letter-spacing: -0.015em; color: var(--text); overflow-wrap: anywhere; }
.link { color: var(--text); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.link:hover { text-decoration-color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-small);
  background: transparent; color: var(--text);
  font-size: 13.5px; font-weight: 500; line-height: 1; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease), color 0.16s var(--ease), transform 0.12s var(--ease), opacity 0.16s var(--ease);
}
.btn:hover { background: rgba(236, 232, 225, 0.05); border-color: rgba(236, 232, 225, 0.2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.42; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #f4efe4; border-color: #f4efe4; }
.btn-quiet { border-color: transparent; color: var(--muted); padding: 0 10px; }
.btn-quiet:hover { color: var(--text); border-color: transparent; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { color: #e6a99c; }
.btn-small { min-height: 30px; padding: 0 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn.is-busy { opacity: 0.7; cursor: progress; }

/* Boot and sign-in */
.boot, .login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.boot-note { margin-top: 12px; color: var(--muted); }
.login-card {
  width: min(100%, 348px); display: grid; gap: 16px;
  padding: 30px 28px 28px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px;
  animation: rise 0.42s var(--ease) both;
}
.login-title { font: 500 19px/1.2 var(--mono); letter-spacing: -0.015em; margin-top: 14px; }
.login-lead { color: var(--muted); margin-top: -10px; margin-bottom: 4px; }

/* Shell */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr) 372px; min-height: 100dvh; animation: fade 0.3s ease both; }

.sidebar { border-right: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; min-width: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 20px 18px; }
.sidebar-toggle { display: none; }
.sidebar-body { display: flex; flex-direction: column; flex: 1; min-height: 0; padding: 0 14px 14px; }
.sidebar-body > .eyebrow { margin: 24px 6px 10px; }
.sidebar-body nav { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.sidebar-body > .muted { padding: 0 6px; }
.sidebar-foot { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.engine-line { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); padding-left: 6px; min-width: 0; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: none; }
.engine-line.is-ready .dot { background: var(--ok); }
.engine-line.is-off .dot { background: var(--warn); }

.draft-list { display: grid; gap: 2px; }
.draft-item {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline;
  padding: 9px 10px; border: 0; border-radius: var(--radius-small);
  background: transparent; text-align: left; cursor: pointer;
  transition: background-color 0.16s var(--ease);
}
.draft-item:hover { background: rgba(236, 232, 225, 0.04); }
.draft-item[aria-current="true"] { background: rgba(236, 232, 225, 0.07); }
.draft-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-ticker { font: 12px/1.4 var(--mono); color: var(--muted); }
.draft-status { grid-column: 1 / -1; font-size: 12px; color: var(--faint); }

/* Studio */
.studio { min-width: 0; padding: 34px 40px 80px; }
.studio > section { max-width: 640px; margin: 0 auto; }
.studio-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 1px solid var(--line); margin-bottom: 26px; }
.studio-head .eyebrow { margin-bottom: 9px; }
.studio-state { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; flex: none; text-align: right; }
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); font: 500 11.5px/1 var(--mono); color: var(--muted); white-space: nowrap; }
.chip.is-ok { color: var(--ok); border-color: rgba(149, 181, 160, 0.3); }
.chip.is-warn { color: var(--warn); border-color: rgba(207, 174, 122, 0.3); }
.chip.is-bad { color: var(--bad); border-color: rgba(214, 148, 134, 0.3); }

.empty { padding-top: 16vh; display: grid; gap: 14px; justify-items: start; animation: rise 0.4s var(--ease) both; }
.empty .muted { max-width: 46ch; }

.notice { padding: 11px 14px; border-radius: var(--radius-small); border: 1px solid rgba(207, 174, 122, 0.22); background: rgba(207, 174, 122, 0.055); color: #dcc59c; margin-bottom: 20px; }
.notice.small { margin: 12px 0 0; padding: 9px 12px; }
.notice.is-bad { border-color: rgba(214, 148, 134, 0.24); background: rgba(214, 148, 134, 0.06); color: #e2ab9f; }

.editor, .invoice { display: grid; gap: 30px; animation: rise 0.36s var(--ease) both; }
.group { display: grid; gap: 18px; }
.group > legend { font: 500 11px/1 var(--mono); letter-spacing: 0.09em; text-transform: uppercase; color: var(--faint); padding-bottom: 14px; }
.group + .group { padding-top: 28px; border-top: 1px solid var(--line); }

.identity { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 20px; }
.identity-text { display: grid; gap: 18px; align-content: start; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.field { display: grid; gap: 7px; min-width: 0; align-content: start; }
.field-narrow { max-width: 260px; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field input[type="text"], .field input[type="url"], .field input[type="password"], .field textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  background: var(--field); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-small);
  transition: border-color 0.16s var(--ease), background-color 0.16s var(--ease);
}
.field textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.field input::placeholder, .field textarea::placeholder { color: var(--faint); }
.field input:hover, .field textarea:hover { border-color: rgba(236, 232, 225, 0.2); }
.field input:focus-visible, .field textarea:focus-visible { outline: none; border-color: rgba(233, 227, 214, 0.55); background: #141415; }
.field.has-error input, .field.has-error textarea, .field.has-error .image-drop { border-color: rgba(214, 148, 134, 0.55); }
.hint { font-size: 12px; color: var(--faint); line-height: 1.5; }
.error { font-size: 12.5px; color: var(--bad); line-height: 1.45; }

.affix { position: relative; }
.affix input { padding-right: 52px; }
.affix-unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font: 500 11.5px/1 var(--mono); color: var(--faint); pointer-events: none; }

.image-drop {
  display: grid; place-items: center; aspect-ratio: 1; width: 100%;
  background: var(--field); border: 1px dashed var(--line-strong); border-radius: var(--radius);
  cursor: pointer; overflow: hidden;
  transition: border-color 0.16s var(--ease), background-color 0.16s var(--ease);
}
.image-drop:hover, .image-drop.is-over { border-color: rgba(236, 232, 225, 0.3); background: #151516; }
.image-drop img { width: 100%; height: 100%; object-fit: cover; animation: fade 0.3s ease both; }
.image-placeholder { font-size: 12.5px; color: var(--muted); }
#f-image:focus-visible + .hint { color: var(--muted); }
.image-field:focus-within .image-drop { border-color: rgba(233, 227, 214, 0.55); }
.image-field .btn { justify-self: start; margin-left: -10px; }

.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding-top: 22px; border-top: 1px solid var(--line); }
.actions-gap { flex: 1; }

/* Invoice */
.card { padding: 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.headline { font: 500 16px/1.3 var(--mono); letter-spacing: -0.01em; margin-bottom: 5px; }
.card .notice { margin: 14px 0 0; }
.steps { display: grid; gap: 0; margin-top: 18px; }
.steps li { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 12px; padding: 7px 0; color: var(--faint); }
.steps li::before { content: ""; width: 8px; height: 8px; margin: 7px 5px 0; border-radius: 50%; border: 1px solid var(--faint); transition: background-color 0.3s var(--ease), border-color 0.3s var(--ease); }
.steps li.is-done { color: var(--muted); }
.steps li.is-done::before { background: var(--ok); border-color: var(--ok); }
.steps li.is-active { color: var(--text); }
.steps li.is-active::before { border-color: var(--text); background: var(--text); animation: breathe 1.8s ease-in-out infinite; }
.steps li.is-stopped::before { border-color: var(--bad); background: var(--bad); animation: none; }

.copy-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.copy-row:first-of-type { padding-top: 0; }
.copy-row .btn { flex: none; }
.address { font-size: 13px; overflow-wrap: anywhere; line-height: 1.5; margin-top: 3px; }
#ca-value { font-size: 11px; }
.amount { font-size: 18px; margin-top: 2px; }

.ledger { display: grid; }
.ledger > div { display: flex; justify-content: space-between; gap: 18px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ledger > div:last-child { border-bottom: 0; }
.ledger dt { color: var(--muted); flex: none; }
.ledger dd { text-align: right; min-width: 0; }
.ledger-total dt, .ledger-total dd { color: var(--text); font-weight: 500; }
.card .ledger + .hint, .card .transactions + .hint { margin-top: 12px; }
.card .copy-row + .ledger { margin-top: 4px; }

.transactions { display: grid; margin-top: 4px; }
.transactions li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.transactions .tx-state { color: var(--faint); font-size: 12px; }

/* Inspector */
.inspector { border-left: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; height: 100dvh; overflow-y: auto; min-width: 0; }
.panel { padding: 24px 22px; border-bottom: 1px solid var(--line); }
.panel:last-child { border-bottom: 0; }
.panel-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }

.preview { display: grid; grid-template-columns: 60px minmax(0, 1fr); gap: 14px; align-items: center; }
.preview-image { width: 60px; height: 60px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line); overflow: hidden; display: grid; place-items: center; font: 500 20px/1 var(--mono); color: var(--faint); }
.preview-image img { width: 100%; height: 100%; object-fit: cover; }
.preview-name { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; line-height: 1.3; }
.preview-description { margin-top: 14px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 9.3em; overflow: hidden; }
.preview-description:empty { display: none; }
.preview-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.preview-links:empty { display: none; }
.preview-links li { font: 12px/1 var(--mono); color: var(--muted); padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.notes { display: grid; gap: 8px; margin: 16px 0 18px; }
.notes li { position: relative; padding-left: 14px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.notes li::before { content: ""; position: absolute; left: 0; top: 0.72em; width: 5px; height: 1px; background: var(--faint); }
#launch + .hint { margin-top: 10px; }
#launch-hint:empty { display: none; }

/* Dialog */
.dialog { width: min(calc(100% - 32px), 480px); padding: 0; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--raised); color: var(--text); }
.dialog::backdrop { background: rgba(6, 6, 7, 0.72); }
.dialog[open] { animation: rise 0.26s var(--ease) both; }
.dialog form { display: grid; gap: 16px; padding: 26px; }
.dialog .notes { margin: 0; }
.dialog .actions { padding-top: 18px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 10px 16px; background: #1b1b1c; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 13px; z-index: 20; animation: rise 0.22s var(--ease) both; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
/* The toast keeps its horizontal centring while it rises. */
.toast { animation-name: toast-rise; }
@keyframes toast-rise { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Narrower screens: the inspector moves under the editor, then the sidebar folds away. */
@media (max-width: 1180px) {
  .app { grid-template-columns: 232px minmax(0, 1fr); }
  .inspector { grid-column: 2; position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); background: transparent; padding: 0 40px 60px; }
  .inspector .panel { max-width: 640px; margin: 0 auto; padding-left: 0; padding-right: 0; }
  .studio { padding-bottom: 40px; }
}
@media (max-width: 760px) {
  .app { display: block; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-head { padding: 14px 18px; }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-body { display: none; padding: 0 14px 16px; }
  .sidebar.is-open .sidebar-body { display: flex; }
  .sidebar-body nav { max-height: 46vh; }
  .studio { padding: 24px 18px 32px; }
  .inspector { padding: 0 18px 48px; }
  .studio-head { align-items: flex-start; }
  .identity { grid-template-columns: 104px minmax(0, 1fr); gap: 14px; }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .field-narrow { max-width: none; }
  .copy-row { flex-direction: column; align-items: stretch; }
  .ledger > div { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 auto; }
  .actions-gap { display: none; }
  .field input[type="text"], .field input[type="url"], .field input[type="password"], .field textarea { font-size: 16px; }
}

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