/*
 * Shared layout and keyboard-accessibility repair layer.
 *
 * This file intentionally keeps the existing component palette, typography,
 * and geometry. It only supplies stable shared tokens, non-shifting focus
 * indicators, neutral resets for semantic controls, and narrow overflow fixes.
 */

:root {
    --ui-control-height: 38px;
    --ui-control-radius: var(--radius-lg, 12px);
    --ui-header-height: 70px;
    --ui-container-max: 1440px;
    --ui-focus-color: var(--orange, var(--gold, #ff6600));
}

.webkeys-wordmark {
    display: inline-flex;
    align-items: baseline;
    color: #09090b;
    font-family: var(--font-display, "Outfit", sans-serif);
    font-size: 1.15rem;
    font-weight: 900;
    letter-spacing: -0.04em;
    line-height: 1;
    white-space: nowrap;
}

.webkeys-wordmark-keys {
    color: var(--orange, #ff6600);
}

:root:not(.light-theme) .webkeys-wordmark {
    color: #ffffff;
}

html,
body {
    max-width: 100%;
}

html {
    overflow-x: clip;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a,
input,
select,
textarea {
    min-width: 0;
}

img,
video,
canvas {
    max-width: 100%;
}

/* Outline does not take up layout space, so focused controls never shift. */
:where(a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [role="button"], [tabindex]:not([tabindex="-1"])):focus-visible {
    outline: 2px solid var(--ui-focus-color) !important;
    outline-offset: 2px;
}

/* Search inputs already expose focus on their shared outer container. */
.search-container input:focus-visible {
    outline: none !important;
}

/* Preserve existing component visuals after replacing clickable divs. */
button:is(.logo-mark, .widget-status-item, .calendar-day-card, .calendar-day-cell, .calendar-day-block, .property-card, .door-item, .status-pill, .sidebar-policy-item, .sidebar-prop-card, .preset-link, .group-select-action, .group-meta) {
    -webkit-appearance: none;
    appearance: none;
    color: inherit;
    font: inherit;
}

button.logo-mark {
    background: transparent;
    border: 0;
    text-align: left;
}

button.widget-status-item {
    width: 100%;
    text-align: center;
}

button:is(.property-card, .door-item) {
    width: 100%;
    text-align: left;
}

button:is(.status-pill, .preset-link) {
    border: 0;
}

button.preset-link {
    background: transparent;
}

button:is(.sidebar-policy-item, .sidebar-prop-card) {
    width: 100%;
    text-align: left;
}

/* Header sign-out is intentionally distinct from the many compact controls
 * that historically shared .logout-btn. Its layout cannot collapse when a
 * page or theme adds a narrower button rule. */
.portal-signout {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    min-height: var(--ui-control-height) !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    margin: 0 !important;
    padding: 0 16px !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--ui-control-radius) !important;
    background: transparent !important;
    color: var(--text-main, #fff) !important;
    font-size: 0.72rem !important;
    font-weight: 800 !important;
    letter-spacing: 0.08em !important;
    line-height: 1 !important;
    white-space: nowrap !important;
}

.portal-signout:hover {
    border-color: var(--orange, #ff6600) !important;
    background: rgba(255, 102, 0, 0.08) !important;
    color: var(--orange, #ff6600) !important;
}

.portal-signout:disabled {
    opacity: 0.6;
    cursor: wait;
}

@media (max-width: 520px) {
    .portal-signout {
        min-height: 36px !important;
        padding-inline: 12px !important;
        font-size: 0.66rem !important;
    }
}

/* Public key cards use two sibling buttons to avoid nested controls. */
.door-open-action {
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.door-btn:focus-within,
.door-btn:focus-visible {
    outline: 2px solid var(--ui-focus-color);
    outline-offset: 2px;
}

.door-btn .door-open-action:focus-visible,
.door-btn .fav-btn:focus-visible {
    outline-offset: 1px;
}

.fav-btn {
    color: color-mix(in srgb, var(--text-primary, var(--text-main, #111)) 58%, transparent) !important;
}

.fav-btn:hover,
.fav-btn.active {
    color: var(--brand-color, var(--orange, #ff6600)) !important;
}

.fav-btn svg {
    width: 17px;
    height: 17px;
    stroke-width: 2.25;
}

.door-section {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.door-section + .door-section {
    margin-top: 8px;
}

.door-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 4px;
    color: var(--text-secondary, var(--text-dim));
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.door-section-count {
    min-width: 24px;
    padding: 3px 7px;
    border: 1px solid currentColor;
    border-radius: 999px;
    text-align: center;
    opacity: 0.72;
}

.door-section-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.key-is-paused .door-open-action {
    cursor: not-allowed;
    opacity: 0.58;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) .form-cell-group {
    margin: 0 !important;
    padding: 14px 16px !important;
    border-radius: 14px !important;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) .form-input-raw {
    min-height: 30px;
    padding-top: 5px !important;
    line-height: 1.35;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) .doors-header-bar {
    margin-top: 4px;
    margin-bottom: -4px;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) .search-container {
    margin-bottom: 0 !important;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) .doors-selection-grid {
    margin-top: 0 !important;
    border-radius: 16px !important;
}

:is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) > .btn-primary {
    min-height: 48px;
    margin-top: 4px !important;
}

.notification-item {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.notification-item:hover {
    border-color: var(--orange, #ff6600);
    background: rgba(255, 102, 0, 0.045);
    transform: translateY(-1px);
}

.patch-note-detail {
    max-width: min(560px, calc(100vw - 32px)) !important;
}

.patch-note-detail-message {
    margin: 18px 0 0;
    color: var(--text-dim);
    font-size: 0.88rem;
    line-height: 1.7;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.admin-patch-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.018);
    overflow: hidden;
}

.admin-patch-card summary {
    padding: 14px 16px;
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
}

.admin-patch-card-body {
    padding: 0 16px 16px;
    color: var(--text-dim);
    font-size: 0.78rem;
    line-height: 1.65;
    white-space: pre-wrap;
}

/* Shared flex/grid children may shrink instead of pushing the page sideways. */
.top-header > *,
.header-actions-group,
.dashboard-layout-wrapper,
.dashboard-main-content,
.content-card,
.modal-box,
.custom-confirm-box,
.widget-status-grid,
.key-card-info {
    min-width: 0;
}

.modal-overlay {
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal-box,
.custom-confirm-box {
    max-width: min(100%, 440px);
}

.settings-dropdown-menu {
    max-width: calc(100vw - 24px);
}

.phone-input-group {
    display: grid;
    grid-template-columns: minmax(145px, 0.85fr) minmax(0, 1.15fr);
    gap: 10px;
    align-items: stretch;
}

.phone-input-group .form-input {
    margin: 0 !important;
    min-width: 0;
}

.phone-code-select {
    text-overflow: ellipsis;
}

.field-help {
    margin: 7px 0 0;
    color: var(--text-muted, var(--text-dim));
    font-size: 0.72rem;
    line-height: 1.45;
}

.admin-view-only-banner {
    position: fixed;
    z-index: 99990;
    right: 20px;
    bottom: 94px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    width: min(520px, calc(100vw - 40px));
    padding: 11px 12px;
    border: 1px solid rgba(255, 102, 0, 0.42);
    border-radius: 16px;
    background: color-mix(in srgb, var(--bg, #0b0b0c) 91%, transparent);
    color: var(--text-main, #fff);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.admin-view-only-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 11px;
    color: var(--orange, #ff6600);
    background: rgba(255, 102, 0, 0.1);
}

.admin-view-only-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    font-size: 0.74rem;
}

.admin-view-only-copy strong {
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}

.admin-view-only-copy span {
    overflow: hidden;
    color: var(--text-dim);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-view-only-exit {
    min-height: 36px;
    padding: 0 13px;
    border: 1px solid rgba(255, 102, 0, 0.5);
    border-radius: 11px;
    background: var(--orange, #ff6600);
    color: #090909;
    font-size: 0.69rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}

@media (max-width: 640px) {
    .modal-overlay {
        padding: var(--space-md, 16px) !important;
    }

    .modal-box,
    .custom-confirm-box {
        max-height: calc(100dvh - 32px);
    }

    .calendar-days-select-grid {
        gap: min(10px, 2vw) !important;
    }

    button.calendar-day-block {
        min-width: 0;
    }

    .custom-confirm-actions > *,
    .modal-actions > * {
        min-width: 0;
    }

    #toastContainer {
        right: 12px;
        left: 12px;
        align-items: stretch;
    }

    .toast {
        max-width: 100%;
    }

    :is(#issueKeyForm, #issueStaffKeyForm, #issueCompanyKeyForm) > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
        margin-bottom: 0 !important;
    }

    .phone-input-group {
        grid-template-columns: 1fr;
    }

    .admin-view-only-banner {
        right: 12px;
        bottom: 82px;
        width: calc(100vw - 24px);
        grid-template-columns: auto minmax(0, 1fr);
    }

    .admin-view-only-exit {
        grid-column: 1 / -1;
        width: 100%;
    }
}
