/* signatures.css - the signature manager (saved cards + Draw / Type / Upload editor), the
   signature pad, the typed-style grid, the upload clean-up view and the quick picker.

   Signatures are ink on paper, so every preview sits on a white "paper" chip in both themes
   (var(--paper) stays white in dark mode) with a faint baseline under the ink. Everything
   else is chrome and uses the theme tokens. Prefix: .sig-  */

.sig-mgr [hidden],
.sig-pick [hidden] { display: none !important; }

/* ------------------------------------------------------------------ paper chips */

.sig-paper {
    --sig-rule: color-mix(in srgb, var(--text-3) 40%, var(--paper));
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    overflow: hidden;
    color-scheme: light;
}

/* the faint baseline the ink sits on */
.sig-paper::after {
    content: "";
    position: absolute;
    left: 9%;
    right: 9%;
    bottom: 22%;
    border-bottom: 1px solid var(--sig-rule);
    pointer-events: none;
}

.sig-preview {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    padding: 6px 12px;
    box-sizing: border-box;
    pointer-events: none;
}

.sig-preview svg,
.sig-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    overflow: visible;
    user-select: none;
    -webkit-user-drag: none;
}

/* ------------------------------------------------------------------ dialog */

/* scoped to .modal so nothing happens if the kit puts `cls` on another element */
.modal.sig-modal { width: min(760px, calc(100vw - 32px)); }

@media (max-width: 640px) {
    /* a bottom sheet on phones */
    .modal.sig-modal {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 94vh;
        max-height: 94dvh;
        margin: auto 0 0 !important;
        align-self: flex-end;
        border-radius: var(--radius-l) var(--radius-l) 0 0 !important;
    }
}

.sig-mgr {
    display: grid;
    grid-template-columns: 224px minmax(0, 1fr);
    gap: 20px;
    min-height: 420px;
    font-size: var(--fs-m);
    color: var(--text);
}

.sig-mgr-heading,
.sig-editor-title {
    margin: 0;
    font: 600 var(--fs-m) / 1.3 var(--font-ui);
    color: var(--text);
}

/* ---- saved list */

.sig-mgr-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    max-height: min(600px, calc(100vh - 200px));
    padding-right: 16px;
    border-right: 1px solid var(--line);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sig-mgr-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 32px;
}

.sig-mgr-new,
.sig-editor-back { display: none; }

.sig-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sig-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    transition: border-color var(--dur-fast) var(--ease);
}

.sig-card:hover { border-color: var(--line-strong); }

.sig-card-paper {
    width: 100%;
    height: 64px;
    padding: 0;
}

button.sig-card-use {
    cursor: pointer;
    font: inherit;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

button.sig-card-use:hover {
    border-color: var(--ink-line);
    box-shadow: 0 0 0 1px var(--ink-line);
}

.sig-card-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.sig-card-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--fs-s);
    color: var(--text);
}

.sig-card-actions {
    display: inline-flex;
    align-items: center;
    flex: none;
    margin-right: -4px;
}

.sig-card-actions .icon-btn {
    width: 32px;
    height: 32px;
}

.sig-card-usebtn { align-self: stretch; justify-content: center; }

.sig-star {
    font: 17px / 1 var(--font-ui);
    color: var(--text-3);
}

.sig-star[aria-pressed="true"] { color: var(--ink); }

.sig-card-actions .sig-del:hover { color: var(--red); }

.sig-tag {
    flex: none;
    padding: 1px 7px;
    font-size: var(--fs-xs);
    line-height: 16px;
    color: var(--ink);
    background: var(--ink-soft);
    border-radius: var(--pill);
    white-space: nowrap;
}

.sig-empty {
    padding: 18px 14px;
    text-align: center;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
}

.sig-empty-title {
    margin: 0 0 4px;
    font-weight: 600;
    color: var(--text);
}

.sig-empty-text {
    margin: 0;
    font-size: var(--fs-s);
    line-height: 1.45;
}

/* ---- editor */

.sig-editor {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.sig-editor-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
}

.sig-editor-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 20px;
}

.sig-panels { min-width: 0; }

.sig-editor-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.sig-editor-note {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: var(--fs-s);
    color: var(--text-3);
}

.sig-editor-note svg { flex: none; }

/* ---- ink colour */

.sig-colors {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
    transition: opacity var(--dur-fast) var(--ease);
}

.sig-colors.is-muted { opacity: 0.55; }

.sig-colors-label {
    font-size: var(--fs-s);
    color: var(--text-2);
}

.sig-colors-hint {
    flex-basis: 100%;
    font-size: var(--fs-xs);
    color: var(--text-3);
}

.sig-color-group {
    display: flex;
    gap: 2px;
}

.sig-color {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.sig-color-dot {
    width: 20px;
    height: 20px;
    background: var(--dot);
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--line-strong);
    transition: box-shadow var(--dur-fast) var(--ease);
}

.sig-color:hover .sig-color-dot { box-shadow: 0 0 0 1px var(--text-3); }

.sig-color[aria-checked="true"] .sig-color-dot {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text);
}

/* ------------------------------------------------------------------ Draw tab: the pad */

.sig-draw {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sig-pad-host { min-width: 0; }

.sig-pad {
    width: 100%;
    aspect-ratio: 3 / 1;
    border-color: var(--line-strong);
    border-radius: var(--radius);
    cursor: crosshair;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

@media (max-width: 520px) {
    .sig-pad { aspect-ratio: 2 / 1; }
}

/* the signing line: lower on the pad, with a "×" at its start - both orange, as on the start
   screen's sheet (the pad is always white paper; the × is large bold text, --select is 3.3:1) */
.sig-pad::after {
    left: 6%;
    right: 6%;
    bottom: 24%;
    border-bottom: 2px solid var(--marker);
}

.sig-pad-canvas {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.sig-pad-x {
    position: absolute;
    left: 6%;
    bottom: calc(24% + 3px);
    font: 700 21px / 1 var(--font-ui);
    color: var(--select);
    pointer-events: none;
}

.sig-pad-hint {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(24% + 10px);
    text-align: center;
    font-size: var(--fs-s);
    color: var(--text-3);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--dur) var(--ease);
}

.sig-pad.is-empty .sig-pad-hint { opacity: 1; }

.sig-draw-bar,
.sig-upload-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.sig-bar-label {
    font-size: var(--fs-s);
    color: var(--text-2);
}

.sig-bar-spacer { flex: 1; }

/* base.css's .seg-btn splits a .seg into equal flex shares, which is too narrow for "Medium"
   in this three-way control (it ellipsizes to "Me…") - size each button to its label instead. */
.sig-thickness .seg-btn { flex: 0 0 auto; }

/* ------------------------------------------------------------------ Type tab */

.sig-type {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sig-font-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 8px;
    max-height: 232px;
    padding: 2px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sig-font-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    min-width: 0;
    padding: 6px;
    font: inherit;
    color: var(--text-2);
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.sig-font-card:hover { border-color: var(--line-strong); }

.sig-font-card[aria-checked="true"] {
    border-color: var(--accent-line);
    box-shadow: 0 0 0 1px var(--accent-line);
}

.sig-font-paper {
    width: 100%;
    height: 58px;
    border-color: transparent;
}

.sig-font-card .sig-preview { padding: 4px 8px; }

.sig-font-card.is-loading .sig-preview,
.sig-font-grid.is-placeholder .sig-preview { opacity: 0.4; }

.sig-font-card .sig-preview { transition: opacity var(--dur) var(--ease); }

.sig-font-name {
    position: relative;
    z-index: 0;
    max-width: 100%;
    padding: 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--fs-xs);
    line-height: 18px;
}

/* the chosen style gets the highlighter swipe (skewed like a marker stroke; text stays upright) */
.sig-font-card[aria-checked="true"] .sig-font-name {
    color: var(--text);
    font-weight: 600;
}

.sig-font-card[aria-checked="true"] .sig-font-name::before {
    content: "";
    position: absolute;
    inset: 0 1px;
    z-index: -1;
    background: var(--swipe);
    transform: skewX(-8deg);
}

/* ------------------------------------------------------------------ Upload tab */

.sig-upload {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sig-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-height: 168px;
    padding: 20px;
    font: inherit;
    text-align: center;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease);
}

/* a drop target: orange dashes and tint, like the start screen's sheet and the editor's drop frame */
.sig-drop:hover,
.sig-upload.is-over .sig-drop {
    color: var(--text);
    background: var(--accent-soft);
    border-color: var(--accent-line);
}

.sig-upload.is-over .sig-upload-paper { box-shadow: 0 0 0 2px var(--accent-line); }

.sig-drop:disabled { cursor: progress; opacity: 0.7; }

.sig-drop-title {
    font-weight: 600;
    color: inherit;
}

.sig-drop-hint {
    font-size: var(--fs-s);
    color: var(--text-3);
}

.sig-upload-result {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sig-upload-paper {
    width: 100%;
    height: 150px;
    border-radius: var(--radius);
}

.sig-upload-paper .sig-preview { padding: 12px 20px; }

.sig-upload-status {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 18px;
    margin: 0;
    font-size: var(--fs-s);
    line-height: 1.4;
    color: var(--text-2);
}

.sig-upload-status:empty { display: none; }

.sig-upload-status.is-problem svg {
    flex: none;
    color: var(--amber);
}

.sig-upload.is-busy .sig-upload-status { color: var(--text-3); }

/* ------------------------------------------------------------------ picker popover */

.sig-pick {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: min(312px, calc(100vw - 32px));
    font-size: var(--fs-m);
    color: var(--text);
}

.sig-pick-scroll {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: min(360px, 55vh);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sig-pick-heading {
    padding: 4px 6px 2px;
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-3);
}

.sig-pick-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sig-pick-empty {
    margin: 0;
    padding: 4px 6px 8px;
    font-size: var(--fs-s);
    color: var(--text-2);
}

.sig-pick-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 56px;
    padding: 5px 6px;
    font: inherit;
    text-align: left;
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: var(--radius-s);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
}

.sig-pick-item:hover { background: var(--surface-3); }

.sig-pick-paper {
    flex: none;
    width: 128px;
    height: 46px;
}

.sig-pick-paper .sig-preview { padding: 4px 8px; }

.sig-pick-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--fs-s);
}

.sig-pick-foot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
}

/* stand-in anchor when the picker has no button to hang from (centred near the top) */
.sig-anchor {
    position: fixed;
    top: 18vh;
    left: 50%;
    width: min(312px, calc(100vw - 32px));
    height: 0;
    transform: translateX(-50%);
    pointer-events: none;
    visibility: hidden;
}

.sig-anchor.at-point {
    width: 0;
    transform: none;
}

/* ------------------------------------------------------------------ focus */

.sig-card-use:focus-visible,
.sig-color:focus-visible,
.sig-font-card:focus-visible,
.sig-drop:focus-visible,
.sig-pick-item:focus-visible,
.sig-star:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------ narrow screens */

@media (max-width: 640px) {
    .sig-mgr {
        grid-template-columns: minmax(0, 1fr);
        min-height: 0;
    }

    .sig-mgr-list {
        max-height: none;
        padding-right: 0;
        border-right: 0;
        overflow: visible;
    }

    .sig-mgr[data-view="editor"] .sig-mgr-list,
    .sig-mgr[data-view="list"] .sig-editor { display: none; }

    .sig-mgr-new,
    .sig-editor-back { display: inline-flex; }

    .sig-editor-foot {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        padding-bottom: 2px;
    }

    .sig-editor-note { display: none; }

    .sig-editor-foot .sig-save { flex: 1; justify-content: center; }

    .sig-font-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}

@media (pointer: coarse) {
    .sig-card-actions .icon-btn,
    .sig-color { width: 40px; height: 40px; }
}
