/* forms, library and admin pages: structure styles (portal UX rework 2026-11-21). Loaded after app.css. */

/* long per-item text: clamp to N lines, the full text is in the title / an expander */
.clamp2, .clamp3, .clamp4 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.clamp2 { -webkit-line-clamp: 2; line-clamp: 2; }
.clamp3 { -webkit-line-clamp: 3; line-clamp: 3; }
.clamp4 { -webkit-line-clamp: 4; line-clamp: 4; }

/* New instance: profile cards form an even grid */
.profile-grid { grid-auto-rows: 1fr; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 12px; }
.profile-grid .profile-card { min-height: 74px; padding: 10px 12px; }
.profile-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* form pages: sections stack with even spacing; the action bar stays in view */
.form-page > .sec { margin-top: 0; margin-bottom: 14px; }
.form-page > .sec + .sec { margin-top: 0; }
.form-page .action-bar { margin-top: 18px; }
.form-page .cli-wrap { margin: 0 2px 4px; }
.form-page .sec-body > .form-grid + .adv { margin-top: 14px; }
.sec-body > .table-wrap + .adv, .sec-body > .adv:first-child { margin-top: 4px; }

/* key/value summary rows used by detail pages */
.sum-line { display: flex; gap: 6px 18px; flex-wrap: wrap; font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.sum-line b { color: var(--text-primary); font-weight: 600; }

/* page-level toolbar under the header (environment detail, device detail) */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

/* expander for long text (details/summary) */
details.more { font-size: 12.5px; color: var(--text-secondary); }
details.more > summary { cursor: pointer; width: max-content; color: var(--accent-text); }
details.more[open] > summary { margin-bottom: 4px; }

@media (max-width: 700px) {
  .form-page .action-bar { gap: 8px; padding: 8px 12px; }
  .form-page .action-bar .ab-sum { flex-basis: 100%; min-width: 0; white-space: normal; font-size: 12.5px; }      /* wraps: its badges must stay visible */
  .form-page .action-bar .check { font-size: 13px; }
  .form-page .action-bar button.primary { flex: 1; min-height: 40px; }
  .form-page .action-bar .btn { min-height: 40px; display: inline-flex; align-items: center; }
  .form-page > .sec { margin-bottom: 10px; }
  .form-page .sec-body, .admin-page .sec-body { padding-left: 12px; padding-right: 12px; }
  .profile-grid { grid-auto-rows: auto; }
}
.sec.mt, .card.mt { margin-top: 16px; }

/* app package page: versions beside the settings column */
.app-pkg-grid { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); }
@media (max-width: 900px) { .app-pkg-grid { grid-template-columns: minmax(0, 1fr); } }

/* New instance: compact profile chooser (replaces the tile grid) */
.pc-chooser { display: flex; flex-direction: column; gap: 8px; }
.pc-sel { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pc-sel .pc-name, .pc-pick .pc-name { font-weight: 600; white-space: nowrap; }
.pc-first, .pc-d { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); font-size: 13px; }
.pc-change { margin-left: auto; flex: none; min-height: 32px; }
.pc-full { margin-top: -2px; }
.pc-full[open] { line-height: 1.45; }
.pc-panel { border: 1px solid var(--border); border-radius: var(--radius, 8px); padding: 8px; background: var(--surface-2, transparent); }
.pc-search { width: 100%; margin-bottom: 6px; }
.pc-list { max-height: 264px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.pc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; border-radius: 6px; }
.pc-row.on { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.pc-pick { display: flex; align-items: center; gap: 8px; min-width: 0; text-align: left; background: transparent; border: 0; padding: 6px 8px; min-height: 36px; color: inherit; cursor: pointer; border-radius: 6px; }
.pc-pick:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.pc-pick:focus-visible, .pc-det:focus-visible, .pc-change:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pc-det { min-width: 36px; min-height: 36px; }
.pc-more { grid-column: 1 / -1; padding: 2px 10px 8px; font-size: 12.5px; }
.pc-none { padding: 8px; }
@media (max-width: 700px) {
  .pc-sel { flex-wrap: wrap; }
  .pc-first { flex-basis: 100%; order: 5; white-space: normal; }
  .pc-change { min-height: 40px; }
  .pc-pick { min-height: 40px; flex-wrap: wrap; }
  .pc-pick .pc-d { flex-basis: 100%; white-space: normal; }
  .pc-det { min-width: 40px; min-height: 40px; }
  .pc-list { max-height: 50vh; }
}

/* Firmware: page filters sit in the list toolbar */
.fw-filters { display: contents; }
.fw-filters select { min-width: 150px; flex: 0 1 200px; }

/* Environment detail: the defaults share one compact tile */
.tile-defaults { grid-column: span 2; }
.tile-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 4px 0 0; font-size: 13px; }
.tile-dl dt { color: var(--text-secondary); }
.tile-dl dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.tile-dl dd .muted { font-weight: 400; font-size: 12px; }
@media (max-width: 700px) { .tile-defaults { grid-column: 1 / -1; } }

/* touch targets of at least 40 px on the pages built from the shared blocks */
@media (pointer: coarse), (max-width: 700px) {
  .page-head .actions button, .page-head .actions .btn, .toolbar button, .toolbar .btn,
  .form-page button, .form-page .btn, .sec-body > button, .sec-actions button, .sec-actions .btn,
  .admin-page button, .admin-page .btn, .ac-tools button, .ac-tools .btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .admin-page .sec-toggle, .form-page .sec-toggle, .admin-page .adv-toggle, .form-page .adv-toggle, .sec-body > .adv-toggle { justify-content: flex-start; }
  .cli-box > summary, details.more > summary, .sec-about summary { min-height: 40px; display: flex; align-items: center; }
  details.more > summary { width: auto; }
}

/* inline field validation (pages/fielderr.js) */
.field-err { color: var(--critical-text); font-size: 12.5px; margin-top: 3px; }
.field input.invalid, .field select.invalid { border-color: var(--critical-text); box-shadow: 0 0 0 1px var(--critical-text); }

/* New instance: extra internet providers */
.sub-head { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; }
.sub-head h3 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; color: var(--text-primary); }
.sub-head .doc-link { font-size: 13px; }
.prov-cards { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.prov-card { border: 1px solid var(--border); border-radius: var(--radius, 8px); padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; }
.prov-card-head { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.prov-card .field { margin: 0; min-width: 0; }
.prov-card .field.wide { grid-column: 1 / -1; }
.prov-card input, .prov-card select { width: 100%; box-sizing: border-box; }

/* Profiles: the title sits above its badges on phones */
@media (max-width: 700px) {
  .prof-head { flex-wrap: wrap; }
  .prof-head h2 { flex: 1 1 100%; overflow-wrap: anywhere; }
}

/* plain tables as labelled cards on phones (cardTable() in pages/fielderr.js) */
@media (max-width: 700px) {
  table.rcards, table.rcards tbody, table.rcards tr, table.rcards td { display: block; width: 100%; box-sizing: border-box; }
  table.rcards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table.rcards tr { border: 1px solid var(--border); border-radius: var(--radius, 8px); padding: 6px 12px; margin-bottom: 8px; }
  table.rcards td { border: 0; padding: 3px 0; display: grid; grid-template-columns: minmax(84px, 36%) minmax(0, 1fr); gap: 8px; text-align: left; overflow-wrap: anywhere; }
  table.rcards td::before { content: attr(data-label); color: var(--text-secondary); font-size: 12px; }
  table.rcards td:not([data-label])::before { content: none; }
  table.rcards td:empty { display: none; }
  table.rcards td.num { text-align: left; }
}

/* action bar: status badges first on their own non-shrinking line, only the text may truncate */
.ab-sum { display: flex; align-items: center; gap: 4px 8px; min-width: 0; }
.ab-sum .ab-badges { display: inline-flex; flex-wrap: wrap; gap: 4px; flex: none; }
.ab-sum .ab-badges:empty { display: none; }
.ab-sum .ab-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
@media (max-width: 700px) { .form-page .action-bar .ab-sum { flex-wrap: wrap; } .form-page .action-bar .ab-sum .ab-text { flex-basis: 100%; } }
