/* Building blocks shared by every page (taken from Arideo): user block, tooltips, "?" and "i" buttons, collapsible
   sidebar with groups, secret inputs, choice and confirmation dialogs, tab picker, settings tiles, notices,
   pull-to-refresh. Uses the variables from base.css/theme.css only. */

/* Placeholder for parts that are not built yet */
.placeholder-notice { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 10px; border: 1px dashed var(--accent); background: var(--accent-soft); font-size: 14px; }
.placeholder-notice strong { color: var(--accent); text-transform: uppercase; letter-spacing: .06em; font-size: 12px; }
.placeholder-phase { margin-left: auto; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 9px; background: var(--accent); color: var(--on-accent); white-space: nowrap; }
dialog .placeholder-notice { margin-bottom: 4px; }

/* User block at the bottom of the sidebar */
.user { display: grid; gap: 6px; padding: 12px; margin-top: 8px; border-top: 1px solid var(--line); font-size: 14px; }
.user-name { color: var(--muted); }
.user-name strong { color: var(--text); display: block; }
.user-links { display: flex; gap: 8px; flex-wrap: wrap; }
.user-links a, .user-links button { font: inherit; font-size: 13px; color: var(--accent); background: none; border: 0; padding: 4px 0; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.user-links a:hover, .user-links button:hover { text-decoration: underline; }
.user-links a[aria-current] { font-weight: 600; }

/* Tooltips: data-tip="…" on the element. On desktop on hover/keyboard focus, on phones via a "?" button (.help).
   With a mouse, workspace.js replaces the CSS tooltip by one layer in the foreground (.tip-layer). */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; z-index: 60; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
  width: max-content; max-width: 260px; padding: 8px 10px; border-radius: 8px;
  background: #1E2125; color: #fff; border: 1px solid #555B63; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  font: 400 13px/1.35 var(--body-font); text-align: left; white-space: normal; text-transform: none; letter-spacing: 0;
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .12s ease .4s, visibility 0s linear .52s;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; transition-delay: .4s, 0s; }
.sidebar [data-tip]::after { left: calc(100% + 12px); bottom: auto; top: 50%; transform: translateY(-50%); }
.user [data-tip]::after { left: 0; transform: none; }
@media (hover: none) { [data-tip]:not(.help)::after { display: none; } }
.help { display: inline-grid; place-items: center; width: 24px; height: 24px; min-width: 24px; padding: 0; border-radius: 50%; border: 1px solid var(--border); background: transparent; color: var(--muted); font: 700 13px/1 var(--body-font); cursor: help; vertical-align: middle; }
.help:focus::after { opacity: 1; visibility: visible; transition-delay: 0s; }
.help::after { left: auto; right: -8px; transform: none; }
.help.help-text { display: inline; width: auto; height: auto; min-width: 0; border: 0; border-radius: 0; color: var(--accent); font: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.help.help-text::after { left: 0; right: auto; white-space: pre-line; }
html.js-tips [data-tip]::after { display: none; }
.tip-layer { position: fixed; inset: auto; margin: 0; z-index: 2147483647; max-width: 280px; width: max-content; padding: 8px 10px; border-radius: 8px;
  background: #1E2125; color: #fff; border: 1px solid #555B63; box-shadow: 0 8px 24px rgba(0,0,0,.45); font: 400 13px/1.35 var(--body-font);
  text-align: left; white-space: pre-line; pointer-events: none; overflow: visible; }
.tip-layer[hidden] { display: none; }

/* Page head: title with "i" button left, actions right */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.back-link { color: var(--accent); text-decoration: none; }

/* Navigation items are links (they lead to /#view on other pages) */
a.nav, a.capture, a.command-button, .sidebar a.brand, .topbar a.brand { color: inherit; text-decoration: none; }
.bottom-nav a { text-decoration: none; }
a.capture { display: flex; align-items: center; justify-content: center; gap: 6px; }
.nav { position: relative; }
.app-main { min-width: 0; }
.collapse-toggle { margin-top: 4px; color: var(--muted); font-size: 13px; min-height: 40px; }
.collapse-toggle svg { transition: transform .2s ease; }

/* Sidebar collapsed to an icon rail (like WordPress): toggled manually, remembered per browser, always visible */
@media (min-width: 1024px) {
  .sidebar-collapsed .app { grid-template-columns: 68px 1fr; }
  .sidebar-collapsed .sidebar { padding-left: 10px; padding-right: 10px; }
  .sidebar-collapsed .sidebar .label, .sidebar-collapsed .sidebar kbd, .sidebar-collapsed .user-name { display: none; }
  .sidebar-collapsed .sidebar .brand { margin-left: -10px; margin-right: -10px; padding: 0; justify-content: center; }
  .sidebar-collapsed .sidebar :is(.nav, .command-button, .capture) { justify-content: center; padding: 0; gap: 0; }
  .sidebar-collapsed .nav :is(.dot, .counter) { position: absolute; top: 4px; right: 4px; }
  .sidebar-collapsed .user { padding: 8px 0; justify-items: center; }
  .sidebar-collapsed .user-links { flex-direction: column; align-items: center; gap: 4px; }
  .sidebar-collapsed .user-links :is(a, button) { min-width: 44px; min-height: 36px; justify-content: center; }
  .sidebar-collapsed .collapse-toggle svg { transform: rotate(180deg); }
  .sidebar-collapsed .sidebar [data-tip]::after { left: calc(100% + 14px); }
}
.command-button .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.command-button kbd { white-space: nowrap; }
.command-button svg { flex-shrink: 0; }

/* Sidebar groups: sub items show while one of them is current; collapsed rail: flyout on hover */
.nav-parent > svg:last-child { margin-left: auto; transition: transform .15s; color: var(--muted); }
.nav-sub { display: none; flex-direction: column; gap: 2px; margin: 2px 0 4px; }
.nav-sub .nav { padding-left: 24px; min-height: 40px; }
html:not(.sidebar-collapsed) .nav-group:not(.closed):has(.nav-sub [aria-current]) .nav-sub { display: flex; }
.nav-group:has(.nav-sub [aria-current]) .nav-parent { color: var(--accent); }
.nav-group:has(.nav-sub [aria-current]) .nav-parent > svg:first-child { color: var(--accent); }
.nav-group:not(.closed):has(.nav-sub [aria-current]) .nav-parent > svg:last-child { transform: rotate(90deg); }
@media (min-width: 1024px) {
  .sidebar-collapsed .nav-parent > svg:last-child { display: none; }
  .sidebar-collapsed .nav-group { position: relative; }
  .sidebar-collapsed .sidebar .nav-group .nav-sub { display: none; }
  .sidebar-collapsed .nav-group:is(:hover, :focus-within) .nav-sub { display: flex; position: absolute; left: 100%; top: 0; z-index: 20; min-width: 220px; padding: 6px; margin: 0; background: var(--sidebar); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
  .sidebar-collapsed .nav-group .nav-sub .label { display: inline; }
  .sidebar-collapsed .nav-group .nav-sub .nav { justify-content: flex-start; padding: 0 12px; gap: 12px; }
  .sidebar-collapsed .nav-group .nav-sub [data-tip]::after { display: none; }
}
/* Phone "More" dialog: a group as a heading with its items indented, like the sidebar */
.more-group { display: flex; align-items: center; gap: 12px; margin: 8px 0 0; padding: 0 12px; min-height: 36px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.more .more-sub { padding-left: 28px; }
.more .nav[aria-current] { color: var(--accent); }

/* Links styled as buttons; quiet buttons and text links */
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn.danger { background: #c9534a; border-color: #c9534a; color: #fff; }
.btn.danger:hover { background: #b3453d; }
.btn.small.primary { min-height: 32px; }
.link-button { border: 0; background: none; padding: 4px 0; color: var(--accent); font: inherit; font-size: 13px; cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.add-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.add-chips .chip { background: transparent; border-style: dashed; min-height: 36px; }
.tabs a[role="tab"] { display: inline-flex; align-items: center; min-height: 44px; border-bottom: 2px solid transparent; color: var(--muted); text-decoration: none; }
.tabs a[role="tab"][aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Inputs for third-party secrets: masked text field (not type=password, so password managers stay away) */
.secret-input { display: flex; gap: 6px; align-items: stretch; }
.secret-input .secret { flex: 1; min-width: 0; -webkit-text-security: disc; text-security: disc; font-family: ui-monospace, monospace; }
.secret-input .secret.revealed { -webkit-text-security: none; text-security: none; }
.secret-toggle { min-width: 44px; border: 1px solid var(--border); border-radius: var(--r); background: var(--ground); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.secret-toggle[aria-pressed="true"] { color: var(--accent); }

/* Close button in the top right corner of a dialog */
.commands { position: relative; }
.dialog-close { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; z-index: 1; }
.dialog-close:hover { background: rgba(255,255,255,.06); color: inherit; }
.commands .command-input { padding-right: 52px; }
.command-empty { padding: 12px; color: var(--muted); font-size: 14px; }

/* Choice dialog (public/js/choice.js): large tiles for decisions */
.choice-dialog { width: min(760px, calc(100vw - 24px)); }
.choice-dialog .wizard-head .muted { white-space: pre-line; }
.choice-tiles { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.choice-tile { min-height: 64px; min-width: 0; }
.choice-tile.suggested { border-color: var(--accent); }
.choice-label { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.choice-label small { font-size: 12px; font-weight: 400; color: var(--muted); }
.choice-more { display: grid; gap: 10px; }
.choice-more summary { list-style: none; justify-self: start; display: inline-flex; align-items: center; }
.choice-more summary::-webkit-details-marker { display: none; }
.choice-more[open] { display: grid; }
.choice-search { min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--ground); color: var(--text); width: 100%; font: inherit; }
.choice-more > .choice-search { display: block; margin: 12px 0 10px; }
.choice-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.choice-search-hint { margin: 0 0 6px; }
.choice-more-list { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); max-height: 40vh; overflow-y: auto; overflow-x: hidden; margin-top: 4px; padding: 4px; }
.choice-more-list .tile { min-height: 48px; padding: 8px 12px; }
.choice-custom { display: grid; gap: 8px; }
.choice-custom-row { display: flex; gap: 8px; }
.choice-custom-row input { flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--ground); color: var(--text); font: inherit; }
.choice-foot-left, .choice-foot-right { display: flex; gap: 8px; align-items: center; }
.choice-link { margin: 12px 0 4px; }
.choice-link .btn { display: inline-flex; align-items: center; text-decoration: none; }
.choice-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; margin: 12px 0; }
.choice-fields .field { display: grid; gap: 4px; min-width: 0; }
.choice-fields .field.wide { grid-column: 1 / -1; }
.choice-fields .field > span { font-size: 13px; color: var(--muted); }
.choice-fields input, .choice-fields select, .choice-fields textarea { width: 100%; min-height: 44px; box-sizing: border-box; }
.choice-fields .field-hint { font-size: 12px; color: var(--muted); }
.choice-segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.choice-segmented label { position: relative; }
.choice-segmented input { position: absolute; opacity: 0; pointer-events: none; }
.choice-segmented span { display: inline-block; min-height: 44px; line-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choice-segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.choice-segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (max-width: 600px) { .choice-fields { grid-template-columns: 1fr; } }
/* Tiles inside a form field: the general field rule (min-height 44px, padding) must not stretch the round markers */
.field .tile input:is([type="radio"], [type="checkbox"]) { min-height: 0; padding: 0; border-radius: 50%; }
.tile input[type="radio"] { border-radius: 50%; }

/* Confirmation with two buttons (Choice.confirm) */
.confirm-dialog { width: min(420px, calc(100vw - 32px)); }
.confirm-dialog h2 { font-size: 20px; margin-bottom: 8px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.confirm-actions .btn { min-width: 120px; }

/* "i" buttons and the info window */
.info-btn { position: relative; display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; margin-left: 10px; padding: 0; border-radius: 50%; border: 1.5px solid var(--accent); background: transparent; color: var(--accent); font: italic 700 15px/1 var(--heading-font); cursor: pointer; vertical-align: middle; transition: background .15s, color .15s; }
.info-btn::before { content: ''; position: absolute; inset: -9px; }
.info-btn:hover, .info-btn:focus-visible { background: var(--accent); color: var(--on-accent); outline: none; }
.info-dialog { width: min(460px, calc(100vw - 32px)); padding: 24px 24px 20px; }
.info-dialog::backdrop { background: rgba(0,0,0,.45); }
.info-head { display: flex; align-items: center; gap: 12px; padding-right: 36px; }
.info-badge { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font: italic 700 18px/1 var(--heading-font); }
.info-head h2 { font-size: 20px; }
.info-text { margin: 14px 0 18px; line-height: 1.55; }
.info-text p { margin: 0 0 10px; }
.info-ok { width: 100%; min-height: 44px; }
@media (max-width: 700px) {
  .info-dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 85dvh; overflow: auto; }
}

/* Settings start page: topics with tiles; sub page navigation as chips */
.settings-group { margin-top: 20px; }
.settings-group h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.settings-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.settings-tile { display: grid; gap: 4px; align-content: start; padding: 14px 16px; min-height: 88px; border: 1px solid var(--border); border-radius: var(--r, 10px); background: var(--list); color: inherit; text-decoration: none; }
a.settings-tile:hover, a.settings-tile:focus-visible { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.settings-tile strong { font-size: 16px; }
.settings-tile .muted { font-size: 14px; }
.settings-count { font-size: 13px; color: var(--accent-text, var(--accent)); }
.settings-tile[data-planned] { opacity: .75; outline: 0; border-style: dashed; cursor: default; }
.settings-subnav { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; }
.settings-subnav .chip { text-decoration: none; min-height: 36px; display: inline-flex; align-items: center; color: inherit; }
.settings-subnav .chip[aria-current="page"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text, var(--accent)); }

/* Picker instead of a tab row ([data-tabs-picker] right before [data-tabs], workspace.js) */
.tabs-picker { display: none; position: relative; }
.tabs-picker.active { display: flex; }
.tabs-picker.active + .tabs { display: none; }
.tabs-picker-button { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.tabs-picker-button .counter { margin-left: 0; }
.tabs-picker-arrow { color: var(--accent); }
.tabs-picker-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 50; display: grid; gap: 2px; min-width: 300px; max-height: 70vh; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: var(--r-large); background: var(--surface); box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.tabs-picker-menu[hidden] { display: none; }
.tabs-picker-group { margin: 8px 8px 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tabs-picker-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 0 10px; border: 0; border-radius: var(--r); background: none; color: var(--text); font: inherit; text-align: left; text-decoration: none; cursor: pointer; }
.tabs-picker-item:hover, .tabs-picker-item:focus-visible { background: var(--accent-soft); }
.tabs-picker-item[aria-current] { color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.tabs-picker-item .counter { margin-left: 0; }
.tabs-picker-done > summary { min-height: 44px; display: flex; align-items: center; padding: 0 10px; color: var(--muted); cursor: pointer; }
.tabs-picker-done .tabs-picker-item { color: var(--muted); }
.tabs-next { margin: 0; }
@media (max-width: 1023px) {
  .tabs-picker { display: flex; }
  .tabs-picker + .tabs { display: none; }
  .tabs-picker-menu { right: 0; min-width: 0; }
}

/* Buttons of the same size next to each other (e.g. "Check connection" and "Remove") */
.inline-forms { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
.inline-forms form, .inline-forms .btn { width: 100%; }
@media (max-width: 560px) { .inline-forms { grid-auto-flow: row; } }

/* Pull down to reload (home-screen app): the arrow that follows the finger */
.pull-refresh { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); left: 50%; z-index: 1000; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: var(--surface, #4A4F57); border: 2px solid var(--border); color: var(--text); font-size: 20px; opacity: 0; transform: translate(-50%, -50px); pointer-events: none; transition: opacity .15s; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.pull-refresh.ready { border-color: var(--accent); color: var(--accent); }
.pull-refresh.loading { opacity: 1; transform: translate(-50%, 40px); animation: pull-refresh-spin .8s linear infinite; }
@keyframes pull-refresh-spin { from { rotate: 0deg; } to { rotate: 360deg; } }
