/* =============================================================================
 * app.css - the shared component layer for every nube app.
 *
 * WHAT THIS IS
 *   nube is nine small single-page apps that must feel like one product. The
 *   colour tokens and a few widgets already lived in shared/theme.css; this
 *   file adds the rest of the common UI - the app shell, the header, the icon
 *   button, the dialog, the form field, pills and cards - so an app's own
 *   <style> block only has to hold what is genuinely unique to that app.
 *
 *   THIS FILE (plus theme.css and the ui.js header comment) IS the nube style
 *   guide - the only one. Each block below is preceded by a comment that says
 *   what the component is, when to use it, and the rules it must follow. If you
 *   are building or changing nube UI, read the comment for the component you
 *   are touching. There is no separate style-guide document to keep in sync.
 *
 * HOW TO LOAD  (in every app's <head>, in this order)
 *     <meta name="theme-color" content="#1E1F23">           <!-- the dark --bg -->
 *     <link rel="stylesheet" href="../shared/theme.css">    <!-- tokens first -->
 *     <link rel="stylesheet" href="../shared/app.css">
 *     <script>try{ if(localStorage.getItem('balata-theme')==='light')
 *         document.documentElement.setAttribute('data-theme','light'); }catch(e){}</script>
 *     <script src="../shared/theme.js" defer></script>      <!-- scheme toggle + sync -->
 *     <script src="../shared/ui.js"></script>               <!-- NubeUI: sheets, toast, buttons -->
 *     ... then the app's own <style> ...
 *   The inline script applies the saved scheme before first paint (no flash).
 *   The app's <style> comes last, so on an equal-specificity clash the app
 *   wins - use that only for real per-app layout, never to restyle a shared
 *   component into a different look. PWA manifests set theme_color /
 *   background_color to #1E1F23.
 *
 * THE TOKENS  (defined in theme.css - use the name, never the literal)
 *   colour     --bg --card --card2 --line --text --text-dim --text-faint
 *              --accent --on-accent --danger --link --ok --warn --busy --shadow
 *              (each has a one-line "what it's for" comment in theme.css)
 *   type       --font-sans --font-mono
 *   radius     --radius-s (8) --radius-m (12) --radius-l (16) --radius-pill (999)
 *   spacing    --space-1..5  (4 8 12 16 24)
 *   elevation  --elev-card --elev-dialog --scrim
 *   motion     --tr-fast (colour) --tr-move (transform)
 *
 * TYPE SIZES  (rem; weight 700 where noted)
 *   app title (h1 / .app-title) 1.1  --accent 700    dialog title (h2)  1.15  700
 *   body / list rows            0.9 - 0.95           field label / meta 0.8  --text-dim
 *   section label               0.72 700 uppercase, letter-spacing 0.06em, --text-dim
 *
 * GLOBAL RULES
 *   - Never write a hex colour, a raw box-shadow, or an off-scale corner radius
 *     in an app. Add the value to theme.css if the scale is missing something.
 *   - Hover / pressed tints use color-mix(in srgb, var(--text) N%, transparent)
 *     so they flip light-on-dark and dark-on-light. Never a fixed rgba().
 *   - An accent fill means "active / selected / primary". It is not a hover
 *     colour - hover is a neutral --text tint.
 *   - Every icon-only control needs a Spanish `title` and an `aria-label`.
 *   - Every date shown to a person is yyyy-mm-dd. No locale or month-name form.
 *   - All user-facing text is Spanish; app names keep their short label
 *     ("Calc", "Drive", ...).
 *   - A dialog closes on its own × / ✓ buttons and the Esc key only - never on
 *     a click on the backdrop.
 *
 * PER-APP OVERRIDES
 *   An app's <style> may carry a few small overrides of the rules here - a
 *   page that hides its own scroll, calc's tinted toolbar, trip's two-column
 *   layout, the compose-bar submit in tasks, the entry-screen styling in
 *   login.html / admin.html, the 30-32px "toolbar button" that calc / text /
 *   write use instead of .icon-btn. Each such override carries a one-line
 *   comment saying why. That comment is the record; there is no central list.
 * ===========================================================================*/


/* -----------------------------------------------------------------------------
 * BASE / RESET
 *
 * border-box everywhere. The page never scrolls sideways. The body carries the
 * UI font, the primary text colour and the page background so an app's <body>
 * rule can be deleted. Links are the accent-independent --link blue, underline
 * on hover only.
 * ---------------------------------------------------------------------------*/
*,
*::before,
*::after            { box-sizing: border-box; }

html               { overflow-x: hidden; overflow-y: auto; }

body
{
    margin: 0;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
}

a                  { color: var(--link); text-decoration: none; }
a:hover            { text-decoration: underline; opacity: 0.85; }


/* -----------------------------------------------------------------------------
 * APP SHELL - two layouts, pick one per app
 *
 * A) TOOL SHELL  (.app)  - calc, calendar, drive, text, write, planner
 *    A full-height flex column: a fixed .topbar on top, the work area (a grid,
 *    an editor, a map) fills the rest and does its own scrolling. The page
 *    background is --bg.
 *
 * B) CARD SHELL  (.page > .page-inner > .card)  - tasks, contact
 *    A single centred column that reads like a sheet of paper. Max width
 *    460px. On a real phone (<=480px) the card loses its border, radius and
 *    shadow and goes edge to edge. The edge-to-edge rule is scoped to
 *    .page > .page-inner > .card, so a standalone .card (login, a dialog-free
 *    panel) keeps its box at every width.
 *
 *    trip is a card app too but runs its own two-column variant (.trip-panel,
 *    not .card): the list on the left, a sticky route map on the right on a
 *    wide viewport.
 *
 * Do not mix A and B. An app is either a tool or a list/document.
 * ---------------------------------------------------------------------------*/
.app
{
    display: flex;
    flex-direction: column;
    height: 100%;
}

.page
{
    display: flex;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding: 28px 14px;
}

.page-inner        { width: 100%; max-width: 460px; }

.card
{
    padding: 20px 16px 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    box-shadow: var(--elev-card);
}

@media (max-width: 480px)
{
    .page                        { padding: 0; }
    .page > .page-inner          { max-width: 100%; }
    .page > .page-inner > .card
    {
        min-height: 100vh;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }
}


/* -----------------------------------------------------------------------------
 * HEADER
 *
 * Same shape in every app, same order left to right:
 *
 *     [.app-icon]  [<h1> app name]  ... app controls ...  [.sync-indicator]
 *
 * - .topbar is the tool-shell header: one row, scrolls sideways if it must,
 *   divider underneath. Card-shell apps use a plain flex row with the same
 *   parts and `margin-bottom: var(--space-4)` instead of a border.
 * - .app-icon: an inline SVG in --accent. Render it 20px in a .topbar, 26px in
 *   a card header.
 * - The <h1> (or .app-title) is ALWAYS --accent, 1.1rem, weight 700, no margin.
 *   Do not colour it --text; do not size it per app.
 * - The sync dot is ALWAYS the last child of the header.
 * - Header buttons are .icon-btn (see below). The primary "new" one gets
 *   .accent; a destructive one gets .danger.
 * ---------------------------------------------------------------------------*/
.topbar
{
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}

.topbar h1,
.app-title
{
    flex: 0 0 auto;
    margin: 0 10px 0 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

.app-icon          { flex: 0 0 auto; color: var(--accent); }

/* Card-shell header: same parts, no divider. */
.header
{
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}
.header h1,
.header .app-title
{
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* -----------------------------------------------------------------------------
 * ICON BUTTON  (.icon-btn)  - the workhorse control
 *
 * A round, borderless, icon-only button used in headers, toolbars and rows.
 *
 *   size        36px (use .icon-btn.sm = 30px for dense toolbars)
 *   shape       circle, no border, transparent background
 *   colour      --text-dim at rest, --text on hover
 *   hover       a neutral --text 9% wash (NEVER an accent tint)
 *   pressed     --text 14%
 *   focus       a visible --accent ring for keyboard users
 *   disabled    opacity 0.45, no pointer, no hover
 *
 * The SVG inside: 24x24 viewBox, stroke="currentColor", fill="none",
 * stroke-width ~2, round caps and joins (Feather style). Rendered 18-20px.
 *
 * MODIFIERS
 *   .accent   solid --accent fill, --on-accent icon. The "new item" button.
 *   .danger   a DELETE button: a --danger icon at rest (not just on hover);
 *             hover adds a faint --danger wash. Borderless like every other
 *             .icon-btn - the red icon alone marks it. Matches the dialog
 *             .btn-danger so "delete" looks the same everywhere.
 *   .is-active  solid --accent fill for a toggle that is currently on
 *               (e.g. the calendar view switch).
 * ---------------------------------------------------------------------------*/
.icon-btn
{
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: background-color var(--tr-fast), color var(--tr-fast);
}
.icon-btn svg           { width: 19px; height: 19px; display: block; }
.icon-btn:hover         { background: color-mix(in srgb, var(--text) 9%, transparent); color: var(--text); }
.icon-btn:active        { background: color-mix(in srgb, var(--text) 14%, transparent); }
.icon-btn:focus         { outline: none; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn:disabled      { opacity: 0.45; cursor: default; background: transparent; color: var(--text-dim); }

.icon-btn.sm            { width: 30px; height: 30px; }
.icon-btn.sm svg        { width: 17px; height: 17px; }

.icon-btn.accent        { background: var(--accent); color: var(--on-accent); }
.icon-btn.accent:hover  { background: var(--accent); filter: brightness(1.08); }

.icon-btn.danger        { color: var(--danger); }
.icon-btn.danger:hover  { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

.icon-btn.is-active         { background: var(--accent); color: var(--on-accent); }
.icon-btn.is-active:hover   { background: var(--accent); }

/* TOOLBAR BUTTON - a related but distinct component, NOT styled here.
 * calc (.fmt-btn), text (.tb-btn) and write (#writeTools .icon-btn) each define
 * their own: a 30-32px rounded SQUARE (--radius-s), --text-dim icon, and an
 * ACCENT-tinted hover (color-mix(--accent 14%)) / active (--accent 24%) because
 * the button acts on document content, not app chrome. It stays per-app on
 * purpose - the three toolbars differ enough that a shared class earns nothing.
 * If you add a fourth, copy one of the existing three. */


/* -----------------------------------------------------------------------------
 * TEXT BUTTON  (.text-btn)  - a wide call to action
 *
 * Use when a button needs a word, not just an icon: "Añadir", "Importar",
 * "Guardar cambios" on a full-width row. Accent fill, --on-accent text.
 * For a dialog's confirm / cancel row use the round .btn set from theme.css
 * instead (see DIALOG BUTTONS below).
 *
 *   .text-btn.ghost   quiet version: no fill, --line border, --text-dim text.
 *   .text-btn.dashed  an "add another" affordance: dashed accent border on a
 *                     faint accent wash (trip's "Añadir etapa").
 * ---------------------------------------------------------------------------*/
.text-btn
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-s);
    background: var(--accent);
    color: var(--on-accent);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter var(--tr-fast), background-color var(--tr-fast);
}
.text-btn:hover     { filter: brightness(1.08); }
.text-btn:active    { filter: brightness(0.94); }
.text-btn:disabled  { opacity: 0.45; cursor: default; filter: none; }

.text-btn.ghost
{
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--line);
}
.text-btn.ghost:hover { background: color-mix(in srgb, var(--text) 9%, transparent); color: var(--text); filter: none; }

.text-btn.dashed
{
    width: 100%;
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    color: var(--accent);
    border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
}
.text-btn.dashed:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); filter: none; }


/* -----------------------------------------------------------------------------
 * DIALOG BUTTONS  (.sheet-actions / .btn / .btn-*)  - defined in theme.css
 *
 * The bottom row of a dialog is a right-aligned line of round 44px icon-only
 * buttons. Mark them up declaratively and let shared/ui.js fill in class + SVG:
 *
 *     <div class="sheet-actions">
 *       <button data-act="close"   title="Cancelar"></button>
 *       <button data-act="primary" title="Guardar"></button>
 *     </div>
 *
 * Roles: close (X) - primary (check) - danger (trash) - ghost (help).
 * .sheet-actions-left pins a delete button to the far left.
 *
 * ONE ICON PER MEANING (dialogs and toolbars alike):
 *   check   = confirm / apply / save / rename / create - always, any verb.
 *   saveas  = "save as a new copy" (check + a small +). Nothing else.
 *   trash   = a destructive confirm. Never looks like a save.
 *   A different verb keeps its own glyph: edit (opens a form), search (runs a
 *   query), plus (a compose bar).
 *
 * A dialog whose only action is "close" has NO bottom row - ui.js moves the
 * lone close button to the top-right corner as .sheet-close.
 * ---------------------------------------------------------------------------*/


/* -----------------------------------------------------------------------------
 * DIALOG / SHEET  (.sheet-backdrop > .sheet)
 *
 *     <div class="sheet-backdrop" id="fooBackdrop">
 *       <div class="sheet">
 *         <h2>Título</h2>
 *         ... .field rows ...
 *         <div class="sheet-actions"> ... </div>
 *       </div>
 *     </div>
 *
 * - The backdrop is a fixed --scrim layer; add .open (or NubeUI.open(id)) to
 *   show it. It centres the sheet on desktop.
 * - The sheet is a --card panel, --radius-l corners, --elev-dialog shadow,
 *   scrolls inside at tall content. Default max-width 460px; add .sheet--wide
 *   for 560px when the content is genuinely wide (a table, a wide form).
 * - CLOSING: only the × / ✓ buttons and the Esc key close a dialog. Never wire
 *   a click on the backdrop to close - it loses half-typed input.
 * - On a phone (<=640px) the sheet becomes a bottom sheet: full width, only
 *   the top corners rounded, pinned to the bottom edge.
 * ---------------------------------------------------------------------------*/
.sheet-backdrop
{
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--scrim);
}
.sheet-backdrop.open { display: flex; }

.sheet
{
    position: relative;
    width: 100%;
    max-width: 460px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    box-shadow: var(--elev-dialog);
}
.sheet--wide       { max-width: 560px; }

.sheet h2
{
    margin: 0 0 14px;
    font-size: 1.15rem;
    font-weight: 700;
}

/* A dialog header row: a title on the left, one small control on the right
 * (an "all day" switch, a step counter). */
.sheet-header
{
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 2px 0 16px;
}
.sheet-header h2   { margin: 0; }

@media (max-width: 640px)
{
    .sheet-backdrop { align-items: flex-end; padding: 0; }
    .sheet
    {
        max-width: none;
        max-height: 90vh;
        border-inline: none;
        border-bottom: none;
        border-radius: var(--radius-l) var(--radius-l) 0 0;
    }
}


/* -----------------------------------------------------------------------------
 * FORM FIELD  (.field)
 *
 *     <div class="field">
 *       <label for="x">Etiqueta</label>
 *       <input id="x" type="text">
 *     </div>
 *
 * - Label: 0.8rem, --text-dim, sentence case (NOT uppercase - that style is
 *   reserved for .section-label).
 * - Inputs, selects and textareas share one look: --card2 fill, --line border,
 *   --radius-s, 10px 11px padding, the page font at 1rem, no default outline.
 * - Focus shows a slightly stronger border (--text 30%). No glow, no colour
 *   change - the same treatment on every field in every app.
 * - Put two fields side by side by wrapping them in .field-row.
 *
 * SPECIFICITY: the input rules below are deliberately kept at their weakest
 * (`input, select, textarea`), so ANY rule an app already has - a
 * `.topbar-search`, a `.file-label-input`, a `.loc-input-wrap input` - still
 * wins. app.css only supplies the default for an otherwise-unstyled field.
 * When you sweep an app, delete its local copy of this look and let app.css
 * carry it.
 * ---------------------------------------------------------------------------*/
.field             { margin-bottom: 14px; }

.field label
{
    display: block;
    margin-bottom: 5px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.field-row
{
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.field-row .field  { flex: 1 1 120px; min-width: 0; }

/* A field's control fills the row. Scoped to .field so it never stretches a
 * toolbar / search input that lives outside a form. */
.field input,
.field select,
.field textarea    { width: 100%; }

input,
select,
textarea
{
    padding: 10px 11px;
    font: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    outline: none;
}
textarea           { resize: vertical; min-height: 54px; }

input:focus,
select:focus,
textarea:focus     { border-color: color-mix(in srgb, var(--text) 30%, transparent); }

::placeholder      { color: var(--text-faint); }

/* Browser autofill paints its own pale background + a hard border. Force the
 * themed look back. Chrome/Edge: the inset box-shadow is the only way to cover
 * the autofill background. Firefox: honours background-color on :autofill. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus
{
    -webkit-text-fill-color: var(--text);
    -webkit-box-shadow: 0 0 0 100px var(--card2) inset;
    caret-color: var(--text);
    border: 1px solid var(--line);
}
input:autofill { background-color: var(--card2); color: var(--text); }

/* Checkbox / radio / colour / file / range keep the browser's box - the field
 * look above is for text-like inputs only. */
input[type="checkbox"],
input[type="radio"],
input[type="color"],
input[type="file"],
input[type="range"]
{
    width: auto;
    padding: 0;
    background: none;
    border: none;
    border-radius: 0;
    accent-color: var(--accent);
}


/* -----------------------------------------------------------------------------
 * PILL  (.pill)  and  TAG  (.tag)
 *
 * .pill  - a small rounded button, used for filters and mode switches. At rest
 *          it is a quiet --card2 chip; add .is-active for the accent state.
 * .tag   - the same shape but read-only (a metadata chip on a card). No hover,
 *          no active state, default cursor.
 * ---------------------------------------------------------------------------*/
.pill
{
    padding: 7px 14px;
    font-family: inherit;
    font-size: 0.77rem;
    color: var(--text-dim);
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: opacity var(--tr-fast), background-color var(--tr-fast);
}
.pill:hover        { opacity: 0.85; }
.pill.is-active
{
    color: var(--on-accent);
    background: var(--accent);
    border-color: var(--accent);
}

.tag
{
    padding: 4px 10px;
    font-size: 0.74rem;
    color: var(--text-dim);
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
}


/* -----------------------------------------------------------------------------
 * CARD ROW  (.card-row)
 *
 * A row in a list - a file in Drive, a trip, a saved document. A --card2
 * surface with --line border and --radius-m corners. Hover firms up the
 * border; .is-selected fills it with accent and flips the text.
 * ---------------------------------------------------------------------------*/
.card-row
{
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--card2);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    transition: border-color var(--tr-fast), background-color var(--tr-fast);
}
.card-row:hover        { border-color: color-mix(in srgb, var(--text) 22%, transparent); }
.card-row.is-selected  { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }


/* -----------------------------------------------------------------------------
 * SECTION LABEL  (.section-label)
 *
 * A small uppercase heading over a group of fields or rows ("DOCUMENTOS",
 * "ETAPAS"). The one place uppercase + letter-spacing is used. Keep it short.
 * ---------------------------------------------------------------------------*/
.section-label
{
    margin: 4px 2px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
}


/* -----------------------------------------------------------------------------
 * SYNC INDICATOR + TOAST  - defined in theme.css
 *
 * .sync-indicator  a filled-circle SVG in the header. Toggle the state class:
 *     (none)     --danger red   not synced yet (the safe start state)
 *     .synced    --ok green     saved
 *     .busy      --busy blue    a GET / PUT is in flight
 *     .offline   --warn gold    working offline, changes queued
 *
 * .toast  a bottom-centre transient message. Put <div id="toast" class="toast">
 * in the page and call NubeUI.toast("Guardado"). For confirmations only, not
 * for errors that need the user to act.
 * ---------------------------------------------------------------------------*/
