/* The look of the link page. It belongs to this module and not to the toolkit: a picture with a
   handful of short links under it is nothing general but the picture of this one thing. What
   stands here travels along in the package of the module and is loaded by the app as soon as it
   has installed it.

   THE OLD START PAGE IS THE MEASURE (decided 2026-09-17): a chapter is a narrow bar over the
   whole width, a tile is a picture of a fixed height with its targets in ONE line under it - no
   frame, no background -, and the rows are set tight, so that a page holds many of them. Colours,
   spacings and type come out of the variables of the platform. Sizes stand HERE and never in the
   data: a tile is as big as this file says, not as big as a row happens to say. */

/* --- the page: chapters one below the other --------------------------------------------- */

/* positioned, so that the hidden file field at its end stays inside it and never widens the page */
.link-page { position: relative; display: flex; flex-direction: column; gap: var(--s1); }

/* the head of the page carries the search box and the button for a new chapter */
.link-search { width: var(--field-medium); max-width: 100%; }

/* the form for a new chapter, opened from the top: it stands under the head, over the chapters */
.link-form-top { display: flex; margin-bottom: var(--s2); }

/* --- a chapter: a bar and a wrapping row of tiles ---------------------------------------- */

.link-chapter { margin-bottom: var(--s2); }

/* The bar is the handle of the chapter: a pointer takes hold of it and drags the whole chapter
   up or down. It is reachable by the tab key as well, so that the keyboard finds the chapter -
   F2 renames it there, Alt+Shift with the arrows moves it. A bar over the whole width, like the
   heading of the old page - in a tone of the platform, not in the colour of the old one. */
.link-head
{
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin: 0;
    padding: 2px var(--s2);
    min-height: 26px;
    background: var(--surface-3);
    border-radius: var(--radius-sm);
}

.link-head:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.link-title
{
    margin: 0;
    font-size: var(--fs-base);
    font-weight: 600;
    cursor: grab;
}

/* the field the bar turns into: the same size as the title, so that nothing jumps */
.link-title-field { font-size: var(--fs-base); font-weight: 600; max-width: 420px; }

/* The row wraps: as many tiles as fit beside each other, the rest on the next line. It keeps a
   height even when empty - an empty chapter is still a place to drop a link on, and a place to
   double-click on. */
.link-row
{
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--s2) var(--s4);
    min-height: 56px;
    padding: var(--s2) var(--s1);
}

/* --- a tile: the picture, the targets in one line under it ------------------------------ */

.link-tile
{
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--s1);
    border-radius: var(--radius-sm);
    box-sizing: border-box;
}

.link-tile:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* The picture: a fixed height, the width follows the picture up to a limit - a wide logo stays
   readable, a square one stays square. No frame and no background: the picture stands on the
   page, as it did on the old one (decided 2026-09-17). */
.link-picture
{
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    min-width: 32px;
    max-width: 110px;
    cursor: grab;
    text-decoration: none;
    color: inherit;
}

/* A LINK LOOKS LIKE A LINK (2026-09-21): the pointer, as everywhere on the web - that the picture
   with a target and the words are handles for dragging as well does not change what they are
   first. The title, and a picture without a target, are handles and nothing else: they keep the
   hand. While a tile is dragged the closed hand wins, further down. */
a.link-picture, .link-target-text { cursor: pointer; }

.link-picture img
{
    display: block;
    height: 32px;
    width: auto;
    max-width: 110px;
    object-fit: contain;
}

/* the picture or the placeholder, the same in the card and in the mask */
.link-pic { display: inline-flex; align-items: center; justify-content: center; }

/* the placeholder with the initial - the same badge a module without an icon gets, only bigger */
.link-picture .icon { --icon-size: 28px; font-size: var(--fs-md); }

/* the targets: short words side by side in ONE line, each a link */
.link-targets
{
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    /* half a step between the words (2026-09-21): eight pixels read as three separate things, four
       as one row of words */
    gap: var(--s1);
    white-space: nowrap;
}

.link-target { display: flex; align-items: center; border-radius: var(--radius-sm); }

.link-target-text
{
    display: block;
    padding: 0 1px;
    font-size: var(--fs-sm);
    color: var(--link);
    text-decoration: none;
}

.link-target-text:hover { text-decoration: underline; }

/* --- the tools: pencil and bin - under the pointer, and always reachable ----------------- */

/* They appear under the pointer or when something inside has the focus. Invisible does NOT mean
   unreachable: the tab key finds them, and then they are to be seen. Where there is no pointer at
   all - a phone - they always stand there: the stylus is the only way to the mask on touch. */
.link-tools
{
    display: inline-flex;
    align-items: center;
    gap: 0;
    opacity: 0;
    transition: opacity .12s ease-in-out;
}

.link-tile > .link-tools
{
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.link-tools .btn { padding: 2px; border: 0; }

.link-tools .btn svg { width: 16px; height: 16px; }

.link-tile:hover > .link-tools,
.link-tile:focus-within > .link-tools,
.link-head:hover > .link-tools,
.link-head:focus-within > .link-tools,
.link-tile.link-edit .link-tools,
.link-target-open .link-tools { opacity: 1; }

@media (hover: none)
{
    .link-tools { opacity: 1; }
}

/* the arrows of the toolkit point left and right; where things stand one below the other they
   are turned to point up and down */
.link-vertical { display: inline-flex; }

.link-vertical .btn svg { transform: rotate(90deg); }

/* --- the plus at the end of a row, and the field it turns into --------------------------- */

/* The visible way to a new tile (decided 2026-09-17): it stands at the end of every row, faint
   until the pointer reaches it - but it stands there, and so does its title. */
.link-row-plus
{
    display: inline-flex;
    align-self: center;
    opacity: .55;
    transition: opacity .12s ease-in-out;
}

.link-row-plus:hover,
.link-row-plus:focus-within { opacity: 1; }

.link-row-add
{
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    align-self: center;
    width: 280px;
    max-width: 100%;
}

/* --- the mask: a tile in its editing state --------------------------------------------- */

/* The mask is the tile itself, opened up: name, one line per target, the address field for the
   next one, the picture and the way into another chapter. It takes the whole row, because two
   fields side by side need room; the neighbouring tiles wrap around it. It is the one thing on
   the page with a frame: a form is a form. */
.link-tile.link-edit
{
    align-items: stretch;
    width: 100%;
    max-width: 520px;
    gap: var(--s2);
    padding: var(--s3);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: default;
}

.link-edit .link-picture { cursor: default; }

/* inside the mask the targets are lines of fields, one below the other */
.link-edit .link-targets
{
    flex-direction: column;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 1px;
    white-space: normal;
}

.link-mask-head
{
    display: flex;
    align-items: center;
    gap: var(--s2);
}

.link-mask-head .link-field { flex: 1 1 auto; min-width: 0; }

/* the fields of the mask look like fields and take the whole width they are given */
.link-field
{
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    font: inherit;
}

.link-field-url { font-family: var(--mono); font-size: var(--fs-sm); }

/* a target inside the mask: the two fields and the buttons for this one line */
.link-target-open
{
    display: flex;
    align-items: center;
    gap: var(--s1);
    padding: 1px 0;
}

.link-target-fields
{
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: var(--s1);
}

.link-target-fields .link-field { flex: 1 1 40%; }

.link-target-fields .link-field-url { flex: 2 1 60%; }

/* the line for the next target, the picture and the move - each a small row of its own */
.link-add,
.link-image-url,
.link-move
{
    display: flex;
    align-items: center;
    gap: var(--s2);
}

.link-add .link-field,
.link-image-url .link-field { flex: 1 1 auto; }

.link-image
{
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    padding-top: var(--s1);
    border-top: 1px solid var(--border);
}

.link-label { font-size: var(--fs-sm); color: var(--text-muted); }

.link-file
{
    display: flex;
    align-items: center;
    gap: var(--s2);
    font-size: var(--fs-sm);
}

.link-move { padding-top: var(--s1); border-top: 1px solid var(--border); }

.link-move .suggest { flex: 1 1 auto; min-width: 140px; }

/* the mask's own tools stand at its right edge, in the row of the move */
.link-mask-tools { margin-left: auto; }

/* a hint at the field: what the module refused, in a sentence - it stays until the next try */
.link-problem
{
    font-size: var(--fs-sm);
    color: var(--err-fg);
}

/* --- the free area under the last chapter ---------------------------------------------- */

/* Where a dropped link becomes a new chapter, and where the button for the keyboard stands. It
   is drawn as a place: a dashed frame says "something may be put here". */
.link-free
{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--s2);
    margin-top: var(--s3);
    padding: var(--s4);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
}

.link-free p { margin: 0; }

/* the form for a new chapter: its name, the dropped address when there is one, go and cancel */
.link-form
{
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    width: 100%;
    max-width: 640px;
}

.link-form .link-field { flex: 1 1 180px; }

.link-form .link-problem { flex-basis: 100%; }

/* --- dropping from outside: the place under the pointer lights up ---------------------- */

.link-over
{
    outline: 2px dashed var(--accent);
    outline-offset: 2px;
}

/* --- dragging inside the page ----------------------------------------------------------- */

/* the handles for a finger: on them a touch drags instead of scrolling the page. Nowhere else -
   the rest of the page stays scrollable on a phone (decided 2026-09-17) */
.link-handle
{
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* while an element travels, nothing shall be selected under it */
.link-dragging { user-select: none; }

/* the dragged element lifts off the page a little and travels over the others */
.link-dragged
{
    position: relative;
    z-index: 1;
    opacity: .85;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    cursor: grabbing;
}

.link-dragged .link-picture,
.link-dragged .link-target-text,
.link-dragged .link-title { cursor: grabbing; }

/* --- the one file field of the page ------------------------------------------------------ */

/* The field a dropped picture goes into. It is not shown - the drop puts the files in and lets
   it fire -, but it must not be display:none: a field the browser considers absent is one whose
   events some browsers swallow. So it is there, one pixel small, out of sight. */
.link-upload
{
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* on a narrow screen the mask takes all the width, and the search box less of it */
@media (max-width: 720px)
{
    .link-tile.link-edit { max-width: none; }
    .link-search { width: var(--field-short); }
}
