/* ==========================================================================
   scottliu.com design suite - components.css
   Reusable UI components in the editorial / ghost aesthetic.
   Load AFTER tokens.css and base.css. Per-site overrides go in local app.css.
   See DESIGN.md for the "when to use each of these" guide.
   ========================================================================== */

/* ==========================================================================
   BUTTONS  - one visual language: outlined "ghost". No filled CTAs.
   Emphasis comes from placement/hierarchy, not color fill.
   .btn          default action (outlined accent)
   .btn-small    dense contexts (toolbars, table rows)
   .btn-large    primary page action by SIZE, still outlined
   .btn-danger   destructive action (delete/remove) - danger-colored outline
   .icon-btn     icon-only control (ghost, no border until hover)
   .toggle-btn   a button that represents on/off or selected state
                 (.is-active FILLS with accent - this is the ONE place fill is
                  used, to signal a persistent selected state, not a CTA)
   ========================================================================== */
.btn,
.toggle-btn {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.2;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.6em 1.2em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    transition: background var(--dur-fast) var(--ease),
        color var(--dur-fast) var(--ease),
        border-color var(--dur-fast) var(--ease),
        transform var(--dur-fast) var(--ease),
        box-shadow var(--dur-fast) var(--ease);
}

.btn:hover,
.toggle-btn:hover {
    background: var(--accent-weak);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
    text-decoration: none;
}

.btn:active,
.toggle-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn:focus-visible,
.toggle-btn:focus-visible,
.icon-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Selected/persistent-on state - the only filled button treatment. */
.toggle-btn.is-active {
    background: var(--accent);
    color: var(--paper-raised);
}

/* Size variants */
.btn-small {
    font-size: var(--text-sm);
    padding: 0.4em 0.9em;
}

.btn-large {
    font-size: var(--text-lg);
    padding: 0.75em 1.6em;
}

/* Destructive intent - same ghost shape, danger color. */
.btn-danger {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(156, 43, 43, 0.1);
}

/* Icon-only ghost button (borderless until hover). */
.icon-btn {
    font-family: var(--font-body);
    color: var(--ink-soft);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.4em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background var(--dur-fast) var(--ease),
        color var(--dur-fast) var(--ease);
}

.icon-btn:hover {
    background: var(--accent-weak);
    color: var(--accent);
}

/* Disabled applies to every button flavor. */
.btn:disabled,
.btn-small:disabled,
.btn-large:disabled,
.toggle-btn:disabled,
.icon-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* A group of related buttons/toggles. */
.btn-group {
    display: inline-flex;
    gap: var(--space-1);
    flex-wrap: wrap;
}

/* ==========================================================================
   FORMS & INPUTS
   .form / .field / .field-label / .field-hint / .form-status
   .text-input   applies to <input>, <textarea>, <select>
   .text-input.is-invalid   validation error state
   ========================================================================== */
.form {
    display: grid;
    gap: var(--space-2);
    max-width: 520px;
}

.field {
    display: grid;
    gap: 0.3em;
}

.field-label {
    font-family: var(--font-head);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
}

.field-hint {
    font-size: var(--text-sm);
    color: var(--ink-soft);
}

.text-input {
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--ink);
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 0.55em 0.7em;
    width: 100%;
}

.text-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.text-input.is-invalid {
    border-color: var(--danger);
}

.text-input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Code/monospace input (composer, snippet editors). */
textarea.text-input {
    resize: vertical;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

/* Inline label + checkbox/radio row. */
.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.5em;
}

.form-status {
    min-height: 1.4em;
    color: var(--ink-soft);
}

/* ==========================================================================
   SURFACES: tile vs panel
   .tile    INTERACTIVE card - lifts on hover, use for clickable items/links
   .panel   STATIC container - grouping/section, no hover motion
   .tile-grid   responsive auto-fill grid for either
   ========================================================================== */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-2);
}

.tile {
    display: block;
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: var(--space-3);
    box-shadow: var(--shadow-soft);
    color: var(--ink);
    transition: transform var(--dur-fast) var(--ease),
        border-color var(--dur-fast) var(--ease);
}

.tile:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    text-decoration: none;
}

.tile h3 {
    margin: 0 0 var(--space-1);
    font-size: var(--text-xl);
}

.panel {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: var(--space-3);
    box-shadow: var(--shadow-soft);
}

.panel-sunken {
    background: var(--paper-sunken);
    box-shadow: none;
}

/* ==========================================================================
   ROWS  - horizontal list items (history lists, catalogs, settings rows)
   .row        flex space-between (label left, actions right)
   .row-grid   grid "1fr auto auto" for aligned columns
   .is-active  selected row
   ========================================================================== */
.row,
.row-grid {
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: var(--space-2);
    color: var(--ink);
}

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.row-grid {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: var(--space-2);
}

.row:hover,
.row-grid:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.row.is-active,
.row-grid.is-active {
    border-color: var(--accent);
    background: var(--accent-weak);
}

.row-actions {
    display: flex;
    gap: var(--space-1);
}

/* ==========================================================================
   DATA TABLE  - dense tabular data (dashboards, admin lists)
   .data-table  + optional .is-zebra for striped rows
   th.sortable  + .asc / .desc for click-to-sort headers
   ========================================================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-md);
}

.data-table th,
.data-table td {
    border: 1px solid var(--hairline);
    padding: 0.5em 0.7em;
    text-align: left;
}

.data-table th {
    background: var(--paper-sunken);
    font-family: var(--font-head);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
}

.data-table tbody tr:hover {
    background: var(--accent-weak);
}

.data-table.is-zebra tbody tr:nth-child(even) {
    background: var(--paper-sunken);
}

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable::after {
    content: "";
    opacity: 0.4;
    margin-left: 0.4em;
}

th.sortable.asc::after { content: "\25B2"; opacity: 1; } /* up arrow */
th.sortable.desc::after { content: "\25BC"; opacity: 1; } /* down arrow */

/* ==========================================================================
   BADGES, STATUS PILLS & CHIPS
   .badge    quiet metadata label (hairline pill)
   .status   colored state pill; pair with .is-* state modifier
   .chip     removable/addable token (filters, tags, builder)
   ========================================================================== */
.badge {
    display: inline-block;
    font-family: var(--font-head);
    font-size: var(--text-2xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.2em 0.55em;
    border-radius: var(--radius-pill);
    border: 1px solid var(--hairline);
    color: var(--ink-soft);
}

/* Status pill - map any domain state onto one of five semantics.
   success = done/loaded/running/healthy
   warning = pending/loading/paused/degraded
   error   = failed/crashed/unavailable
   info    = active/in-progress (neutral-positive)
   neutral = idle/cancelled/unknown */
.status {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    font-family: var(--font-head);
    font-size: var(--text-2xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.25em 0.7em;
    border-radius: var(--radius-pill);
    border: 1px solid var(--hairline);
    color: var(--ink-soft);
    background: var(--paper-sunken);
}

.status.is-success { color: var(--success); border-color: var(--success); background: rgba(47, 125, 79, 0.1); }
.status.is-warning { color: var(--warn); border-color: var(--warn); background: rgba(156, 107, 43, 0.1); }
.status.is-error   { color: var(--danger); border-color: var(--danger); background: rgba(156, 43, 43, 0.1); }
.status.is-info    { color: var(--accent); border-color: var(--accent); background: var(--accent-weak); }
.status.is-neutral { color: var(--ink-soft); border-color: var(--hairline); background: var(--paper-sunken); }

/* Optional leading dot for status. */
.status::before {
    content: "";
    width: 0.5em;
    height: 0.5em;
    border-radius: 50%;
    background: currentColor;
}

.status.no-dot::before { display: none; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    background: var(--accent-weak);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.15em 0.5em;
    margin: 0 0.25em;
    font-size: var(--text-md);
}

.chip-remove,
.chip-add {
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: var(--text-base);
}

.chip-add {
    border: 1px dashed var(--hairline);
    border-radius: var(--radius);
    padding: 0.15em 0.6em;
}

/* ==========================================================================
   POPOVERS / MENUS / DROPDOWNS
   .popover        floating panel (autocomplete, pickers)
   .menu-dropdown  action menu (the 3-dot options menu)
   .menu-item / .popover-item   rows inside them
   ========================================================================== */
.popover,
.menu-dropdown {
    position: absolute;
    z-index: var(--z-dropdown);
    margin-top: 0.4em;
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    padding: 0.3em;
    min-width: 160px;
    max-height: 280px;
    overflow: auto;
}

.popover-item,
.menu-item {
    display: flex;
    align-items: center;
    gap: 0.5em;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 0.45em 0.6em;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: var(--text-md);
    color: var(--ink);
}

.popover-item:hover,
.menu-item:hover {
    background: var(--accent-weak);
}

.menu-item.is-danger {
    color: var(--danger);
}

.popover-item[aria-disabled="true"],
.menu-item[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ==========================================================================
   MODAL / DIALOG  - one canonical overlay + centered card
   .modal-overlay > .modal > (.modal-header, body, .modal-actions)
   Toggle visibility with the .is-open class (display:flex).
   ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-3);
    background: rgba(31, 28, 24, 0.5);
    animation: fade-in var(--dur-fast) var(--ease) both;
}

.modal-overlay.is-open {
    display: flex;
}

.modal {
    position: relative;
    z-index: var(--z-modal);
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow: auto;
    background: var(--paper-raised);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    padding: var(--space-4);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--ink-soft);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--ink);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================================================
   TOAST  - transient bottom-center notification
   .toast + .is-visible to show; .is-error / .is-success for intent
   ========================================================================== */
.toast {
    position: fixed;
    left: 50%;
    bottom: var(--space-3);
    transform: translate(-50%, 1rem);
    z-index: var(--z-toast);
    background: var(--ink);
    color: var(--paper-raised);
    font-family: var(--font-head);
    font-size: var(--text-sm);
    padding: 0.7em 1.2em;
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease),
        transform var(--dur-base) var(--ease);
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.toast.is-error { background: var(--danger); }
.toast.is-success { background: var(--success); }

/* ==========================================================================
   PROGRESS BAR
   .progress (track) > .progress-bar (fill); .is-warning / .is-danger
   ========================================================================== */
.progress {
    width: 100%;
    height: 10px;
    background: var(--paper-sunken);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: inherit;
    transition: width var(--dur-base) var(--ease);
}

.progress-bar.is-warning { background: var(--warn); }
.progress-bar.is-danger { background: var(--danger); }

/* ==========================================================================
   SPINNER  - indeterminate loading
   .spinner (inline) / wrap in .spinner-overlay to cover a region
   ========================================================================== */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--hairline);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(250, 247, 241, 0.6);
    z-index: var(--z-overlay);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   SWITCH  - boolean on/off toggle (settings). For selecting among options
   use .toggle-btn instead.
   Markup: <label class="switch"><input type="checkbox"><span></span></label>
   ========================================================================== */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch span {
    position: absolute;
    inset: 0;
    background: var(--hairline);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease);
}

.switch span::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background: var(--paper-raised);
    border-radius: 50%;
    transition: transform var(--dur-fast) var(--ease);
}

.switch input:checked + span {
    background: var(--accent);
}

.switch input:checked + span::before {
    transform: translateX(20px);
}

/* ==========================================================================
   ALERTS / INLINE MESSAGES  - persistent, in-flow feedback (not transient)
   .alert + .is-error / .is-success / .is-warning / .is-info
   ========================================================================== */
.alert {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    background: var(--paper-sunken);
    color: var(--ink);
}

.alert.is-error   { border-color: var(--danger); background: rgba(156, 43, 43, 0.06); }
.alert.is-success { border-color: var(--success); background: rgba(47, 125, 79, 0.08); }
.alert.is-warning { border-color: var(--warn); background: rgba(156, 107, 43, 0.08); }
.alert.is-info    { border-color: var(--accent); background: var(--accent-weak); }

/* Legacy shorthand kept for the editorial trio; prefer .alert.is-error. */
.error {
    padding: var(--space-3);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    background: rgba(156, 43, 43, 0.06);
}

/* ==========================================================================
   EMPTY STATE  - centered "nothing here yet" / greeting block
   ========================================================================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--space-2);
    padding: var(--space-5) var(--space-3);
    color: var(--ink-soft);
}
