/* =================================================================
   admin-panels.css — Shared styles for Companies & Bakers admin pages
   ================================================================= */

/* ── Shell ── */
.ap-shell {
    min-height: 100vh;
    background: var(--color-bg);
    padding: var(--LR-padding);
}

.ap-content {
    max-width: 1100px;
    margin: 0 auto;
}

/* ── Page header ── */
.ap-header {
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

/* ── "View as" button (super-admin impersonation) ── */
.ap-viewas-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--color-brown, #412b23);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

.ap-viewas-btn:hover { filter: brightness(1.1); }

.ap-viewas-btn:disabled { opacity: 0.6; cursor: default; }

.ap-title {
    font-family: var(--font-serif);
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.ap-subtitle {
    margin: 0.4rem 0 0;
    color: var(--color-muted);
    font-size: 0.95rem;
}

/* ── Back link ── */
.ap-back {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-muted);
    text-decoration: none;
    margin-bottom: 1.75rem;
    padding: 0.35rem 0.75rem 0.35rem 0.5rem;
    border-radius: 0.5rem;
    background: transparent;
    border: 1.5px solid var(--color-border);
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.ap-back:hover {
    color: var(--color-text);
    border-color: var(--color-brown);
    background: var(--color-bg-light);
}

/* ── Card ── */
.ap-card {
    padding: 1.75rem;
    margin-bottom: 1.5rem;
}

/* ── Read-only notice (e.g. inspection-only settings panes) ── */
.ap-readonly-note {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0.65rem 1rem;
    background: var(--color-bg-light);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.ap-readonly-note svg {
    flex-shrink: 0;
}

/* ── Section header (title + count badge) ── */
.ap-section-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.ap-section-title {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0;
}

.ap-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.5rem;
    background: var(--color-peach);
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--color-darker-brown);
}

/* ── Meta fields grid ── */
.ap-meta-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
}

.ap-meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.ap-meta-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--color-muted);
}

.ap-meta-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
}

/* ── Status badges ── */
.ap-badge-active {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--color-mint);
    color: var(--color-olive);
    border-radius: 9999px;
    padding: 0.18rem 0.65rem;
}

.ap-badge-inactive {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--color-peach);
    color: var(--color-red);
    border-radius: 9999px;
    padding: 0.18rem 0.65rem;
}

/* ── Table ── */
.ap-tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ap-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.ap-tbl thead tr {
    border-bottom: 2px solid var(--color-border);
}

.ap-tbl thead th {
    text-align: left;
    padding: 1rem 1.125rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--color-muted);
    white-space: nowrap;
}

.ap-tbl tbody tr {
    border-bottom: 1px solid var(--color-bg-light);
    transition: background 0.12s;
}

.ap-tbl tbody tr:last-child {
    border-bottom: none;
}

.ap-tbl tbody tr.ap-clickable {
    cursor: pointer;
}

.ap-tbl tbody tr.ap-clickable:hover {
    background: var(--color-bg-light);
}

.ap-tbl td {
    padding: 0.9rem 1.125rem;
    vertical-align: middle;
}

.ap-td-name {
    font-weight: 600;
    color: var(--color-text);
}

.ap-td-link {
    color: var(--color-darker-brown);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.12s;
}

.ap-td-link:hover {
    color: var(--color-red);
    text-decoration: underline;
}

.ap-td-muted {
    color: var(--color-muted);
}

/* ── States ── */
.ap-loading {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--color-muted);
    font-size: 0.9rem;
}

.ap-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-muted);
    font-size: 0.9rem;
    border: 2px dashed var(--color-border);
    border-radius: 14px;
}

.ap-error {
    color: var(--color-red);
    font-size: 0.9rem;
    padding: 1rem 1.25rem;
    background: #fff5f5;
    border: 1.5px solid var(--color-peach);
    border-radius: 0.75rem;
}

/* ── Modal ── */
/* Lock background scrolling while a modal is open (toggled from JS).
   padding-right compensates for the removed scrollbar so nothing shifts. */
body.ap-modal-open {
    overflow: hidden;
    padding-right: var(--ap-scrollbar-pad, 0);
}

.ap-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(61, 40, 23, 0.42);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    overscroll-behavior: contain;
    animation: ap-modal-fade 0.18s ease-out;
}

.ap-modal {
    position: relative;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card, 16px);
    box-shadow: 0 24px 70px rgba(61, 40, 23, 0.28);
    padding: 1.75rem;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ap-modal-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Brand accent bar along the top edge */
.ap-modal::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--color-peach), var(--color-gold) 55%, var(--color-peach-dark));
    border-top-left-radius: var(--radius-card, 16px);
    border-top-right-radius: var(--radius-card, 16px);
}

.ap-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 0.9rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.ap-modal-title {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-brown-dark, var(--color-text));
    margin: 0;
}

.ap-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-pill, 9999px);
    color: var(--color-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.ap-modal-close:hover {
    background: var(--color-peach);
    color: var(--color-brown-dark, var(--color-text));
    transform: rotate(90deg);
}

.ap-modal-field {
    margin-bottom: 0.85rem;
}

/* Scrollable body so tall forms never overflow the viewport */
.ap-modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    /* keep scrolling inside the modal — don't chain to the page behind it */
    overscroll-behavior: contain;
    /* breathing room so focus rings / shadows aren't clipped while scrolling */
    margin: 0 -0.4rem;
    padding: 0.2rem 0.4rem;
}

.ap-modal-body > .ap-modal-field:last-child {
    margin-bottom: 0;
}

.ap-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

@keyframes ap-modal-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes ap-modal-pop {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Modal form controls ──
   Denser, on-brand inputs/selects/checkboxes scoped to modals. The global
   .form-input is sized for full-page forms (1rem 1.5rem); that's too airy here. */
.ap-modal .form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-muted);
    margin-bottom: 0.4rem;
}

.ap-modal .form-input {
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    border-radius: 10px;
    border-width: 1.5px;
    background: #fff;
}

.ap-modal .form-input:hover:not(:focus) {
    border-color: var(--color-peach-dark);
}

.ap-modal select.form-input {
    padding-right: 2.4rem;
    cursor: pointer;
    background-position: right 0.75rem center;
}

/* Checkboxes rendered as themed toggle chips */
.ap-check {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-muted);
    background: #fff;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-pill, 9999px);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.ap-check:hover {
    border-color: var(--color-peach-dark);
}

.ap-check:has(input:checked) {
    background: var(--color-peach);
    border-color: var(--color-peach-dark);
    color: var(--color-brown-dark, var(--color-text));
}

.ap-check input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    flex-shrink: 0;
    border: 1.5px solid var(--color-border);
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.ap-check input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 214, 201, 0.55);
}

.ap-check input[type="checkbox"]:checked {
    background-color: var(--color-brown, #a87865);
    border-color: var(--color-brown, #a87865);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 0.8rem;
}

/* ── Tabs ── */
.ap-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0;
}

.ap-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    border-radius: 0.375rem 0.375rem 0 0;
    transition: color 0.15s, border-color 0.15s;
}

.ap-tab:hover {
    color: var(--color-text);
}

.ap-tab--active {
    color: var(--color-darker-brown);
    border-bottom-color: var(--color-darker-brown);
}

/* ── Pagination ── */
.ap-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    /* Full padding (not just top) so the buttons clear the rounded bottom corners of an
       overflow:hidden card and aren't clipped. Acts as a proper footer bar. */
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--color-border);
}

.ap-pg-btn {
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-darker-brown);
    background: transparent;
    border: 1.5px solid var(--color-border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.ap-pg-btn:hover:not(:disabled) {
    background: var(--color-bg-light);
    border-color: var(--color-darker-brown);
}

.ap-pg-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.ap-pg-info {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-muted);
    min-width: 8rem;
    text-align: center;
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .ap-meta-grid {
        gap: 1.25rem;
    }
}
