/* ==========================================================================
   hg-components.css — the shared component layer.

   Load order: design-tokens.css → THIS FILE → feature stylesheets →
   hg-unify.css. Element defaults here use :where() (zero specificity), so a
   feature class always wins over them; they only fill the gaps where a
   control had no styling of its own.

   New UI uses the .hg-* classes below instead of a new button/card/input
   family. See design/DESIGN_LANGUAGE.md.
   ========================================================================== */

/* ---- Element defaults ---------------------------------------------------- */
:where(html) {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

:where(body) {
    font-family: var(--hg-font);
    font-size: var(--hg-fs-md);
    line-height: var(--hg-lh-snug);
    color: var(--hg-text);
    accent-color: var(--hg-accent);
}

:where(h1, h2, h3, h4) {
    font-family: var(--hg-font-display);
    letter-spacing: var(--hg-tracking-title);
    line-height: var(--hg-lh-tight);
    color: var(--hg-text);
}

:where(button, input, select, textarea) {
    font-family: inherit;
}

:where(a) {
    color: var(--hg-link);
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]), select, textarea) {
    color: var(--hg-text);
    border-color: var(--hg-border);
    transition: border-color var(--hg-dur-fast) var(--hg-ease), box-shadow var(--hg-dur-fast) var(--hg-ease);
}

:where(input, select, textarea)::placeholder {
    color: var(--hg-text-tertiary);
}

:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea):focus-visible {
    outline: none;
    border-color: var(--hg-accent);
    box-shadow: var(--hg-focus-ring);
}

:where(button, [role="button"], a, summary):focus-visible {
    outline: 2px solid var(--hg-accent);
    outline-offset: 2px;
}

::selection {
    background: var(--hg-selection);
}

/* Thin, quiet scrollbars (macOS-style overlay look on desktop browsers). */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--hg-radius-pill);
    border: 3px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.32);
}

/* ---- Button ---------------------------------------------------------------
   One recipe, four roles: primary (the one main action of a view),
   secondary (gray fill), plain (text only), destructive. */
.hg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--hg-space-2);
    min-height: var(--hg-control-md);
    padding: 0 var(--hg-space-4);
    border: none;
    border-radius: var(--hg-radius-sm);
    background: var(--hg-fill);
    color: var(--hg-text);
    font: var(--hg-fw-medium) var(--hg-fs-md) / 1 var(--hg-font);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background-color var(--hg-dur-fast) var(--hg-ease),
                color var(--hg-dur-fast) var(--hg-ease),
                transform var(--hg-dur-press) var(--hg-ease-out);
}

.hg-btn:hover { background: var(--hg-fill-strong); }
.hg-btn:active:not(:disabled) { transform: scale(0.97); }
.hg-btn:disabled { opacity: 0.4; cursor: default; }

.hg-btn--primary { background: var(--hg-accent); color: var(--hg-on-accent); font-weight: var(--hg-fw-semibold); }
.hg-btn--primary:hover { background: var(--hg-accent-hover); }
.hg-btn--primary:active:not(:disabled) { background: var(--hg-accent-pressed); }

.hg-btn--plain { background: transparent; color: var(--hg-accent); }
.hg-btn--plain:hover { background: var(--hg-accent-tint-subtle); }

.hg-btn--danger { background: var(--hg-danger-tint); color: var(--hg-danger); }
.hg-btn--danger:hover { background: var(--hg-danger-border); }

.hg-btn--sm { min-height: var(--hg-control-sm); padding: 0 var(--hg-space-3); font-size: var(--hg-fs-sm); }
.hg-btn--lg { min-height: var(--hg-control-lg); padding: 0 var(--hg-space-6); font-size: var(--hg-fs-base); border-radius: var(--hg-radius-md); }

/* Round icon button (close, more, back). */
.hg-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: var(--hg-radius-pill);
    background: transparent;
    color: var(--hg-text-secondary);
    cursor: pointer;
    transition: background-color var(--hg-dur-fast) var(--hg-ease), transform var(--hg-dur-press) var(--hg-ease-out);
}

.hg-icon-btn:hover { background: var(--hg-fill); color: var(--hg-text); }
.hg-icon-btn:active { transform: scale(0.94); }

/* ---- Input ----------------------------------------------------------------- */
.hg-input {
    min-height: var(--hg-control-md);
    padding: 0 var(--hg-space-3);
    border: 1px solid var(--hg-border);
    border-radius: var(--hg-radius-sm);
    background: var(--hg-surface);
    color: var(--hg-text);
    font: var(--hg-fs-md) / var(--hg-lh-snug) var(--hg-font);
}

/* ---- Card / grouped surface ---------------------------------------------- */
.hg-card {
    background: var(--hg-surface);
    border-radius: var(--hg-radius-lg);
    box-shadow: var(--hg-shadow-2);
    padding: var(--hg-space-5);
}

.hg-card__title {
    margin: 0 0 var(--hg-space-1);
    font: var(--hg-fw-semibold) var(--hg-fs-lg) / var(--hg-lh-tight) var(--hg-font-display);
    letter-spacing: var(--hg-tracking-title);
}

.hg-card__subtitle {
    margin: 0 0 var(--hg-space-4);
    color: var(--hg-text-secondary);
    font-size: var(--hg-fs-sm);
}

/* ---- Segmented control ---------------------------------------------------- */
.hg-segmented {
    display: inline-flex;
    padding: 2px;
    gap: 2px;
    border-radius: var(--hg-radius-sm);
    background: var(--hg-fill);
}

.hg-segmented > button {
    min-height: calc(var(--hg-control-md) - 4px);
    padding: 0 var(--hg-space-3);
    border: none;
    border-radius: calc(var(--hg-radius-sm) - 2px);
    background: transparent;
    color: var(--hg-text);
    font: var(--hg-fw-medium) var(--hg-fs-sm) / 1 var(--hg-font);
    cursor: pointer;
}

.hg-segmented > button[aria-pressed="true"],
.hg-segmented > button.is-active {
    background: var(--hg-surface);
    box-shadow: var(--hg-shadow-1);
}

/* ---- Badge ------------------------------------------------------------------ */
.hg-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--hg-radius-pill);
    background: var(--hg-fill);
    color: var(--hg-text-secondary);
    font: var(--hg-fw-medium) var(--hg-fs-2xs) / 1.4 var(--hg-font);
    letter-spacing: var(--hg-tracking-caption);
}

.hg-badge--accent { background: var(--hg-accent-tint); color: var(--hg-accent-pressed); }
.hg-badge--success { background: var(--hg-success-tint); color: var(--hg-success); }
.hg-badge--warning { background: var(--hg-warning-tint); color: var(--hg-warning); }
.hg-badge--danger { background: var(--hg-danger-tint); color: var(--hg-danger); }

/* ---- Tool start panel -----------------------------------------------------
   One layout for every tool that starts from a file or a short form: a
   centred column with the tool's glyph, its name, one line of what it does,
   the inputs, and the one main action. */
/* A tool's root; scripts show it with display: flex. */
.hg-tool {
    flex: 1;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
}

.hg-task {
    display: flex;
    flex-direction: column;
    gap: var(--hg-space-4);
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: var(--hg-space-10) var(--hg-space-5) var(--hg-space-6);
    box-sizing: border-box;
    direction: rtl;
}

.hg-task__head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--hg-space-2);
    margin-bottom: var(--hg-space-2);
    text-align: center;
}

.hg-task__icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-bottom: var(--hg-space-1);
    border-radius: var(--hg-radius-lg);
    background: var(--hg-accent-tint);
}

/* The feature bar's own glyphs, tinted the accent (.feature-icon in
   components.css uses the same filter). */
.hg-task__icon img {
    width: 30px;
    height: 30px;
    filter: brightness(0) saturate(100%) invert(27%) sepia(51%) saturate(2878%) hue-rotate(190deg) brightness(104%) contrast(97%);
}

.hg-task__title {
    margin: 0;
    font: var(--hg-fw-semibold) var(--hg-fs-xl) / var(--hg-lh-tight) var(--hg-font-display);
    letter-spacing: var(--hg-tracking-title);
    color: var(--hg-text);
}

.hg-task__subtitle {
    margin: 0;
    max-width: 44ch;
    color: var(--hg-text-secondary);
    font-size: var(--hg-fs-md);
    line-height: var(--hg-lh-snug);
}

/* The field and its button side by side; stacked on a phone. */
.hg-task__row {
    display: flex;
    gap: var(--hg-space-2);
    align-items: stretch;
}

.hg-task__row > .hg-input { flex: 1; min-width: 0; }

.hg-task__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--hg-space-3);
    justify-content: center;
}

.hg-task__actions > .hg-btn { min-width: 140px; }

@media (max-width: 600px) {
    .hg-task { padding: var(--hg-space-6) var(--hg-space-4); }
    .hg-task__row { flex-direction: column; }
    .hg-task__actions > .hg-btn { flex: 1; }
}

/* ---- Chip: a filter that can be on or off --------------------------------- */
.hg-chip {
    --chip: var(--hg-text-secondary);
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 12px;
    border: 1px solid color-mix(in srgb, var(--chip) 45%, transparent);
    border-radius: var(--hg-radius-pill);
    background: transparent;
    color: var(--chip);
    font-size: var(--hg-fs-sm);
    font-weight: var(--hg-fw-medium);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background-color var(--hg-dur-fast) var(--hg-ease), color var(--hg-dur-fast) var(--hg-ease);
}

.hg-chip:hover { background: color-mix(in srgb, var(--chip) 10%, transparent); }
.hg-chip:active { transform: scale(0.97); }
.hg-chip.is-active { border-color: var(--chip); background: var(--chip); color: var(--hg-on-accent); font-weight: var(--hg-fw-semibold); }
.hg-chip:focus-visible { outline: 2px solid var(--hg-accent); outline-offset: 2px; }

.hg-chip--folder { --chip: var(--hg-accent); }
.hg-chip--danger { --chip: var(--hg-danger); }
.hg-chip--warning { --chip: var(--hg-warning); }
.hg-chip--neutral { --chip: var(--hg-gray-600); }

/* ---- Field parts ------------------------------------------------------------ */
.hg-input--lg {
    min-height: var(--hg-control-lg);
    padding: 0 var(--hg-space-4);
    border-radius: var(--hg-radius-md);
    font-size: var(--hg-fs-base);
}

.hg-input--block { display: block; width: 100%; box-sizing: border-box; }

textarea.hg-input {
    padding: 10px var(--hg-space-3);
    line-height: var(--hg-lh-body);
    resize: vertical;
}

/* A link is typed left to right, but its Hebrew prompt reads right to left:
   with one direction for both, "הזן קישור לתיקיית Google Drive" came out in
   the wrong word order. The glyph sits at the start of the prompt. */
.hg-input--ltr {
    direction: ltr;
    text-align: left;
}

.hg-input--ltr:placeholder-shown {
    direction: rtl;
    text-align: right;
}

.hg-input--url:placeholder-shown {
    padding-right: 40px;
    background: var(--hg-surface) no-repeat right 14px center / 18px 18px
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'/%3E%3C/svg%3E");
}

.hg-form-field { margin-bottom: var(--hg-space-5); direction: rtl; text-align: right; }

.hg-label {
    display: block;
    margin-bottom: 6px;
    color: var(--hg-text);
    font-size: var(--hg-fs-md);
    font-weight: var(--hg-fw-medium);
}

.hg-required { color: var(--hg-danger); }

.hg-helper,
.hg-field-error {
    margin-top: var(--hg-space-1);
    font-size: var(--hg-fs-xs);
    line-height: var(--hg-lh-snug);
    direction: rtl;
    text-align: right;
}

.hg-helper { color: var(--hg-text-secondary); }
.hg-field-error { color: var(--hg-danger); }

/* A checkbox with its label and a quieter line under it. */
.hg-check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    direction: rtl;
    text-align: right;
}

.hg-check > input {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    cursor: pointer;
}

.hg-check__label { color: var(--hg-text); font-size: var(--hg-fs-md); font-weight: var(--hg-fw-medium); }
.hg-check__hint { margin-top: 2px; color: var(--hg-text-secondary); font-size: var(--hg-fs-xs); }

/* A field the script marked wrong. */
.hg-input.is-invalid,
.hg-input.is-invalid:focus-visible {
    border-color: var(--hg-danger);
    box-shadow: 0 0 0 3px var(--hg-danger-tint);
}

/* ---- Result table ------------------------------------------------------------
   A small editable table: quiet header, hairline rows, inline controls the
   height of a row. (A table people sort and filter is a DataTable instead,
   core/js/data_table.js.) */
.hg-grid-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border: 1px solid var(--hg-separator);
    border-radius: var(--hg-radius-md);
    direction: rtl;
    text-align: right;
    font-size: var(--hg-fs-md);
}

.hg-grid-table th {
    padding: 10px 12px;
    border-bottom: 1px solid var(--hg-separator);
    background: var(--hg-bg);
    color: var(--hg-text-secondary);
    font-size: var(--hg-fs-sm);
    font-weight: var(--hg-fw-semibold);
    text-align: right;
}

.hg-grid-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--hg-separator);
    vertical-align: middle;
}

.hg-grid-table tbody tr:last-child td { border-bottom: none; }
.hg-grid-table tbody tr:hover td { background: var(--hg-accent-tint-subtle); }
.hg-grid-table td a { color: var(--hg-link); text-decoration: none; }
.hg-grid-table td a:hover { text-decoration: underline; }

/* ---- Row menu (⋯) ------------------------------------------------------------ */
.hg-menu-anchor { position: relative; display: inline-block; }

.hg-menu-btn { width: 30px; height: 26px; border-radius: var(--hg-radius-xs); font-size: var(--hg-fs-lg); font-weight: var(--hg-fw-bold); line-height: 1; }

.hg-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    z-index: 1000;
    min-width: 180px;
    padding: var(--hg-space-1);
    overflow: hidden;
    border-radius: var(--hg-radius-md);
    background: var(--hg-surface-raised);
    box-shadow: var(--hg-shadow-3);
    transform: translateX(-50%);
    text-align: right;
}

.hg-menu__item {
    padding: 8px 12px;
    border-radius: var(--hg-radius-xs);
    color: var(--hg-text);
    font-size: var(--hg-fs-md);
    white-space: nowrap;
    cursor: pointer;
}

.hg-menu__item:hover { background: var(--hg-fill); }
.hg-menu__item--danger { color: var(--hg-danger); }
.hg-menu__item--danger:hover { background: var(--hg-danger-tint); }

/* Underline tabs: the one tab idiom. The open tab carries .is-active. */
.hg-underline-tab {
    margin-bottom: -2px;
    padding: 10px 16px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--hg-text-secondary);
    font-size: var(--hg-fs-sm);
    font-weight: var(--hg-fw-medium);
    white-space: nowrap;
    cursor: pointer;
}

.hg-underline-tab.is-active { border-bottom-color: var(--hg-accent); color: var(--hg-accent); font-weight: var(--hg-fw-semibold); }

.hg-spinner {
    width: 32px;
    height: 32px;
    margin: 0 auto;
    border: 3px solid var(--hg-fill-strong);
    border-top-color: var(--hg-accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

/* A hand-built dialog: the scrim (a script shows it with display: flex) and
   its sheet. */
.hg-scrim {
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    background: var(--hg-scrim);
}

.hg-scrim--top { z-index: 2000; }
.hg-scrim--column { flex-direction: column; }

.hg-sheet {
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 500px;
    padding: 0;
    border-radius: var(--hg-radius-lg);
    background: var(--hg-surface);
    box-shadow: var(--hg-shadow-4);
}

.hg-sheet__head { padding: var(--hg-space-5); border-bottom: 1px solid var(--hg-separator); }
.hg-sheet__foot { display: flex; justify-content: center; gap: 10px; padding: var(--hg-space-5); border-top: 1px solid var(--hg-separator); }

/* ---- Drop zone ---------------------------------------------------------------- */
.hg-dropzone {
    display: block;
    padding: var(--hg-space-8) var(--hg-space-6);
    border: 1.5px dashed var(--hg-border);
    border-radius: var(--hg-radius-lg);
    background: var(--hg-bg);
    text-align: center;
    cursor: pointer;
    direction: rtl;
    transition: border-color var(--hg-dur-fast) var(--hg-ease), background-color var(--hg-dur-fast) var(--hg-ease);
}

.hg-dropzone:hover,
.hg-dropzone.is-dragover {
    border-color: var(--hg-accent);
    background: var(--hg-accent-tint-subtle);
}

.hg-dropzone__glyph { display: block; margin: 0 auto var(--hg-space-3); color: var(--hg-accent); }
.hg-dropzone__text { margin: 0 0 var(--hg-space-4); color: var(--hg-text-secondary); font-size: var(--hg-fs-md); }

/* The chosen file, in place of the prompt. */
.hg-file-chip {
    display: flex;
    align-items: center;
    gap: var(--hg-space-3);
    padding: var(--hg-space-3) var(--hg-space-4);
    border-radius: var(--hg-radius-md);
    background: var(--hg-surface);
    box-shadow: var(--hg-shadow-1);
    text-align: right;
}

.hg-file-chip__body { flex: 1; min-width: 0; }
.hg-file-chip__name { margin: 0; overflow: hidden; color: var(--hg-text); font-weight: var(--hg-fw-semibold); text-overflow: ellipsis; white-space: nowrap; }
.hg-file-chip__meta { margin: 2px 0 0; color: var(--hg-text-secondary); font-size: var(--hg-fs-xs); }

/* ---- Status ------------------------------------------------------------------- */
/* Loading: the first child holds the text (scripts write to it), the
   spinner is drawn above it. */
.hg-loading {
    padding: var(--hg-space-10) var(--hg-space-5);
    color: var(--hg-text-secondary);
    font-size: var(--hg-fs-base);
    text-align: center;
    direction: rtl;
}

.hg-loading::before {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    margin: 0 auto var(--hg-space-4);
    border: 3px solid var(--hg-fill-strong);
    border-top-color: var(--hg-accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.hg-result { padding: var(--hg-space-2) 0; text-align: center; direction: rtl; }

.hg-result__title {
    margin: 0 0 var(--hg-space-4);
    color: var(--hg-success);
    font-size: var(--hg-fs-lg);
    font-weight: var(--hg-fw-semibold);
}

.hg-notice {
    padding: var(--hg-space-3) 14px;
    border: 1px solid transparent;
    border-radius: var(--hg-radius-md);
    font-size: var(--hg-fs-md);
    direction: rtl;
    text-align: right;
}

.hg-notice__title { margin: 0 0 6px; font-weight: var(--hg-fw-semibold); }
.hg-task__subtitle--center { margin-inline: auto; }

.hg-plain-list {
    margin: 0;
    padding-right: var(--hg-space-5);
    color: var(--hg-text);
    font-size: var(--hg-fs-sm);
    line-height: 1.6;
}

.hg-notice--danger { background: var(--hg-danger-tint); border-color: var(--hg-danger-border); color: var(--hg-danger); }
.hg-notice--warning { background: var(--hg-warning-tint); border-color: var(--hg-warning-border); color: var(--hg-warning); }

/* A row that copies something to the clipboard. */
.hg-copy-row {
    display: flex;
    align-items: center;
    gap: var(--hg-space-2);
    margin-bottom: var(--hg-space-5);
    padding: 10px var(--hg-space-3);
    border-radius: var(--hg-radius-sm);
    background: var(--hg-fill);
    color: var(--hg-text);
    font-size: var(--hg-fs-md);
    font-weight: var(--hg-fw-medium);
    text-decoration: none;
    cursor: pointer;
    direction: rtl;
    transition: background-color var(--hg-dur-fast) var(--hg-ease);
}

.hg-copy-row:hover { background: var(--hg-fill-strong); }
.hg-copy-row > img { width: 18px; height: 18px; }

/* Machine output: logs, error details. */
.hg-log {
    box-sizing: border-box;
    width: 100%;
    padding: 14px;
    overflow-x: auto;
    border-radius: var(--hg-radius-sm);
    background: var(--hg-fill);
    font: var(--hg-fs-xs) / 1.5 var(--hg-font-mono);
    direction: ltr;
    text-align: left;
}

.hg-log > pre { margin: 0; white-space: pre-wrap; word-break: break-all; overflow-wrap: break-word; }

.hg-section-title {
    margin: 0 0 var(--hg-space-3);
    color: var(--hg-text);
    font-size: var(--hg-fs-lg);
    font-weight: var(--hg-fw-semibold);
    direction: rtl;
    text-align: right;
}

/* ---- Small helpers ------------------------------------------------------------ */
.hg-btn { text-decoration: none; }
.hg-btn--block { display: flex; width: 100%; }
.hg-grow { flex: 1; min-width: 0; }
.hg-center { text-align: center; }
.hg-break { overflow-wrap: anywhere; }
.hg-muted { color: var(--hg-text-secondary); }
.hg-stack { display: flex; flex-direction: column; gap: var(--hg-space-2); }
.hg-row { display: flex; align-items: center; gap: var(--hg-space-2); flex-wrap: wrap; }
.hg-tabular { font-variant-numeric: tabular-nums; }

/* ---- Reduced motion --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        /* Transitions only: loading spinners are status, so they keep turning. */
        transition-duration: 1ms !important;
        scroll-behavior: auto !important;
    }
}
