/* ============================================================
   Permit Lister admin — components
   Buttons, inputs, selects, tables, badges, toggles, modals.
   CLAUDE.md rules enforced:
     - 52px form fields
     - Zero rounded corners
     - No icons in buttons
     - No visible <label> captions (placeholder + aria-label)
     - Native controls never ship (dark-themed checkbox / custom select)
   ============================================================ */

/* ============================================================
   BUTTONS
   ============================================================ */
.pl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    height: var(--field-height);
    min-width: 130px;
    padding: 0 var(--sp-5);
    background: var(--brand);
    color: var(--text-on-brand);
    border: 1px solid var(--brand);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: var(--weight-medium);
    line-height: 1;
    letter-spacing: 0.01em;
    white-space: nowrap;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
    text-decoration: none;
}

.pl-btn:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
    color: var(--text-on-brand);
}

.pl-btn:active {
    background: var(--brand-active);
    border-color: var(--brand-active);
}

.pl-btn:disabled,
.pl-btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Variants */
.pl-btn--secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}

.pl-btn--secondary:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-hover);
}

.pl-btn--ghost {
    background: transparent;
    color: var(--text-dim);
    border-color: transparent;
    min-width: 0;
}

.pl-btn--ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.pl-btn--danger {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--text-on-danger);
}

.pl-btn--danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.pl-btn--sm {
    height: 36px;
    min-width: 0;
    padding: 0 var(--sp-3);
    font-size: var(--font-size-xs);
}

.pl-btn--link {
    background: transparent;
    color: var(--text-link);
    border-color: transparent;
    min-width: 0;
    padding: 0 var(--sp-2);
    height: auto;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.pl-btn--link:hover {
    background: transparent;
    color: var(--text-link-hover);
}

/* ============================================================
   FORM FIELDS
   ============================================================ */
.pl-field {
    display: block;
    width: 100%;
}

.pl-input,
.pl-textarea,
select.pl-input {
    display: block;
    width: 100%;
    height: var(--field-height);
    padding: 0 var(--field-padding-x);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    font-family: inherit;
    font-size: var(--font-size-sm);
    line-height: 1;
    transition: border-color 120ms ease, background 120ms ease;
    appearance: none;
    -webkit-appearance: none;
}

.pl-input::placeholder,
.pl-textarea::placeholder {
    color: var(--text-faint);
}

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

.pl-input:focus-visible,
.pl-textarea:focus-visible {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 var(--focus-ring-width) var(--border-focus-ring);
}

.pl-textarea {
    min-height: var(--field-height);
    padding-top: 14px;
    padding-bottom: 14px;
    line-height: var(--line-normal);
    resize: vertical;
    field-sizing: content;
}

.pl-input[disabled],
.pl-textarea[disabled] {
    background: var(--surface-sunken);
    color: var(--text-mute);
    cursor: not-allowed;
}

/* Search field with inline icon */
.pl-search {
    position: relative;
    display: block;
}

.pl-search__icon {
    position: absolute;
    left: var(--sp-4);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-mute);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.pl-search__icon svg { width: 16px; height: 16px; }

.pl-search .pl-input {
    padding-left: 42px;
}

/* ============================================================
   CHECKBOX + RADIO — custom, never native-styled
   Light theme: white box, teal check.
   ============================================================ */
.pl-check,
.pl-radio {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--text);
    user-select: none;
}

.pl-check input,
.pl-radio input {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
    transition: background 120ms ease, border-color 120ms ease;
}

.pl-radio input { border-radius: 50%; }

.pl-check input:hover,
.pl-radio input:hover { border-color: var(--border-hover); }

.pl-check input:focus-visible,
.pl-radio input:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

.pl-check input:checked,
.pl-radio input:checked {
    background: var(--brand);
    border-color: var(--brand);
}

.pl-check input:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 6px;
    height: 11px;
    border: solid var(--text-on-brand);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.pl-radio input:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 4px;
    width: 8px;
    height: 8px;
    background: var(--text-on-brand);
    border-radius: 50%;
}

/* ============================================================
   TOGGLE (round pill)
   ============================================================ */
.pl-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--text);
    user-select: none;
}

.pl-toggle input {
    appearance: none;
    -webkit-appearance: none;
    width: 36px;
    height: 20px;
    background: var(--toggle-off-track);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    transition: background 120ms ease;
    margin: 0;
    flex-shrink: 0;
}

.pl-toggle input::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--surface-raised);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: transform 120ms ease;
}

.pl-toggle input:checked { background: var(--brand); }
.pl-toggle input:checked::after { transform: translateX(16px); }

.pl-toggle input:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

/* ============================================================
   TABLES
   Linear-style: no zebra, horizontal borders only, sticky header.
   ============================================================ */
.pl-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    overflow-x: auto;
}

.pl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.pl-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    text-align: left;
    font-weight: var(--weight-semibold);
    color: var(--text-dim);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
    z-index: 1;
}

.pl-table tbody td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.pl-table tbody tr:last-child td { border-bottom: none; }

.pl-table tbody tr:hover { background: var(--surface-hover); }

.pl-table tbody tr.is-selected { background: var(--brand-tint); }

.pl-table .pl-col-num {
    text-align: right;
}

.pl-table .pl-col-actions {
    text-align: right;
    white-space: nowrap;
    width: 1%;
}

.pl-table a { color: var(--text-link); font-weight: var(--weight-medium); }
.pl-table a:hover { color: var(--text-link-hover); }

/* Clickable row */
.pl-table tbody tr[data-href] { cursor: pointer; }

/* Empty state */
.pl-empty {
    padding: var(--sp-12) var(--sp-6);
    text-align: center;
    color: var(--text-dim);
    font-size: var(--font-size-sm);
}

.pl-empty__title {
    color: var(--text);
    font-size: var(--font-size-md);
    font-weight: var(--weight-semibold);
    margin-bottom: var(--sp-2);
}

/* ============================================================
   BADGES
   ============================================================ */
.pl-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.4;
    background: var(--badge-bg);
    color: var(--badge-text);
    white-space: nowrap;
}

.pl-badge--brand   { background: var(--brand-tint); color: var(--brand-ink); }
.pl-badge--success { background: var(--success-tint); color: var(--success-ink); }
.pl-badge--warn    { background: var(--warn-tint); color: var(--warn-ink); }
.pl-badge--danger  { background: var(--danger-tint); color: var(--danger-ink); }
.pl-badge--info    { background: var(--info-tint); color: var(--info-ink); }

/* ============================================================
   TOOLBAR + FILTERS
   ============================================================ */
.pl-toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
    flex-wrap: wrap;
}

.pl-toolbar__search {
    flex: 1;
    max-width: 420px;
    min-width: 240px;
}

.pl-toolbar__actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-left: auto;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pl-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: var(--sp-4) 0;
    font-size: var(--font-size-sm);
    color: var(--text-dim);
}

.pl-pager__info { font-variant-numeric: tabular-nums; }
.pl-pager__actions { display: flex; gap: var(--sp-2); }

/* ============================================================
   PANELS (sections inside pages)
   ============================================================ */
.pl-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: var(--sp-5);
    margin-bottom: var(--sp-4);
}

.pl-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
    padding-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border);
}

.pl-panel__title {
    font-size: var(--font-size-md);
    font-weight: var(--weight-semibold);
    color: var(--text-heading);
}

/* ============================================================
   BANNERS (inline alerts above content)
   ============================================================ */
.pl-banner {
    padding: var(--sp-3) var(--sp-4);
    margin-bottom: var(--sp-4);
    font-size: var(--font-size-sm);
    border-left: 3px solid var(--banner-neutral-border);
    background: var(--banner-neutral-bg);
    color: var(--text);
}

.pl-banner--success { border-left-color: var(--success); background: var(--success-tint); color: var(--success-ink); }
.pl-banner--warn    { border-left-color: var(--warn);    background: var(--warn-tint);    color: var(--warn-ink); }
.pl-banner--danger  { border-left-color: var(--danger);  background: var(--danger-tint);  color: var(--danger-ink); }
.pl-banner--info    { border-left-color: var(--info);    background: var(--info-tint);    color: var(--info-ink); }

/* ============================================================
   PL-SELECT (custom dropdown)
   ============================================================ */
.pl-select {
    position: relative;
    display: inline-block;
    min-width: 160px;
}

.pl-select__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    width: 100%;
    height: var(--field-height);
    padding: 0 var(--field-padding-x);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: var(--weight-regular);
    text-align: left;
    cursor: pointer;
    transition: border-color 120ms ease;
}

.pl-select__trigger:hover { border-color: var(--border-hover); }

.pl-select.is-open .pl-select__trigger,
.pl-select__trigger:focus-visible {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 var(--focus-ring-width) var(--border-focus-ring);
}

.pl-select__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pl-select__chevron {
    width: 10px;
    height: 10px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translateY(-2px) rotate(45deg);
    color: var(--text-mute);
    flex-shrink: 0;
    transition: transform 120ms ease;
}

.pl-select.is-open .pl-select__chevron {
    transform: translateY(2px) rotate(-135deg);
}

.pl-select__menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 294px; /* 7 rows × 42px */
    overflow-y: auto;
    background: var(--surface-raised);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-md);
    z-index: var(--z-dropdown);
    padding: 4px 0;
    list-style: none;
    display: none;
}

.pl-select.is-open .pl-select__menu { display: block; }

.pl-select__opt {
    padding: 10px var(--field-padding-x);
    font-size: var(--font-size-sm);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
}

.pl-select__opt:hover { background: var(--surface-hover); }

.pl-select__opt.is-active { background: var(--surface-active); }

.pl-select__opt.is-checked {
    color: var(--brand-ink);
    font-weight: var(--weight-medium);
}

.pl-select__opt.is-checked::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid var(--brand);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    flex-shrink: 0;
}

/* ============================================================
   PL-CONFIRM (modal)
   ============================================================ */
.pl-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--sp-5);
}

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

.pl-modal__backdrop {
    position: absolute;
    inset: 0;
    background: var(--overlay);
    backdrop-filter: blur(2px);
    z-index: var(--z-modal-backdrop);
}

.pl-modal__panel {
    position: relative;
    z-index: calc(var(--z-modal) + 1);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: var(--sp-6);
}

.pl-modal__title {
    font-size: var(--font-size-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-heading);
    margin-bottom: var(--sp-3);
    letter-spacing: -0.01em;
}

.pl-modal__message {
    color: var(--text-dim);
    font-size: var(--font-size-sm);
    line-height: var(--line-normal);
    margin-bottom: var(--sp-5);
}

.pl-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
}

/* ============================================================
   STAT ROW (counts under page header)
   ============================================================ */
.pl-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
}

.pl-stats__item {
    padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
    border: 1px solid var(--border);
}

.pl-stats__label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-mute);
    font-weight: var(--weight-semibold);
    margin-bottom: 2px;
}

.pl-stats__value {
    font-size: var(--font-size-xl);
    font-weight: var(--weight-semibold);
    color: var(--text-heading);
    line-height: var(--line-tight);
    font-variant-numeric: tabular-nums;
}
