/* The application chrome: the bar, the mapping report, the page the document sits on. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.studio { display: flex; flex-direction: column; min-height: 100%; }

/* ---- bar -----------------------------------------------------------------------------------
 * Dark chrome, the same in both themes — the application's own surface, distinct from the paper
 * it is holding. This is the same treatment Advanced Charts gives its edit bar, so the two
 * widgets read as one family when they share a document. */
.studio-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 16px;
  background: var(--chrome); color: var(--chrome-ink);
  border-bottom: 1px solid var(--chrome-rule);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
  position: sticky; top: 0; z-index: 10;
}
.studio-bar__brand { display: flex; align-items: center; gap: 9px; margin-right: 2px; }
/* The mark is brand blue, which disappears into dark chrome; a white plate keeps the official
 * colours official and legible at once. */
.studio-bar__logo {
  height: 22px; width: 22px; flex: none;
  background: #fff; border-radius: 6px; padding: 2px;
}
.studio-bar__name { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }

/* The mode pill: a dot plus a word, because colour alone is not information. */
.studio-bar__mode {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 650; letter-spacing: .04em;
  padding: 3px 10px; border-radius: 999px;
  background: var(--chrome-soft); color: var(--chrome-ink);
}
.studio-bar__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--chrome-mute); flex: none; }
.studio-bar__mode.is-live .studio-bar__dot { background: #59c98f; }
.studio-bar__mode.is-ro .studio-bar__dot { background: #e6b566; }
.studio-bar__mode.is-demo .studio-bar__dot { background: #7fb2f0; }
.studio-bar__spacer { flex: 1 1 auto; }

.studio-select {
  font: inherit; font-size: 14px;
  padding: 6px 10px; min-width: 220px; max-width: 100%;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule-2); border-radius: var(--radius);
  transition: border-color var(--speed), background var(--speed), box-shadow var(--speed);
}
.studio-select:hover { border-color: var(--accent); }
.studio-select--sm { min-width: 0; font-size: 13px; padding: 5px 8px; }
.studio-btn--sm { font-size: 12.5px; padding: 4px 10px; margin-top: 8px; }

/* Controls that sit ON the chrome: translucent over dark, with a light chevron of their own,
 * because the native one disappears against it. */
.studio-bar .studio-select {
  color: var(--chrome-ink); background: var(--chrome-soft);
  border-color: var(--chrome-rule);
  appearance: none; -webkit-appearance: none;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239db1c4' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
.studio-bar .studio-select:hover { background-color: var(--chrome-soft-2); border-color: var(--chrome-soft-2); }
.studio-bar .studio-select option { color: var(--ink); background: var(--surface); }
.studio-bar .studio-btn {
  color: var(--chrome-ink); background: var(--chrome-soft);
  border-color: var(--chrome-rule);
}
.studio-bar .studio-btn:hover { background: var(--chrome-soft-2); border-color: var(--chrome-soft-2); color: var(--chrome-ink); }
.studio-bar .studio-btn--primary { background: var(--chrome-ink); border-color: transparent; color: var(--chrome); font-weight: 650; }
.studio-bar .studio-btn--primary:hover { background: #fff; color: var(--chrome); filter: none; }
.studio-bar :focus-visible { outline-color: var(--chrome-ink); }

/* Toast. setTimeout rather than rAF to reveal it, because rAF is starved while the tab is not
 * compositing — an embedded Grist widget in a background tab — and a "Saved" confirmation that
 * never appears is worse than one that appears without an animation. */
.ap-toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 12px);
  z-index: 60; max-width: min(520px, calc(100vw - 32px));
  padding: 9px 16px; border-radius: var(--radius);
  background: var(--ink); color: var(--paper);
  font-size: 13px; line-height: 1.4;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.ap-toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.ap-toast--ok { background: var(--ok); color: #fff; }
.ap-toast--warn { background: var(--warn); color: #fff; }
.ap-toast--err { background: var(--risk); color: #fff; }
@media (prefers-reduced-motion: reduce) { .ap-toast { transition: none; } }
.studio-btn {
  font: inherit; font-size: 14px; font-weight: 550;
  padding: 6px 14px; min-height: 31px; cursor: pointer;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule-2); border-radius: var(--radius);
  transition: border-color var(--speed), background var(--speed), color var(--speed),
              box-shadow var(--speed), transform var(--speed);
}
.studio-btn:hover { border-color: var(--accent); color: var(--accent); }
/* Pressed feedback by transform, which moves the button without moving anything around it. */
.studio-btn:active { transform: translateY(1px); }
.studio-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.studio-btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.studio-btn--primary:hover { color: var(--accent-ink); filter: brightness(1.08); }
.studio-select:focus-visible, .studio-btn:focus-visible, .studio-upgrade summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .studio-btn, .studio-select { transition: none; }
  .studio-btn:active { transform: none; }
}

/* ---- body --------------------------------------------------------------------------------- */
.studio-body { flex: 1 1 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; align-items: center; }

/* ---- what we worked out about the document ------------------------------------------------ */
.studio-notice {
  width: 100%; max-width: 820px;
  background: var(--surface);
  border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  font-size: 13.5px;
  box-shadow: 0 1px 2px rgba(20, 32, 43, .04);
}
.studio-notice--warn { border-left-color: var(--warn); }
.studio-notice p { margin: 6px 0 0; }
.studio-notice__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--muted); }
.studio-notice__tables { color: var(--ink-2); }
.studio-notice__tables code, .studio-upgrade code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--sunk); border: 1px solid var(--rule);
  padding: 1px 5px; border-radius: 3px;
}
.studio-notice__warn { color: var(--warn); }
.studio-notice__tax { color: var(--muted); font-size: 13px; }
.studio-notice__tax strong { color: var(--ink-2); }

.studio-chip {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 3px;
  background: var(--sunk); color: var(--muted);
}
.studio-chip.is-strong { background: var(--ok-soft); color: var(--ok); }

.studio-upgrade { margin-top: 10px; border-top: 1px solid var(--rule); padding-top: 8px; }
.studio-upgrade summary { cursor: pointer; color: var(--accent); font-weight: 550; }
.studio-upgrade ul { margin: 8px 0 0; padding-left: 18px; }
.studio-upgrade li { margin: 4px 0; color: var(--ink-2); }
.studio-upgrade__note { color: var(--muted); font-size: 12.5px; }

/* ---- the page the document sits on --------------------------------------------------------- */
.studio-page {
  width: 100%; max-width: 820px;
  background: var(--doc-paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---- the printing frame ---------------------------------------------------------------------
 * A one-cell table around the page whose header and footer rows are the printed margins — see
 * print.js for why the sheet's own margin is zero. On screen it is plain blocks, and the two
 * margin rows are not shown. */
.studio-printframe, .studio-printframe > thead, .studio-printframe > tbody, .studio-printframe > tfoot,
.studio-printframe > * > tr, .studio-printframe__cell { display: block; width: 100%; }
.studio-printframe { max-width: 820px; border-collapse: collapse; border-spacing: 0; }
.studio-printframe__cell { padding: 0; }
.studio-printframe__gap { display: none; }

/* ---- print ---------------------------------------------------------------------------------
 * Printing an invoice should produce the invoice, not the application it was drawn in: no bar,
 * no notices, no hint strip, no toast — and none of the browser's own furniture, which is what
 * the zero page margin in print.js is for. The frame's margin rows repeat on every page. */
@media print {
  html, body { background: #fff; }
  .studio-bar, .studio-notice, .studio-hintbar, .studio-sample-note, .ap-toast { display: none !important; }
  .studio-body { padding: 0 var(--print-inset, 14mm); display: block; }
  .studio-page { max-width: none; border: 0; border-radius: 0; box-shadow: none; overflow: visible; }
  .studio-printframe { display: table; width: 100%; max-width: none; }
  .studio-printframe > thead { display: table-header-group; }
  .studio-printframe > tbody { display: table-row-group; }
  .studio-printframe > tfoot { display: table-footer-group; }
  .studio-printframe > * > tr { display: table-row; }
  .studio-printframe__cell { display: table-cell; vertical-align: top; }
  .studio-printframe__gap { display: table-cell; height: var(--print-inset, 14mm); padding: 0; }
}

/* The empty-document setup offer. */
.studio-setup__list { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.studio-setup__summary { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.studio-setup__list li { margin: 2px 0; }
.studio-setup__row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }

/* ---- the app frame -------------------------------------------------------------------------
 * Bar on top, sidebar and content side by side, each scrolling on its own. The frame fills the
 * iframe exactly; nothing scrolls the page itself, which is what makes it feel like an
 * application rather than a document. */
.studio { height: 100%; }
.studio-main { flex: 1 1 auto; display: flex; min-height: 0; }
.studio-body { overflow-y: auto; min-width: 0; }

.studio-side__kind { font-size: 11px; color: var(--muted); white-space: nowrap; padding: 0 6px; border: 1px solid var(--rule); border-radius: 999px; }

/* ---- the invoice list ----------------------------------------------------------------------- */
.studio-side {
  width: 276px; flex: none;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--rule);
}
.studio-side__head { display: flex; align-items: center; gap: 6px; padding: 12px 14px 8px; }
/* One row, in every list and in every state. Refresh, Edit and New are the same three buttons
 * whether the list is invoices, clients or the catalogue, so they must sit in the same places —
 * a header that reflows when Edit becomes Close reads as three different headers. */
.studio-side__head .studio-btn { flex: none; padding: 4px 8px; white-space: nowrap; }
/* Edit and Close are the same button wearing two words. Reserving the wider one's room is what
 * stops New moving when a record is opened. */
.studio-side__head .studio-btn--edit { min-width: 62px; }
.studio-side__count { flex: 0 1 auto; overflow: hidden; }
.studio-side__title {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
}
.studio-side__count {
  font-size: 11px; font-weight: 650; padding: 1px 8px; border-radius: 999px;
  background: var(--sunk); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.studio-side__spacer { flex: 1 1 auto; }
.studio-side__head .studio-btn--sm { margin-top: 0; }
.studio-side__tools { padding: 0 14px 10px; }
.studio-side__search {
  width: 100%; font: inherit; font-size: 13px;
  padding: 6px 9px;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule-2); border-radius: var(--radius);
  transition: border-color var(--speed), box-shadow var(--speed);
}
.studio-side__search:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.studio-side__list {
  flex: 1 1 auto; overflow-y: auto; min-height: 0;
  padding: 0 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.studio-side__row {
  appearance: none; -webkit-appearance: none; font: inherit; text-align: left;
  width: 100%; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px;
  background: transparent; color: var(--ink-2);
  border: 0; border-left: 3px solid transparent; border-radius: var(--radius);
  transition: background var(--speed), border-color var(--speed);
}
.studio-side__row:hover { background: var(--sunk); }
.studio-side__row.is-active { background: var(--accent-soft); border-left-color: var(--accent); }
.studio-side__row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.studio-side__line { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.studio-side__num {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.studio-side__total { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.studio-side__client { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.studio-side__empty { margin: 6px 8px; font-size: 12.5px; color: var(--muted); }

/* The three lists: invoices, clients, catalogue. A segmented switch at the top of the column. */
.studio-side__switch {
  display: flex; gap: 2px; margin: 12px 14px 0; padding: 3px;
  background: var(--sunk); border-radius: 8px;
}
.studio-side__tab {
  flex: 1 1 0; padding: 6px 4px; border: 0; border-radius: 6px; background: transparent;
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.studio-side__tab.is-active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.studio-side__tab:disabled { opacity: .45; cursor: not-allowed; }
.studio-side__tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* A client or a catalogue item reads as one line of text with a picture beside it — the same
 * left-aligned shape as an invoice row. The base row stacks (an invoice puts its number over its
 * client), so the direction is set back to a row here; without that the thumbnail sat above a
 * centred name and the catalogue looked like a different product from the invoice list. */
.studio-side__row--record { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.studio-side__text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.studio-side__name { font-size: 13px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.studio-side__thumb {
  width: 30px; height: 30px; flex: none; border-radius: 5px; object-fit: cover;
  border: 1px solid var(--rule); background: var(--surface);
}
.studio-side__thumb.is-empty { background: var(--sunk); }

/* The column mapping in Data: a role a line, its column beside it. */
.studio-cols { margin: 4px 0 10px; font-size: 12.5px; }
.studio-cols summary { cursor: pointer; color: var(--muted); }
.studio-cols__grid { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: 6px 10px; align-items: center; margin-top: 8px; }
.studio-cols__role { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); }
.studio-cols__row { display: contents; }
.studio-cols__row.is-chosen .studio-cols__role { color: var(--accent); font-weight: 600; }

/* Status chips: the dot reinforces the word, never replaces it. */
.studio-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 650; letter-spacing: .03em;
  color: var(--muted); white-space: nowrap; flex: none;
}
.studio-status__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex: none; }
.studio-status.is-paid { color: var(--ok); }
.studio-status.is-paid .studio-status__dot { background: var(--ok); }
.studio-status.is-overdue { color: var(--risk); }
.studio-status.is-overdue .studio-status__dot { background: var(--risk); }
.studio-status.is-sent { color: var(--accent); }
.studio-status.is-sent .studio-status__dot { background: var(--accent); }
.studio-status.is-part { color: var(--warn); }
.studio-status.is-part .studio-status__dot { background: var(--warn); }
.studio-status.is-cancelled { text-decoration: line-through; }

/* ---- the drawer ------------------------------------------------------------------------------
 * Settings and Send slide over the right edge; the document stays visible underneath, so a
 * settings change is observable as it is made. On wide screens the content shifts aside instead
 * of being covered. */
.studio-drawer {
  --drawer-w: min(560px, 100vw);
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--drawer-w);
  z-index: 40;
  background: var(--surface);
  border-left: 1px solid var(--rule);
  box-shadow: -14px 0 36px -20px rgba(0, 0, 0, .45);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .26s ease;
}
.studio-drawer.is-open { transform: none; }
.studio-drawer__body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.studio-drawer .set, .studio-drawer .snd {
  border: 0; border-radius: 0; box-shadow: none; max-width: none;
}
@media (min-width: 1100px) {
  .studio.has-drawer .studio-body { margin-right: min(560px, 100vw); }
}

/* One control or the other: the sidebar on room, the bar's picker without. */
@media (max-width: 879px) { .studio-side { display: none; } }
@media (min-width: 880px) { .studio-bar__picker { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .studio-drawer, .studio-side__row, .studio-side__search { transition: none; }
}

@media print {
  .studio-side, .studio-drawer { display: none !important; }
  .studio, .studio-main { display: block; height: auto; }
  .studio-body { overflow: visible; margin-right: 0 !important; }
}

/* The brand is the credit: it links home, quietly. */
.studio-bar__home { display: flex; align-items: center; gap: 9px; color: inherit; text-decoration: none; }
.studio-bar__home:hover .studio-bar__name { text-decoration: underline; text-underline-offset: 3px; }

/* What is owed, above the invoice list. */
.studio-side__aging { display: flex; gap: 12px; flex-wrap: wrap; padding: 0 14px 6px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.studio-side__aging .is-overdue { color: var(--warn); font-weight: 600; }

/* The one-line note above the document when something deserves attention. */
.studio-hintbar {
  width: 100%; max-width: 820px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--rule); border-left: 3px solid var(--warn);
  border-radius: var(--radius-lg);
  font-size: 13px;
}
.studio-hintbar .studio-btn--sm { margin: 0 0 0 auto; flex: none; }

/* The caption under the setup notice, over the sample document. */
.studio-sample-note {
  width: 100%; max-width: 820px; margin: 0;
  font-size: 12.5px; color: var(--muted); text-align: center;
}

/* The bar's Edit/New exist only where the sidebar (which owns them) does not. */
@media (min-width: 880px) { .studio-bar__narrow { display: none; } }

/* The head does not wrap: the buttons are trimmed to fit instead, above. A long count clips
 * before anything moves — the buttons are what a person aims at. */
.studio-side__head { flex-wrap: nowrap; }
