/* ==========================================================================
   PatchWorld UI - Base layer (Worlds)
   --------------------------------------------------------------------------
   Reset, global typography and the 2-column application layout:
     [ fixed sidebar | scrollable main viewport ]

   Requires: css/tokens.css (must be loaded first).

   Class naming: generic layout pieces use the "pw-" prefix so the same
   shell can be reused by other LocalUI pages (Library, Community...).
   State classes use the "is-" prefix (is-active, is-loading...).
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* The HTML "hidden" attribute must always win over component display rules:
   the router toggles views with it. */
[hidden] {
    display: none !important;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden; /* Only .pw-content scrolls, the shell stays fixed */
    background-color: var(--color-bg-base);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--font-size-md);
    line-height: var(--line-height-base);
    -webkit-font-smoothing: antialiased;
}

img,
svg {
    display: block;
    max-width: 100%;
}

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

button {
    background: none;
    border: 0;
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Keyboard / VR-pointer focus ring (never on mouse click) */
:is(button, a, input, select, [tabindex]):focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

/* --------------------------------------------------------------------------
   2. Scrollbars (Chromium-based Vuplex + desktop browsers)
   Note: Do NOT declare standard scrollbar-width or scrollbar-color, as modern
   Chromium (121+) disables ::-webkit-scrollbar pseudo-elements when they are present.
   -------------------------------------------------------------------------- */
::-webkit-scrollbar,
.pw-content::-webkit-scrollbar {
    width: var(--space-6); /* 24px */
    height: var(--space-6);
}

::-webkit-scrollbar-track,
.pw-content::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb,
.pw-content::-webkit-scrollbar-thumb {
    background: var(--color-scrollbar);
    border-radius: var(--radius-lg);
}

::-webkit-scrollbar-thumb:hover,
.pw-content::-webkit-scrollbar-thumb:hover {
    background: var(--color-scrollbar-hover);
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* Hide scrollbars on horizontal rails (scrolled via < > buttons or touch swipe) */
.pw-rail {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.pw-rail::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* --------------------------------------------------------------------------
   3. Typography helpers
   -------------------------------------------------------------------------- */
h1,
h2,
h3,
h4 {
    font-family: var(--font-head);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-tight);
    letter-spacing: var(--letter-spacing-tight);
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }

.pw-text-muted {
    color: var(--color-text-muted);
}

/* Visually hidden but still announced by screen readers */
.pw-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   4. Application shell
   -------------------------------------------------------------------------- */
.pw-app {
    display: flex;
    width: 100%;
    height: 100%;
    background: transparent;
}

/* ---- 4.1 Sidebar ---- */
.pw-sidebar {
    flex: none;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-3);
    background: var(--color-sidebar-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-right: var(--border-width) solid var(--color-border);
    overflow-y: auto;
}

/* Optional overline label between nav groups (e.g. "Yours") */
.pw-sidebar__label {
    margin: var(--space-4) var(--space-3) var(--space-1);
    font-size: var(--font-size-2xs);
    font-weight: var(--font-weight-semibold);
    letter-spacing: var(--letter-spacing-wide);
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.pw-sidebar__label:first-child {
    margin-top: 0;
}

/* Visual gap that pushes following items apart from the main group */
.pw-sidebar__separator {
    height: var(--border-width);
    margin: var(--space-2) var(--space-3);
    background: var(--color-border);
}

.pw-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: var(--hit-min);
    padding: var(--space-2) var(--space-3);
    border: var(--border-width) solid transparent;
    border-radius: var(--radius-md);
    color: var(--color-text-idle);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-medium);
    text-align: left;
    transition: background-color var(--duration-fast), color var(--duration-fast);
}

.pw-nav-item:hover {
    color: var(--color-text-strong);
    background: var(--color-surface-hover);
}

.pw-nav-item.is-active {
    color: var(--color-text-strong);
    background: var(--color-surface-selected);
    border-color: var(--color-border-selected);
}

.pw-nav-item__icon {
    flex: none;
    width: var(--icon-md);
    height: var(--icon-md);
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.pw-nav-item__label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Trailing hint for items that leave the web page (open a native Unity UI) */
.pw-nav-item__ext {
    flex: none;
    width: var(--icon-sm);
    height: var(--icon-sm);
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.55;
}

/* ---- 4.2 Main viewport ---- */
.pw-content {
    position: relative;
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-5) var(--space-6) var(--space-6);
    background: var(--color-content-bg);
}

.pw-content__inner {
    max-width: var(--content-max);
    margin: 0 auto;
}

/* Banner area shared by every sub-view (demo notice...) */
.pw-content__banners:empty {
    display: none;
}

.pw-demo-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    background: var(--color-demo-bg);
    border: var(--border-width) solid var(--color-demo-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-5);
    color: var(--color-demo-text);
}

.pw-demo-banner__text {
    flex: 1;
    font-size: var(--font-size-md);
    line-height: var(--line-height-base);
}

.pw-demo-banner__text b {
    color: #fff;
    font-weight: var(--font-weight-bold);
}

.pw-demo-banner__cta {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-4);
    background: transparent;
    border: var(--border-width) solid var(--color-demo-border-strong);
    border-radius: var(--radius-md);
    color: var(--color-demo-accent);
    font-family: var(--font-head);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--duration-fast), border-color var(--duration-fast);
}

.pw-demo-banner__cta:hover {
    background: var(--color-demo-hover);
    border-color: var(--color-demo-accent);
}

@media (max-width: 700px) {
    .pw-demo-banner {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-3);
    }

    .pw-demo-banner__cta {
        width: 100%;
    }
}

/* ---- 4.3 Views (one per sidebar tab, toggled with [hidden]) ---- */
.pw-view {
    display: block;
}

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

.pw-view-header__left {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
}

.pw-view-header__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.pw-view-header__count {
    flex: none;
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
}

.pw-section {
    margin-top: var(--space-6);
}

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

/* Temporary placeholder shown while a view is not implemented yet.
   Remove once every view is wired (steps 3 to 6). */
.pw-placeholder {
    display: grid;
    place-items: center;
    min-height: 180px;
    padding: var(--space-8) var(--space-5);
    border: var(--border-width) dashed var(--color-border);
    border-radius: var(--radius-xl);
    color: var(--color-text-muted);
    font-size: var(--font-size-md);
    text-align: center;
}

/* ---- 4.4 Overlay root (modal popup lives here, see worlds-modal.css) ---- */
.pw-overlay-root {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    pointer-events: none;
}

.pw-overlay-root[hidden] {
    display: none !important;
}

/* --------------------------------------------------------------------------
   5. Responsive
   Breakpoints mirror the documentation in tokens.css.
   -------------------------------------------------------------------------- */

/* Compact desktop: slimmer sidebar */
@media (max-width: 860px) {
    .pw-app {
        --sidebar-width: 176px;
    }

    .pw-content {
        padding: var(--space-4) var(--space-4) var(--space-6);
    }
}

/* Mobile / narrow portal iframe: sidebar becomes a horizontal tab strip */
@media (max-width: 700px) {
    .pw-app {
        flex-direction: column;
    }

    .pw-sidebar {
        width: auto;
        flex-direction: row;
        gap: var(--space-1);
        padding: var(--space-2);
        border-right: 0;
        border-bottom: var(--border-width) solid var(--color-border);
        overflow-x: auto;
        overflow-y: hidden;
    }

    .pw-sidebar__label,
    .pw-sidebar__separator {
        display: none;
    }

    .pw-nav-item {
        width: auto;
        flex: none;
        white-space: nowrap;
    }
}
