/* ==========================================================================
   SETTINGS - cards, forms, colour pickers, navigation editor, users.
   Also: interface scaling, uploaded logo, sign-in background.
   ========================================================================== */

/* --- Text size (Settings > Theme) ---------------------------------------- */
/* Scales page content and dialogs, not the menus, so the layout's viewport
   maths (sticky sidebar, phone bar) is untouched. */
.main .view, .modal, .auth-card { zoom: var(--ui-scale, 1); }
@media print { .main .view, .modal { zoom: 1; } }

/* --- Brand mark with an uploaded logo ------------------------------------ */
.brandmark .bm-logo { display: block; flex: none; height: 34px; width: auto; max-width: 120px; object-fit: contain; }
.sidebar .brandmark .bm-logo { height: 38px; max-width: 150px; }


.muted { color: var(--muted); }

/* --- Cards & layout -------------------------------------------------------- */
.set-card {
  padding: 16px; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.set-card-head { margin-bottom: 12px; }
.set-card-head h2 { font-size: 16px; }
.set-card-head p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }
.set-form { max-width: 520px; }
.set-grid { display: grid; gap: 4px 18px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.set-actions { display: flex; gap: 9px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.set-actions .hint { margin-right: auto; color: var(--caution-text); font-weight: 600; font-size: 13px; }
.sticky-actions {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px); z-index: 20;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(8px);
  box-shadow: var(--shadow-pop);
}
@media (min-width: 700px) { .sticky-actions { bottom: 12px; } }

/* --- Brand images ---------------------------------------------------------- */
.set-images { display: flex; flex-direction: column; gap: 14px; }
.set-image { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.si-preview {
  width: 120px; height: 80px; border-radius: var(--radius-sm); border: 1px dashed var(--line2);
  background: repeating-conic-gradient(var(--panel2) 0% 25%, var(--panel) 0% 50%) 50% / 14px 14px;
  display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 12px;
}
.si-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.si-preview.is-small img { width: 48px; height: 48px; }
.si-preview.is-wide img { width: 100%; height: 100%; object-fit: cover; }
.si-label { font-weight: 600; }
.si-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.si-actions label.btn { cursor: pointer; }
.is-busy { opacity: 0.6; pointer-events: none; }
@media (max-width: 480px) { .set-image { grid-template-columns: 1fr; } }

/* --- Colours ------------------------------------------------------------- */
.set-colours { display: flex; flex-direction: column; gap: 10px; }
.set-colour { display: grid; grid-template-columns: 46px 1fr 110px; gap: 12px; align-items: center; }
.set-colour input[type=color] {
  width: 46px; height: 40px; padding: 2px; border: 1px solid var(--line2); border-radius: var(--radius-xs);
  background: var(--panel); cursor: pointer;
}
.set-colour .sc-text label { font-weight: 600; font-size: 14px; }
.set-colour .sc-text .hint { font-size: 12.5px; color: var(--muted); }
.set-colour .sc-hex { text-transform: lowercase; }
@media (max-width: 480px) { .set-colour { grid-template-columns: 46px 1fr; } .set-colour .sc-hex { grid-column: 2; } }
input[type=range] { width: 100%; accent-color: var(--brand); }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 3px; border-radius: var(--radius-sm); background: var(--panel2); border: 1px solid var(--line); flex-wrap: wrap; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-opt span { display: block; padding: 7px 14px; border-radius: var(--radius-xs); font-size: 14px; font-weight: 600; color: var(--ink2); }
.seg-opt input:checked + span { background: var(--panel); color: var(--brand-quiet); box-shadow: var(--shadow-card); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.th-preview { padding: 16px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--line); }
.th-preview h3 { font-size: 18px; margin-bottom: 4px; }
.th-preview p { margin: 0 0 12px; color: var(--ink2); }
.th-preview a { color: var(--brand-quiet); font-weight: 600; }
.th-preview-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.th-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line2); }

/* --- Navigation editor ----------------------------------------------------- */
.nv-help { margin-bottom: 14px; }
.nv-inline svg { width: 14px; height: 14px; vertical-align: -2px; }
.nv-module { padding: 10px; }
.nv-module > .nv-row { background: var(--panel2); }
.nv-tabs { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 2px 22px; }
.nv-row {
  display: grid; grid-template-columns: auto auto auto minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel);
}
.nv-row.is-hidden { opacity: 0.6; }
.nv-row.dragging { opacity: 0.4; }
.nv-row.drop-before { box-shadow: inset 0 3px 0 var(--brand); }
.nv-row.drop-after { box-shadow: inset 0 -3px 0 var(--brand); }
.nv-grip { cursor: grab; color: var(--muted); display: grid; place-items: center; padding: 4px 0; }
.nv-grip svg { width: 18px; height: 18px; }
.nv-move { display: flex; flex-direction: column; }
.nv-move .btn { min-height: 22px; height: 22px; width: 28px; }
.nv-icon { width: 40px; min-height: 40px; }
.nv-names { display: flex; gap: 6px; min-width: 0; flex-wrap: wrap; }
.nv-names .input { flex: 2 1 160px; min-width: 0; }
.nv-names .nv-short { flex: 1 1 100px; }
.nv-opts { display: flex; gap: 6px 12px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.nv-check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600; color: var(--ink2); white-space: nowrap; cursor: pointer; }
.nv-check input { accent-color: var(--brand); width: 16px; height: 16px; }
.nv-roles { display: inline-flex; gap: 4px; }
.nv-role {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 99px;
  border: 1px solid var(--line2); font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.nv-role input { width: 13px; height: 13px; accent-color: var(--brand); margin: 0; }
.nv-role.on { background: var(--brand-wash); color: var(--brand-quiet); border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
@media (max-width: 899px) {
  .nv-row { grid-template-columns: auto auto minmax(0, 1fr); }
  .nv-grip { display: none; }
  .nv-names { grid-column: 3; }
  .nv-opts { grid-column: 1 / -1; justify-content: flex-start; }
  .nv-tabs { margin-left: 8px; }
}

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.icon-pick {
  height: 48px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel);
  display: grid; place-items: center; color: var(--ink2);
}
.icon-pick svg { width: 22px; height: 22px; }
.icon-pick:hover { background: var(--panel2); color: var(--ink); }
.icon-pick.on { border-color: var(--brand); background: var(--brand-wash); color: var(--brand-quiet); }

/* --- Users ----------------------------------------------------------------- */
.role-legend {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); font-size: 13.5px; color: var(--ink2);
}
.role-legend .pill { min-width: 62px; justify-content: center; }

/* --- Settings > Dashboard ------------------------------------------------------ */
.dl-list { list-style: none; margin: 0; padding: 0; }
.dl-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.dl-row + .dl-row { border-top: 1px solid var(--line); }
.dl-row.off .dl-name { opacity: 0.5; }
.dl-move { display: inline-flex; flex: none; }
.dl-show input { width: 18px; height: 18px; }
.dl-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dl-name svg { width: 18px; height: 18px; color: var(--muted); }
.dl-name small { flex-basis: 100%; color: var(--muted); font-size: 12.5px; }
.dl-role { width: auto; flex: 0 1 190px; min-height: 36px; }
@media (max-width: 560px) {
  .dl-row { flex-wrap: wrap; }
  .dl-role { flex-basis: 100%; }
}

/* --- Theme cards ---------------------------------------------------------- */
.th-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.th-card {
  display: flex; flex-direction: column; gap: 6px; padding: 10px; text-align: left;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); cursor: pointer;
}
.th-card:hover { border-color: var(--line2); }
.th-card.is-picked { border-color: var(--ink); }
.th-mini { display: block; padding: 10px; border: 1px solid; }
.th-mini-panel { display: flex; flex-direction: column; gap: 7px; padding: 10px; border: 1px solid; }
.th-dots { display: flex; gap: 5px; }
.th-dots i { width: 14px; height: 14px; border-radius: 50%; }
.th-bar { display: block; height: 7px; width: 80%; border-radius: 4px; opacity: .85; }
.th-bar.short { width: 50%; opacity: .6; }
.th-card-name { font-family: var(--font-heading); font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.th-card-desc { font-size: 13px; color: var(--muted); }

/* --- Settings > Backup & restore ------------------------------------------------- */
.bk-parts { margin: 0 0 14px; padding-left: 18px; font-size: 13.5px; line-height: 1.7; }
.bk-choose { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; margin-bottom: 12px; }
.bk-opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.bk-opt input { margin-top: 3px; }
.bk-opt small { display: block; color: var(--muted); font-size: 12.5px; }
.bk-notes { margin: 0; padding-left: 18px; font-size: 13.5px; }

/* --- Permissions grid ------------------------------------------------------ */
.perm-card { padding-bottom: 6px; }
.perm-table { width: 100%; border-collapse: collapse; }
.perm-table th, .perm-table td { padding: 8px 6px; text-align: left; border-top: 1px solid var(--line); vertical-align: middle; }
.perm-table thead th { border-top: 0; font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.perm-table tbody th { font-weight: 600; font-size: 14px; }
.perm-table td { width: 30%; }
.perm-table .perm-sel { width: 100%; min-width: 0; }
.perm-table .pill { margin-left: 6px; }
.perm-one .perm-mod th { padding-top: 14px; border-top: 0; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.perm-one td { width: 48%; }
@media (max-width: 560px) {
  .perm-table thead { display: none; }
  .perm-table:not(.perm-one) tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
  .perm-table:not(.perm-one) th, .perm-table:not(.perm-one) td { border: 0; padding: 0; width: auto; }
  .perm-table:not(.perm-one) tbody th { grid-column: 1 / -1; }
  .perm-table:not(.perm-one) td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
  .perm-table:not(.perm-one) td[colspan] { grid-column: 1 / -1; }
}
.perm-extra { display: inline-block; padding-left: 18px; font-weight: 500; color: var(--ink2); position: relative; }
.perm-extra::before { content: ''; position: absolute; left: 4px; top: 2px; width: 8px; height: 8px; border-left: 1.5px solid var(--line2); border-bottom: 1.5px solid var(--line2); }

/* Login image preview: drawn like the sign-in screen draws it. */
.si-preview { position: relative; }
.si-splat { position: absolute; inset: 8%; background: var(--splat); -webkit-mask: var(--splat-img) center / contain no-repeat; mask: var(--splat-img) center / contain no-repeat; }
.si-note { position: absolute; right: 6px; bottom: 4px; font-size: 11px; color: var(--muted); }

/* --- Settings > Appearance --------------------------------------------------- */
.field-label { display: block; margin-bottom: 6px; font-size: 12.5px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink2); }
.ap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.ap-mode { margin-top: 16px; }
.th-card { cursor: default; }
.th-pick { display: flex; flex-direction: column; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.th-acts { display: flex; flex-wrap: wrap; gap: 2px; margin: 2px -6px -4px; }
.th-acts .btn { min-height: 34px; padding: 0 8px; font-size: 12.5px; }
.th-new { align-items: center; justify-content: center; text-align: center; min-height: 190px; border-style: dashed; color: var(--ink2); background: none; cursor: pointer; font: inherit; }
.th-new svg { width: 26px; height: 26px; }
.th-new:hover { border-color: var(--ink); color: var(--ink); }

.ap-mods { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.ap-mod { display: grid; grid-template-columns: auto minmax(0, 1fr) 76px auto; gap: 10px; align-items: center; }
.ap-swatch {
  width: 40px; height: 40px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 3px solid var(--panel); background: var(--sw); box-shadow: 0 0 0 1px var(--line2);
}
button.ap-swatch:hover { box-shadow: 0 0 0 2px var(--ink); }
.ap-mod-name { font-family: var(--font-heading); font-size: 16px; font-weight: 600; }
.ap-mod-ini { text-align: center; text-transform: uppercase; font-family: var(--font-heading); font-weight: 700; }
.ap-mod-count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.ap-selects { border-top: 1px solid var(--line); padding-top: 14px; }
@media (max-width: 520px) { .ap-mod { grid-template-columns: auto minmax(0, 1fr) 64px; } .ap-mod-count { display: none; } }

.ap-sample { margin-top: 16px; padding: 16px 18px; border: 1px dashed var(--line2); border-radius: var(--radius-sm); background: var(--bg); }
.ap-sample h3 { font-size: 20px; margin-bottom: 6px; }
.ap-sample p { margin: 0 0 6px; color: var(--ink2); }
.ap-sample p.mono { color: var(--ink); font-size: 14px; margin: 0; }

/* Fonts > Your fonts: uploaded families, each weight with Remove; Add font below. */
.uf { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.uf-title { font-size: 15px; margin-bottom: 4px; }
.uf .hint { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.uf-list, .uf-files { list-style: none; margin: 0; padding: 0; }
.uf-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 4px; }
.uf-family { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); }
.uf-name { font-size: 17px; margin-bottom: 4px; overflow-wrap: anywhere; }
.uf-file { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; min-height: 36px; font-size: 13.5px; color: var(--ink2); }
.uf-fmt { font-size: 11.5px; color: var(--muted); margin-left: 4px; }
.uf .uf-none { margin: 8px 0; }
.uf-add { margin-top: 14px; padding: 12px; border: 1px dashed var(--line2); border-radius: var(--radius-sm); background: var(--bg); }
.uf-add-title { font-weight: 600; margin-bottom: 8px; }
.uf-file-pick { margin-bottom: 14px; }
.uf-pick { cursor: pointer; }

.ap-slots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ap-slot { display: flex; align-items: center; gap: 10px; min-height: var(--touch); padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px; text-align: left; cursor: pointer; }
.ap-slot .ap-swatch { width: 28px; height: 28px; flex: none; }
.ap-slot.on { border-color: var(--ink); font-weight: 600; }
.ap-custom { display: flex; gap: 8px; align-items: center; }
.ap-custom input[type=color] { width: 48px; height: var(--touch); padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); }
.ap-custom .input { width: 120px; }

/* Theme editor */
.modal.modal-wide { max-width: 760px; }
.te-form .check { margin-top: 0; }
.te-table-wrap { max-height: 46dvh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.te-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.te-table th, .te-table td { padding: 6px 10px; text-align: left; border-top: 1px solid var(--line); }
.te-table thead th { position: sticky; top: 0; background: var(--panel); border-top: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; z-index: 1; }
.te-table tbody th { font-weight: 500; color: var(--ink2); }
.te-group th { background: var(--panel2); font-weight: 700 !important; color: var(--ink) !important; font-size: 12.5px; }
.te-colour { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.te-colour input[type=color] { width: 36px; height: 28px; padding: 0; border: 1px solid var(--line2); border-radius: 6px; background: none; cursor: pointer; }
.te-colour .mono { font-size: 12px; color: var(--muted); }
