/*
 * Touch and one identity — October 2026.
 *
 * Minutos Network is used on an iPad in an office and a phone in a van, and it
 * is heading for the App Store. Two things were in the way: the workspace home
 * had been made touch-worthy while every screen that does real work — invoices,
 * reconciliation, bills, reports — still had desktop-sized controls, and the
 * product wore three palettes at once (its own green, a Xero-blue reference
 * layer, a navy shell).
 *
 * This file is additive and loads last, so it changes no markup and no
 * behaviour. It does two jobs:
 *
 *   1. Makes every screen usable with a thumb: 48px controls, 16px fields (iOS
 *      zooms anything smaller the moment it is tapped), safe-area insets on all
 *      four sides rather than only the bottom, and scroll that stops at the edge
 *      of the app instead of rubber-banding the page behind it.
 *   2. Settles the palette on the green one, so Minutos Network and FixMinute
 *      read as one company.
 *
 * It deliberately does not touch `.mn-touch` (the workspace shell already does
 * this for itself) or the printed invoice, which is a paper document and should
 * stay one.
 */

:root {
  /* One identity. The blue reference layer becomes the product's own green,
     and the dark chrome becomes the deep green it should always have been. */
  --xero: var(--brand);
  --navy: var(--brand);
  --tap: 48px;                 /* a gloved thumb, not a mouse pointer */
  --tap-small: 44px;           /* Apple's floor, for secondary controls */
}

/* ---- the app should feel like an app ------------------------------------ */

html {
  -webkit-text-size-adjust: 100%;          /* a rotated iPad must not reflow type */
}
body:not(.invoice-print):not(.print-document) {
  overscroll-behavior-y: contain;          /* no rubber-band, no pull-to-refresh */
}
button, .button, a.button, summary, input[type="submit"], select {
  touch-action: manipulation;              /* no 300ms double-tap wait */
  -webkit-tap-highlight-color: rgba(23, 107, 85, .12);
}

/* ---- room for the hardware --------------------------------------------- */

body:not(.invoice-print):not(.print-document) .shell {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(80px, calc(40px + env(safe-area-inset-bottom)));
}
.topbar, .mn-topbar {
  padding-top: env(safe-area-inset-top, 0px);
}

/* ---- controls a thumb can hit ------------------------------------------- */

button,
.button,
a.button,
input[type="submit"],
input[type="button"] {
  min-height: var(--tap);
  padding-inline: 18px;
  font-size: 16px;
  border-radius: 10px;
}
/* The two properties below carry !important deliberately. This file exists to
   win over rules written before the product had to work on a phone, and the
   cost of losing is not cosmetic: a field under 16px makes iOS zoom the page on
   focus, and the zoom does not come back on its own. Everything else here is
   ordinary cascade. */
/* `input` with no type attribute is a text field, and an attribute selector
   does not match a default — which is how three fields on this very form were
   missed the first time. Select by what is excluded instead. */
input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]),
select, textarea {
  min-height: var(--tap) !important;
  font-size: 16px !important;
  padding: 10px 12px;
  border-radius: 10px;
}
input[type="hidden"] { min-height: 0 !important; }
input[type="checkbox"], input[type="radio"] { min-width: 24px; min-height: 24px; }
textarea { min-height: 120px; }
label { display: block; margin-bottom: 4px; }
summary { min-height: var(--tap-small); display: flex; align-items: center; }

/* Links that act as buttons in toolbars and lists. */
.mn-nav a, .mega-menu a, .status-strip a, nav a {
  min-height: var(--tap-small);
  display: inline-flex;
  align-items: center;
}

/* ---- tables: the thing an accountant actually reads ---------------------- */

.table-wrap, .scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; }
table th, table td {
  padding-block: 12px;                     /* a 44px row, not a 28px one */
}
table thead th {
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 1;
}
table a, table button { min-height: var(--tap-small); }
/* Figures line up when they are tabular, which is half of looking like
   accounting software. */
td.amount, th.amount, .amount, .total, .balance, .money {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---- the palette, settled ----------------------------------------------- */

.mn-topbar, .topbar { background: var(--brand); }
.mn-nav a[aria-current="page"], .mn-nav a.active { box-shadow: inset 0 -3px 0 var(--brand); }
.status-strip { background: var(--brand-soft); color: var(--ink); }
a { color: var(--brand); }
::selection { background: color-mix(in srgb, var(--brand) 22%, transparent); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ---- iPad: two hands, one screen ---------------------------------------- */

@media (min-width: 768px) and (max-width: 1180px) {
  .shell { width: min(100%, calc(100% - 32px)); padding-top: 24px; }
  /* Forms that were two columns on a desktop are easier to fill one-handed on
     a tablet in portrait. */
  form .row, .grid-2 { grid-template-columns: 1fr; }
}

/* ---- phone --------------------------------------------------------------- */

@media (max-width: 700px) {
  .shell { padding-top: 16px; }
  table thead { display: none; }           /* stacked rows read better than a squeeze */
  table.stacked td { display: block; width: 100%; }
  table.stacked td::before { content: attr(data-label) " "; color: var(--muted); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- DNS records ---------------------------------------------------------
   A DKIM value is one unbroken 250-character token. Left alone it widens the
   table past the screen and takes the whole page sideways with it, which on a
   phone is the difference between copying the record and giving up. The table
   scrolls inside its own box; the value wraps anywhere, since the owner is
   selecting it rather than reading it. */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table-scroll table { min-width: 0; }
.breakable, .breakable code {
  overflow-wrap: anywhere;
  word-break: break-all;
  white-space: normal;
}
.breakable code { font-size: 13px; line-height: 1.5; }

@media (max-width: 700px) {
  /* Stacked, because four columns of long values cannot be read side by side. */
  .table-scroll table thead { display: none; }
  .table-scroll table td { display: block; width: 100%; }
}

/* ---- inline "add it here" blocks ----------------------------------------
   A <details> used as a form section, so an invoice can name a customer that
   does not exist yet without JavaScript and without losing the draft. The
   summary is a tap target, not a 14px hyperlink. */

.inline-new { border: 1px solid var(--line, var(--line)); border-radius: 10px; padding: 0; }
.inline-new > summary {
  cursor: pointer; padding: 14px 16px; min-height: var(--tap, 48px);
  display: flex; align-items: center; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.inline-new[open] > summary { border-bottom: 1px solid var(--line, var(--line)); }
.inline-new > .form-grid, .inline-new > .helper { padding: 16px; }
.inline-new > .helper { padding-top: 0; }
