/* ═══════════════════════════════════════
   components.css — shared UI primitives
   ═══════════════════════════════════════

   Buttons, inputs, dropdown menus, and card panels/modals. Loaded after
   main.css (needs its tokens) and before the feature stylesheets (so a
   feature's own `.x-btn { padding: … }` delta wins at equal specificity).

   Usage is additive, matching tiles.css / animation.css: keep the existing
   prefixed class for JS hooks and per-element deltas, and add the primitive
   class(es) alongside — `<button class="cards-filter-btn btn btn--ghost btn--mono">`.
*/

/* ── Button ──────────────────────────────
   .btn sets only the resting frame (font, border box, radius, cursor,
   transition). A variant sets resting colors + a default :hover; a button
   that hovers differently keeps its own :hover rule. Layout (display, padding,
   font-size, width) stays on the prefixed class. */
.btn {
    font-family: var(--font-sans);
    font-weight: 500;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.15s;
}

.btn:disabled {
    cursor: not-allowed;
}

/* Accent-filled — primary actions (Search, Sign in, Sync, Refresh). */
.btn--primary {
    color: var(--bg);
    background: var(--accent);
}
.btn--primary:hover {
    background: var(--accent-dim);
}
.btn--primary:disabled {
    background: var(--border);
    color: var(--text-muted);
}

/* Bordered / transparent — secondary actions, dropdown triggers, toggles. */
.btn--ghost {
    color: var(--text);
    background: transparent;
    border-color: var(--border);
}
.btn--ghost:hover {
    border-color: var(--border-focus);
    color: var(--text);
}

/* Borderless — inline row actions (✎, ⚙ small controls). */
.btn--subtle {
    color: var(--text-muted);
    background: transparent;
    font-weight: 400;
}
.btn--subtle:hover {
    color: var(--text);
}

/* Monospace label — most filter / import-export / dropdown buttons. */
.btn--mono {
    font-family: var(--font-mono);
    font-weight: 400;
}

/* Square icon button — a single glyph, centered, fixed size via --btn-size. */
.btn--icon {
    --btn-size: 30px;
    width: var(--btn-size);
    height: var(--btn-size);
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Destructive hover accent — pair with any variant. */
.btn--danger:hover {
    background: var(--error);
    border-color: var(--error);
    color: var(--text);
}

/* Topbar Login/Logout — a ghost button with the accent (not border-focus) hover. */
.btn-login {
    font-size: 0.85rem;
    padding: 8px 20px;
    text-decoration: none;
}
.btn-login:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Input ───────────────────────────────
   Every <input> and <textarea> gets this base (previously a bare `input {}`
   rule in login.css). The `.input` / `.textarea` classes are aliases for
   non-native elements (contenteditable, styled wrappers). Feature stylesheets
   override font-size / padding / width per field on their prefixed class. For a
   value picker use the .select-dropdown component (dropdown.js) rather than a
   native <select>. */
input,
.input,
.textarea {
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

input:focus,
.input:focus,
.textarea:focus {
    border-color: var(--border-focus);
}

input::placeholder,
.input::placeholder,
.textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

/* ── Menu ────────────────────────────────
   Dropdown popover that opens directly below its trigger. The prefixed class
   keeps its own horizontal anchoring (left/right), width, max-height, and any
   z-index / scroll outliers. Add `.scroll-thin` for a scrolling one. */
.menu {
    position: absolute;
    top: calc(100% + 6px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-menu);
    z-index: 300;
    overflow: hidden;
    animation: revealDown 0.2s ease forwards;
}

/* Rotating chevron on a .menu trigger — the `‹` glyph is in the markup; it
   points down at rest and flips up while the trigger carries `.open`. */
.dropdown-arrow {
    display: inline-block;
    font-size: 1.1rem;
    line-height: 1;
    transform: rotate(-90deg);
    transition: transform 0.25s ease;
}
.open > .dropdown-arrow {
    transform: rotate(90deg);
}

/* ── Select dropdown ─────────────────────
   Value picker built from dropdown.js — an input-styled trigger + a .menu of
   options, with the rotating .dropdown-arrow above. Feature CSS overrides only
   size/typography on a wrapper class. */
.select-dropdown {
    position: relative;
}
.select-dropdown-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.2s;
}
.select-dropdown-btn:hover,
.select-dropdown-btn.open {
    border-color: var(--border-focus);
}
.select-dropdown-btn .dropdown-arrow {
    color: var(--text-muted);
    font-size: 1rem;
    flex-shrink: 0;
}
.select-dropdown-menu {
    left: 0;
    min-width: 100%;
    padding: 4px;
}
.select-dropdown--up .select-dropdown-menu {
    top: auto;
    bottom: calc(100% + 6px);
    animation-name: revealUp;
}
.select-dropdown-option {
    padding: 8px 10px;
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.select-dropdown-option:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.select-dropdown-option.selected {
    color: var(--text);
}

/* ── Pill toggle ─────────────────────────
   Segmented control: a rounded track holding 2+ `.pill-toggle-btn` options with
   a `.pill-indicator` sliding behind whichever has `.active`. positionPillIndicator()
   (animation.js) sizes and moves the indicator — call it after changing which
   button is `.active`, and once the track first becomes visible. The prefixed
   class keeps only size/typography deltas. */
.pill-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    flex-shrink: 0;
}

.pill-toggle-btn {
    position: relative;
    z-index: 1;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.82rem;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.25s;
}
.pill-toggle-btn:hover {
    color: var(--text);
}
.pill-toggle-btn.active {
    color: var(--bg);
}

/* The sliding highlight behind the active button. Its width/height/top and a
   translateX transform are set inline by positionPillIndicator(); this only
   defines the look and the motion. */
.pill-indicator {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--accent);
    border-radius: 999px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 0;
}

/* ── Panel / Overlay / Modal ─────────────
   .panel: the bordered card surface. .overlay: full-viewport dim backdrop.
   .modal: a centered dialog box (a .panel with dialog padding/scroll). */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: overlayFade 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    max-height: 88vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-sizing: border-box;
    animation: modalReveal 0.22s ease;
}

/* ── Tag ─────────────────────────────────
   Tiny uppercase status label on a tile or panel header — a deck format,
   "Public", "Default", a share role. `.tag` is the frame (mono, 3px box,
   faint fill); a `.tag--<hue>` modifier paints it — text colour plus a
   10% / 20% wash of the same hue. Keep a prefixed class alongside only for
   a JS hook or a real per-element delta. */
.tag {
    display: inline-block;
    width: fit-content;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
}
.tag--accent  { color: var(--accent);  background: rgba(200, 169, 110, 0.1); border-color: rgba(200, 169, 110, 0.2); }
.tag--success { color: var(--success); background: rgba(59, 165, 93, 0.1);   border-color: rgba(59, 165, 93, 0.2); }
.tag--mint    { color: #7fd1a8;        background: rgba(127, 209, 168, 0.1); border-color: rgba(127, 209, 168, 0.2); }
.tag--gold    { color: #e3b565;        background: rgba(227, 181, 101, 0.1); border-color: rgba(227, 181, 101, 0.2); }
.tag--slate   { color: #9aa8c0;        background: rgba(154, 168, 192, 0.1); border-color: rgba(154, 168, 192, 0.2); }
