/* Primitives shared by every surface, including the Pipedrive panel (which
   does not load ui.css/ui_components.css): buttons, fields, notices, segments and the
   single modal. No element or body rules here, so the panel keeps its own
   base. Order: tokens.css, ui_primitives.css, then the page stylesheets.
   docs/frontend_guidelines.md §6. */

/* Buttons */
.button {
  min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px; border: 1px solid transparent; border-radius: 10px;
  font-family: var(--font-sans); font-size: 14px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; text-decoration: none; cursor: pointer; transition: .18s ease;
}
.button:hover { text-decoration: none; }
.button:active:not(:disabled):not([aria-disabled="true"]),
.icon-button:active:not(:disabled):not([aria-disabled="true"]) { filter: brightness(.94); transition-duration: 0s; }
.button svg { width: 17px; height: 17px; }
.button-primary { background: var(--accent); color: var(--ink-inverse); }
.button-primary:hover { background: var(--accent-strong); color: var(--ink-inverse); }
.button-secondary { border-color: var(--line-strong); background: var(--surface); color: var(--muted-strong); }
.button-secondary:hover { border-color: var(--line-strong); background: var(--surface-soft); color: var(--ink); }
.button-quiet { background: transparent; color: var(--accent); }
.button-quiet:hover { background: var(--accent-soft); color: var(--accent-strong); }
.button-danger { border-color: var(--danger-line); background: var(--surface); color: var(--danger); }
.button-danger:hover { background: var(--danger-soft); color: var(--danger); }
.button-small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.button-small svg { width: 15px; height: 15px; }
.button:disabled, .button[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.icon-button {
  width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--muted-strong); cursor: pointer;
}
.icon-button:hover { border-color: var(--line-strong); background: var(--surface-soft); }
.icon-button svg { width: 17px; height: 17px; }
.button:focus-visible, .icon-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Fields */
.field { display: grid; align-content: start; gap: 8px; }
.field > * { min-width: 0; }
.field > .button { justify-self: start; }
.field label, fieldset.field legend { color: var(--muted-strong); font-size: 13px; font-weight: 600; }
fieldset.field { margin: 0; padding: 0; border: 0; }
fieldset.field legend { margin-bottom: 8px; padding: 0; }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; outline: none;
  background: var(--surface-subtle); color: var(--ink); font-size: 14px; transition: .18s ease;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--bridge); background: var(--surface); box-shadow: 0 0 0 3px var(--bridge-soft); }
.input[readonly], .select:disabled, .input:disabled { background: var(--neutral-soft); color: var(--muted-strong); cursor: not-allowed; }
.field-help { margin: 1px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
/* Customizable select (Chromium): the open list follows the interface instead of
   the operating system's square menu. Other browsers keep the native list. */
@supports (appearance: base-select) {
  .select, .select::picker(select) { appearance: base-select; }
  .select { display: flex; align-items: center; gap: 8px; padding-right: 10px; cursor: pointer; }
  .select::picker-icon {
    content: ""; flex: none; width: 16px; height: 16px; margin-left: auto;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234b5952' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / 16px no-repeat;
    transition: rotate .15s ease;
  }
  .select:open::picker-icon { rotate: 180deg; }
  .select::picker(select) {
    margin-top: 4px; padding: 4px; max-height: min(320px, 60vh); overflow-y: auto;
    border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-lg);
  }
  .select option {
    display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 10px;
    border-radius: 6px; color: var(--ink); font-size: 14px; cursor: pointer;
  }
  .select option:hover, .select option:focus-visible { background: var(--surface-soft); outline: none; }
  .select option:checked { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
  .select option::checkmark { order: 1; margin-left: auto; content: "✓"; }
  .select option:disabled { color: var(--muted); cursor: not-allowed; }
  .select optgroup { padding: 4px 0; color: var(--muted-strong); font-size: 12px; font-weight: 600; }
}
@media (prefers-reduced-motion: reduce) { .select::picker-icon { transition: none; } }
.field-error { color: var(--danger); font-weight: 600; }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.search { position: relative; }
.search svg { position: absolute; top: 50%; left: 13px; width: 17px; height: 17px; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.search .input { padding-left: 40px; }

/* Notices (flash messages, billing) */
.notice {
  display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; padding: 12px 16px;
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; background: var(--surface);
  color: var(--ink); font-size: 14px; line-height: 1.45;
}
.notice > span { flex: 1; }
/* Several paragraphs, or text plus actions: .notice-body holds the text. */
.notice-body { flex: 1 1 280px; }
.notice-body p { margin: 0; }
.notice-body p + p { margin-top: 6px; }
.notice:has(> .notice-actions) { flex-wrap: wrap; align-items: center; }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.notice svg { width: 18px; height: 18px; margin-top: 1px; }
.notice a { color: var(--accent-strong); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.notice-success { border-color: var(--ok-line); border-left-color: var(--ok); }
.notice-success svg { color: var(--ok); }
.notice-danger { border-color: var(--danger-line); border-left-color: var(--danger); background: var(--danger-soft); }
.notice-danger svg { color: var(--danger); }
.notice-warning { border-color: var(--amber-line); border-left-color: var(--amber); background: var(--amber-soft); }
.notice-warning svg { color: var(--amber); }
.notice-info { border-left-color: var(--blue); }
.notice-info svg { color: var(--blue); }

/* `hidden` always wins, also where the page base (ui_components.css) is not
   loaded, such as the Pipedrive panel. */
.notice[hidden], .ui-dialog [hidden] { display: none !important; }
/* Same sizing model everywhere (the panel has no global box-sizing rule). */
.button, .icon-button, .input, .select, .textarea, .notice,
.ui-dialog, .ui-dialog *, .ui-dialog *::before, .ui-dialog *::after { box-sizing: border-box; }

/* Segments: a few options side by side; filters (aria-pressed), periods and
   sub-views as links (aria-current), sub-tabs below the page tabs and dialog
   tabs (role="tab", ui_tabs.js) and form choices over radios. */
.segments { display: flex; flex-wrap: wrap; gap: 3px; width: fit-content; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--neutral-soft); }
.segment {
  min-height: 32px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted-strong);
  font-family: inherit; font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.segment span { color: var(--muted); font-variant-numeric: tabular-nums; }
.segment:hover { color: var(--ink); }
.segment[aria-pressed="true"], .segment[aria-current="page"], .segment[aria-selected="true"], .segment:has(input:checked) {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
}
/* A segment over a radio (form choice): <label class="segment"><input type="radio">...</label>. */
label.segment { position: relative; }
.segment input[type="radio"] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.segment:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.segment:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Modal: <dialog class="ui-dialog"> opened with showModal(). */
.ui-dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: hidden; }
.ui-dialog.wide { width: min(1080px, calc(100vw - 32px)); }
.ui-dialog::backdrop { background: var(--backdrop); }
.ui-dialog[open] { display: flex; flex-direction: column; }
/* The form fills the dialog, so only the body scrolls. */
.dialog-form { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; max-height: inherit; margin: 0; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 20px; }
.dialog-body > .notice { margin-bottom: 16px; }
.dialog-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-soft); }
.dialog-foot .field-help { margin-right: auto; }
.ui-confirm-dialog { width: min(480px, calc(100vw - 32px)); }
.ui-confirm-dialog .dialog-body p { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
/* Short lists and small forms never take the whole screen; the body scrolls. */
.ui-dialog.small { width: min(480px, calc(100vw - 32px)); max-height: min(640px, calc(100dvh - 32px)); }
.dialog-head { align-items: center; }
.dialog-head .panel-title, .dialog-title { margin: 0; color: var(--ink); font-size: 16px; font-weight: 600; line-height: 1.3; letter-spacing: -0.1px; }
.dialog-subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.dialog-head-actions { display: flex; flex: none; gap: 8px; }
.dialog-head-actions .icon-button { width: 34px; height: 34px; }
.dialog-search { padding: 12px 20px; border-bottom: 1px solid var(--line-soft); }
.dialog-list { display: grid; gap: 2px; margin: -8px -12px; }
.dialog-option { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 6px 12px; border-radius: var(--radius-md); color: var(--ink); cursor: pointer; }
.dialog-option:hover { background: var(--surface-soft); }
.dialog-option:has(input:checked), .dialog-option[aria-selected="true"] { background: var(--bridge-soft); }
.dialog-option input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--bridge); }
.dialog-option .option-main { flex: 1; min-width: 0; }
/* Inside a .field (fieldset of choices) the option keeps body text, not the field-label style. */
.field label.dialog-option { color: var(--ink); font-size: 14px; font-weight: 400; }
/* A toggle row as <button aria-pressed>: drawn check box, same look as a checkbox row. */
button.dialog-option { width: 100%; border: 0; background: transparent; font: inherit; font-size: 14px; text-align: left; }
button.dialog-option:disabled { cursor: progress; opacity: .6; }
.dialog-option[aria-pressed="true"] { background: var(--bridge-soft); }
.dialog-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.option-check { display: inline-grid; place-items: center; width: 18px; height: 18px; flex: none; border: 1.5px solid var(--line-strong); border-radius: 4px; background: var(--surface); }
.dialog-option[aria-pressed="true"] .option-check { border-color: var(--bridge); background: var(--bridge); }
.dialog-option[aria-pressed="true"] .option-check::after { content: ""; width: 9px; height: 5px; margin-top: -2px; border: solid var(--ink-inverse); border-width: 0 0 2px 2px; transform: rotate(-45deg); }
.dialog-option .option-meta { flex: none; color: var(--muted); font-size: 12px; }
.dialog-stack { display: grid; gap: 16px; }
.dialog-check { display: flex; align-items: flex-start; gap: 10px; color: var(--muted-strong); font-size: 13px; }
.dialog-check input { width: 18px; height: 18px; margin: 0; accent-color: var(--bridge); }
/* Narrow screens and the Pipedrive panel: the same dialog as a bottom sheet. */
@media (max-width: 600px) {
  .ui-dialog, .ui-dialog.small, .ui-dialog.wide, .ui-confirm-dialog {
    width: 100vw; max-width: 100vw; max-height: 88dvh; margin: auto 0 0;
    border-bottom: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
}

/* Shared translated file selector, enhanced by ui_lists.js. */
.file-picker { position: relative; display: flex; align-items: center; gap: 12px; min-width: 0; min-height: 48px; padding: 4px 14px 4px 4px; border: 1px dashed var(--line-strong); border-radius: 10px; background: var(--surface-soft); cursor: pointer; }
.file-picker:hover { border-color: var(--bridge); background: var(--bridge-soft); }
.file-picker:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-picker:has(input[aria-invalid="true"]) { border-color: var(--danger); }
.file-picker-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-picker-button { display: inline-flex; flex: none; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; }
.file-picker-button svg { width: 16px; height: 16px; }
.file-picker-name { min-width: 0; overflow: hidden; color: var(--muted-strong); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.file-picker.has-file .file-picker-name { color: var(--ink); font-weight: 600; }
