/* AIR PTT Control (HQ, Partner Portal, public pages). Tokens, header, buttons, forms come from airptt.css.
 * Page styles below are copied from console/style.css; Control additions are at the end. */

.app { min-height: 100vh; display: flex; flex-direction: column; }
.spacer { flex: 1; }
.org-picker { width: auto; min-width: 200px; max-width: 100%; min-height: 36px; padding: 0 10px; }

/* ---- navigation ---- */
.nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line); }
.nav a {
  padding: 12px 14px; text-decoration: none; color: var(--text-muted); white-space: nowrap; font-weight: 600; font-size: 14px;
  border-top: 2px solid transparent; margin-top: -1px;
}
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); border-top-color: var(--red); }
main { width: 100%; max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; flex: 1; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-family: var(--display); font-size: 34px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
h2 { font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; }
.dialog h2 { font-size: 18px; letter-spacing: 0; text-transform: none; color: var(--text); }
.signin h1 { font-family: var(--display); font-size: 34px; text-transform: uppercase; }

/* ---- surfaces ---- */
.card { margin-bottom: 16px; }
.card > h2:first-child { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-family: var(--display); font-size: 44px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat span { color: var(--text-muted); font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1 1 220px; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--text-muted); font-size: .875rem; overflow-wrap: anywhere; }
.row .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { color: var(--text-muted); padding: 12px 0; margin: 0; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-muted); font-size: 12px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; border-top: 0; white-space: nowrap; }

/* ---- status pills (online = cyan, never green) ---- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--radius);
  border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: transparent; border: 1.5px solid var(--line-strong); }
.pill.good { color: var(--rx); border-color: color-mix(in srgb, var(--rx) 45%, var(--line)); }
.pill.good::before { background: var(--rx); border-color: var(--rx); }
.pill.bad { color: var(--red-text); background: var(--red-tint); border-color: color-mix(in srgb, var(--red) 55%, var(--line)); }
.pill.bad::before { background: var(--red); border-color: var(--red); }
.pill.warn { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 55%, var(--line)); }
.pill.warn::before { background: var(--amber); border-color: var(--amber); }
.tag { display: inline-block; padding: 1px 8px; margin: 0 4px 4px 0; border-radius: var(--radius-sm); background: var(--surface-raised); font-size: 12px; }

/* ---- forms ---- */
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.inline .field { margin: 0; flex: 1 1 160px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; margin: 0; padding: 8px 0; min-height: 44px; }
.check input { width: 18px; height: 18px; flex: none; accent-color: var(--red); }
.checks { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; }

/* ---- location ---- */
.loc-controls .hint { margin: 4px 0 12px; color: var(--text-muted); font-size: 13px; }
.loc-controls .hint.indent { margin-left: 28px; margin-top: -6px; }
.loc-controls[hidden], .loc-controls .field[hidden], .warn-note[hidden] { display: none; }
.warn-note { margin: 0 0 12px; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--amber) 55%, var(--line)); border-radius: var(--radius); color: var(--amber); font-size: 14px; }
.loc-group { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 4px; }

/* ---- dialog ---- */
.dialog {
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); background: var(--surface); color: var(--text); box-shadow: 0 12px 48px rgb(0 0 0 / 55%);
}
.dialog::backdrop { background: rgb(0 0 0 / 60%); }
.dialog form, .dialog .body { padding: 20px; }
.buttons { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.signin .buttons .btn { width: 100%; }
.qr { display: block; width: 100%; max-width: 280px; height: auto; margin: 8px auto 12px; border-radius: var(--radius); background: #fff; padding: 8px; }
.link-box { display: flex; gap: 8px; }
.link-box input { font-family: var(--mono); font-size: .8rem; }

/* ---- toasts ---- */
.toasts { position: fixed; left: 0; right: 0; bottom: 16px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; z-index: 10; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); max-width: 520px; box-shadow: 0 6px 24px rgb(0 0 0 / 40%); font-weight: 600; }
.toast.bad { background: var(--red); color: #fff; }

/* ---- reports ---- */
.report-bar { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 16px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab {
  min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius); background: transparent;
  color: var(--text-muted); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--surface-raised); }
.tab[aria-selected="true"], .tab[aria-pressed="true"] { color: var(--text); background: var(--surface-raised); border-color: var(--line-strong); box-shadow: inset 0 -2px 0 var(--red); }
.report-section .page-head { margin-bottom: 8px; }
.report-section .page-head h2 { margin: 0; }
.report-section[hidden] { display: none; }
.card.inner { background: transparent; padding: 0; border: 0; margin: 16px 0 0; }
th.num, td.num { text-align: right; white-space: nowrap; }
th .sort { all: unset; cursor: pointer; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; white-space: nowrap; }
th .sort:hover, th .sort:focus-visible { color: var(--text); }
th[aria-sort="ascending"] .sort::after { content: " \25B2"; font-size: 9px; }
th[aria-sort="descending"] .sort::after { content: " \25BC"; font-size: 9px; }
.print-only { display: none; }

@media print {
  :root { --bg: #fff; --surface: #fff; --surface-raised: #f1f1f1; --line: #bbb; --line-strong: #777; --text: #000; --text-muted: #444; --rx: #005a70; --red-text: #a50012; --red-tint: #fff; --amber: #7a5200; }
  html, body { background: #fff !important; color: #000 !important; }
  .ap-header, .nav, .toasts, .no-print, dialog { display: none !important; }
  main { max-width: none; padding: 0; }
  .print-only { display: block; margin: 0 0 12px; color: #444; }
  .report-section[hidden] { display: block !important; }
  .report-section { break-inside: auto; border: 0; padding: 0; margin: 0 0 18px; }
  .report-section + .report-section { break-before: page; }
  .stat { border-color: #999; break-inside: avoid; }
  .stat b { color: #000; }
  tr { break-inside: avoid; }
  .table-wrap { overflow: visible; }
  table { font-size: 11px; }
  th .sort::after { content: none !important; }
  a { color: #000; text-decoration: none; }
}

@media (max-width: 560px) {
  :root { --gutter: 16px; }
  .row .actions { width: 100%; }
  .ap-tools .who { display: none; }
  .page-head h1 { font-size: 28px; }
}

/* ================================================================ Control additions */

/* ---- header: product, partner, user menu ---- */
.ap-header .ap-product { color: var(--text); }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary .who { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 12px 32px rgb(0 0 0 / 50%);
}
.menu-panel .meta { padding: 6px 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.menu-panel .meta b { display: block; color: var(--text); font-size: 14px; }
.menu-panel .btn { width: 100%; justify-content: flex-start; border-color: transparent; }

/* ---- layout: top nav on small screens, left nav on wide screens ---- */
.layout { display: flex; flex: 1; min-height: 0; }
.layout main { min-width: 0; }
@media (min-width: 960px) {
  .layout .nav {
    flex-direction: column; gap: 2px; overflow: visible; padding: 16px 8px; width: 220px; flex: none;
    border-bottom: 0; border-right: 1px solid var(--line);
  }
  .layout .nav a { border-top: 0; margin-top: 0; border-left: 2px solid transparent; border-radius: 0 var(--radius) var(--radius) 0; }
  .layout .nav a[aria-current="page"] { border-left-color: var(--red); background: var(--surface-raised); }
  .layout .nav .nav-group { padding: 14px 14px 4px; }
}
@media (max-width: 959px) { .layout { flex-direction: column; } .nav .nav-group { display: none; } }
.nav .nav-group { color: var(--text-muted); font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; }

/* ---- sign-in screens ---- */
.signin .lead { color: var(--text-muted); }
.signin .card + .links { margin-top: 12px; text-align: center; }
.signin .links a { color: var(--text-muted); font-size: 14px; }
.secret { font-family: var(--mono); font-size: 14px; letter-spacing: 1px; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.codes { list-style: none; padding: 0; margin: 12px 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; font-family: var(--mono); font-size: 15px; }
.codes li { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; text-align: center; }
.code-input { font-family: var(--mono); font-size: 20px !important; letter-spacing: 6px; text-align: center; }

/* ---- filters and tables ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; margin-bottom: 12px; }
.filters .field { margin: 0; flex: 1 1 150px; min-width: 0; }
.filters .field.wide { flex-basis: 220px; }
.filters input[type="date"] { width: 100%; padding: 10px 12px; font: inherit; color: var(--text); min-height: 44px; background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius); color-scheme: dark; }
td .detail { font-family: var(--mono); font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; max-width: 420px; }
td.nowrap, th.nowrap { white-space: nowrap; }
.more { display: flex; justify-content: center; margin-top: 12px; }
.placeholder-note { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 16px; color: var(--text-muted); }
.public main { max-width: 640px; }

/* ---- HQ: dashboard, detail pages, charts (spec 20c) ---- */
.stat.wide b { font-size: 30px; line-height: 1.15; overflow-wrap: anywhere; }
.stat a { color: inherit; text-decoration: none; display: block; }
.stat a:hover b { color: var(--rx); }
.stat small { display: block; color: var(--text-muted); margin-top: 4px; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.chips a { text-decoration: none; }
.chips .pill { padding: 6px 10px; }
.kv { display: grid; grid-template-columns: minmax(110px, 190px) 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--text-muted); font-size: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; padding-top: 2px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); gap: 16px; align-items: start; }
.grid2 > .card { margin-bottom: 0; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar-new { fill: var(--rx); }
.chart .bar-lost { fill: var(--red); }
.chart .bar-used { fill: var(--rx); }
.chart .bar-cap { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 4 3; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; }
.legend i.new { background: var(--rx); }
.legend i.lost { background: var(--red); }
.meter { height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; overflow: hidden; margin: 6px 0; }
.meter > span { display: block; height: 100%; background: var(--rx); }
.meter.over > span { background: var(--amber); }
.pager { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
a.plain { color: inherit; font-weight: 600; text-decoration: none; }
a.plain:hover { color: var(--rx); text-decoration: underline; }
.note { border-top: 1px solid var(--line); padding: 10px 0; }
.note:first-child { border-top: 0; }
.note .meta { color: var(--text-muted); font-size: .8125rem; }
.hidden-field { display: none; }
.mono { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; } .kv dt { padding-top: 8px; } }
textarea { width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius); resize: vertical; }
textarea:focus-visible { outline: 2px solid var(--rx); outline-offset: 1px; }
