/*
 * WargearWeek shared design tokens and components.
 *
 * Page templates must not define colours. They may define layout only.
 * Everything visual lives here so light/dark stays consistent across features.
 */

:root {
    /* Surfaces */
    --bg-main: #ebebeb;
    --bg-sidebar: #ffffff;
    --surface: #ffffff;
    --surface-2: #f6f8fa;
    --surface-hover: #eef1f4;

    /* Text */
    --text-primary: #212529;
    --text-muted: #6c757d;

    /* Lines */
    --border-color: #dee2e6;
    --border-strong: #c6ccd2;

    /* Accents */
    --accent: #0d6efd;
    --accent-soft: #e7f1ff;
    --accent-contrast: #ffffff;
    --success: #198754;
    --danger: #dc3545;
    --warn: #f0ad4e;

    /* Legacy aliases kept so existing wiki rules keep working */
    --code-bg: #f6f8fa;
    --nav-hover-bg: #e0e0e0;
    --table-header-bg: #f6f8fa;
    --link-color: #0d6efd;

    /* Shape */
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 14px rgba(0, 0, 0, .05);
    --shadow-lift: 0 4px 8px rgba(0, 0, 0, .08), 0 12px 28px rgba(0, 0, 0, .10);

    /* Rhythm */
    --navbar-height: 56px; /* Bootstrap's default navbar height; sticky offsets key off it */
    --gap: 1rem;
    --gap-sm: .5rem;
    --gap-lg: 1.5rem;
}

html.dark-mode {
    --bg-main: #1e1e1e;
    --bg-sidebar: #252526;
    --surface: #252526;
    --surface-2: #2d2d30;
    --surface-hover: #32323a;

    --text-primary: #d4d4d4;
    --text-muted: #9d9d9d;

    --border-color: #3e3e42;
    --border-strong: #55555b;

    --accent: #6ea8fe;
    --accent-soft: #1d2d44;
    --accent-contrast: #10151f;
    --success: #4caf50;
    --danger: #f16b7a;
    --warn: #e0a458;

    --code-bg: #2d2d30;
    --nav-hover-bg: #2a2d2e;
    --table-header-bg: #2d2d30;
    --link-color: #6ea8fe;

    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 4px 14px rgba(0, 0, 0, .35);
    --shadow-lift: 0 4px 8px rgba(0, 0, 0, .55), 0 12px 28px rgba(0, 0, 0, .45);
}

/* ---- Base ---------------------------------------------------------- */

/*
 * The wg-* components size with padding, so they need border-box. Bootstrap's
 * reboot sets it too, but not depending on that keeps the layout intact if
 * Bootstrap is slow, blocked, or ever swapped out.
 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a {
    color: var(--link-color);
}

/*
 * The navbar stays put. Sticky sidebars below it are offset by its height, so
 * if it scrolled away they would pin against a strip of bare page background.
 */
.wg-navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
}

/* Sidebar content that pins inside the wiki must clear the navbar too. */
.wiki-sidebar .sticky-top {
    top: var(--navbar-height);
}

/* ---- Explorer shell ------------------------------------------------ */

/*
 * The explorer is an app frame, not a document: the page itself never scrolls,
 * and each pane owns its own scrollbar the way a file manager does. Below the
 * tablet breakpoint that inverts - panes stack and the page scrolls normally,
 * because nested scroll regions on a phone are miserable.
 */
.wg-explorer-page {
    overflow: hidden;
}

.wg-explorer {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--navbar-height));
    background-color: var(--bg-main);
}

.wg-explorer-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-sm);
    align-items: center;
    flex: 0 0 auto;
    padding: var(--gap-sm) var(--gap);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border-color);
}

.wg-nav-buttons {
    display: flex;
    gap: .25rem;
}

.wg-address {
    flex: 1 1 260px;
    min-width: 0;
    padding: .3rem .6rem;
    overflow-x: auto;
    background-color: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.wg-toolbar-actions {
    display: flex;
    gap: .35rem;
}

.wg-explorer-toolbar .wg-search {
    flex: 0 1 240px;
}

.wg-explorer-body {
    display: flex;
    flex: 1 1 auto;
    min-height: 0; /* lets the panes, not the frame, do the scrolling */
}

.wg-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.wg-pane-tree {
    flex: 0 0 auto;
    width: 260px;
    background-color: var(--bg-sidebar);
}

.wg-pane-list {
    position: relative;
    flex: 1 1 auto;
    background-color: var(--surface);
}

.wg-pane-head {
    flex: 0 0 auto;
    padding: .45rem var(--gap-sm);
    background-color: var(--surface-2);
    border-bottom: 1px solid var(--border-color);
}

.wg-pane-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    outline: none;
}

/* The drag handle between the panes */
.wg-splitter {
    flex: 0 0 5px;
    cursor: col-resize;
    background-color: var(--border-color);
}

.wg-splitter:hover,
.wg-splitter:focus-visible {
    background-color: var(--accent);
    outline: none;
}

body.wg-resizing {
    cursor: col-resize;
    user-select: none;
}

.wg-statusbar {
    display: flex;
    flex: 0 0 auto;
    gap: var(--gap);
    padding: .3rem var(--gap);
    font-size: .8rem;
    color: var(--text-muted);
    background-color: var(--surface-2);
    border-top: 1px solid var(--border-color);
}

@media (max-width: 767.98px) {
    .wg-explorer-page {
        overflow: auto;
    }

    .wg-explorer {
        height: auto;
    }

    .wg-explorer-body {
        flex-direction: column;
    }

    .wg-pane-tree {
        width: auto !important;
        max-height: 40vh;
        border-bottom: 1px solid var(--border-color);
    }

    .wg-splitter {
        display: none;
    }
}

.wg-section-title {
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: var(--gap-sm);
}

/* ---- Card ---------------------------------------------------------- */

.wg-card {
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.wg-card-header {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-sm);
    align-items: center;
    justify-content: space-between;
    padding: var(--gap) var(--gap-lg);
    border-bottom: 1px solid var(--border-color);
}

.wg-card-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 600;
}

.wg-card-body {
    padding: var(--gap-lg);
}

.wg-card-body--flush {
    padding: 0;
}

/* ---- Toolbar ------------------------------------------------------- */

.wg-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-sm);
    align-items: center;
    padding: var(--gap-sm) var(--gap-lg);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--surface-2);
}

.wg-toolbar .wg-search {
    flex: 1 1 220px;
    min-width: 0;
}

.wg-search input {
    width: 100%;
    padding: .375rem .75rem .375rem 2rem;
    color: var(--text-primary);
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.wg-search {
    position: relative;
}

.wg-search .wg-search-icon {
    position: absolute;
    top: 50%;
    left: .65rem;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.wg-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---- Breadcrumb ---------------------------------------------------- */

.wg-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: .9rem;
}

.wg-crumbs li::after {
    content: "/";
    margin-left: .35rem;
    color: var(--text-muted);
}

.wg-crumbs li:last-child::after {
    content: none;
}

.wg-crumbs a {
    color: var(--text-muted);
    text-decoration: none;
}

.wg-crumbs a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.wg-crumbs li[aria-current="page"] {
    color: var(--text-primary);
    font-weight: 600;
}

/* ---- Folder tree --------------------------------------------------- */

.wg-tree,
.wg-tree ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.wg-tree-row {
    display: flex;
    gap: .35rem;
    align-items: center;
    padding: .2rem .4rem;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.wg-tree-row:hover {
    background-color: var(--nav-hover-bg);
}

.wg-tree-row.is-active {
    background-color: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* Fixed width so labels align whether or not a folder has a twisty */
.wg-twisty {
    flex: 0 0 14px;
    font-size: .7rem;
    text-align: center;
    color: var(--text-muted);
}

.wg-twisty i:hover {
    color: var(--text-primary);
}

.wg-tree-icon {
    flex: 0 0 auto;
}

.wg-tree-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Rows (list of nodes) ------------------------------------------ */

.wg-list {
    display: flex;
    flex-direction: column;
}

.wg-row {
    display: flex;
    gap: var(--gap);
    align-items: center;
    width: 100%;
    padding: .65rem var(--gap-lg);
    border: 0;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    text-decoration: none;
}

.wg-row:last-child {
    border-bottom: 0;
}

.wg-row:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
}

.wg-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.wg-row-icon {
    flex: 0 0 2rem;
    font-size: 1.15rem;
    text-align: center;
}

.wg-row-main {
    flex: 1 1 auto;
    min-width: 0;
}

.wg-row-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.wg-row-meta {
    display: block;
    font-size: .8rem;
    color: var(--text-muted);
}

.wg-row-actions {
    flex: 0 0 auto;
    display: flex;
    gap: .35rem;
}

.wg-icon-folder {
    color: var(--warn);
}

.wg-icon-file {
    color: var(--success);
}

/* ---- Empty state --------------------------------------------------- */

.wg-empty {
    padding: 3rem var(--gap-lg);
    text-align: center;
    color: var(--text-muted);
}

.wg-empty i {
    display: block;
    margin-bottom: var(--gap-sm);
    font-size: 2rem;
    opacity: .5;
}

/* ---- Drop zone ----------------------------------------------------- */

.wg-dropzone {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    background-color: var(--surface-2);
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}

.wg-dropzone:hover,
.wg-dropzone.is-dragover {
    border-color: var(--accent);
    background-color: var(--accent-soft);
}

.wg-dropzone.has-file {
    border-color: var(--success);
    border-style: solid;
}

.wg-drop-target {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
    background-color: var(--accent-soft) !important;
}

/* ---- Directory listing --------------------------------------------- */

.wg-entries {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* Shared column geometry keeps the header aligned with the rows */
.wg-list-head,
.wg-entry {
    display: flex;
    gap: var(--gap-sm);
    align-items: center;
}

.wg-list-head {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.wg-col-icon {
    flex: 0 0 1.6rem;
    text-align: center;
}

.wg-col-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wg-col-type {
    flex: 0 0 9rem;
    color: var(--text-muted);
    font-size: .85rem;
}

.wg-entry {
    padding: .3rem var(--gap-sm);
    cursor: default;
    user-select: none;
}

.wg-entry:hover {
    background-color: var(--surface-hover);
}

.wg-entry.is-selected {
    background-color: var(--accent-soft);
    color: var(--accent);
}

.wg-entry.is-dragging {
    opacity: .45;
}

.wg-rename-input {
    width: 100%;
    padding: 0 .25rem;
    font: inherit;
    color: var(--text-primary);
    background-color: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 2px;
}

.wg-rename-input:focus {
    outline: none;
}

@media (max-width: 575.98px) {
    .wg-col-type {
        display: none;
    }
}

/* ---- Marquee (box) selection --------------------------------------- */

/* The scroll pane is the positioning context, so the box scrolls with the rows */
.wg-pane-scroll {
    position: relative;
}

.wg-marquee {
    position: absolute;
    z-index: 5;
    background-color: var(--accent-soft);
    border: 1px solid var(--accent);
    opacity: .55;
    pointer-events: none;
}

body.wg-selecting {
    user-select: none;
    cursor: crosshair;
}

/* ---- Details pane -------------------------------------------------- */

/*
 * Occupies the listing pane rather than the whole page, so the tree and the
 * address bar stay where they were.
 */
.wg-details-head {
    display: flex;
    gap: var(--gap);
    align-items: center;
    padding: var(--gap-sm) var(--gap);
    border-bottom: 1px solid var(--border-color);
}

.wg-details-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* Pushed to the trailing edge so a long title never crowds the action */
.wg-details-download {
    margin-left: auto;
    flex: 0 0 auto;
    white-space: nowrap;
}

.wg-details-body {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gap-lg);
    padding: var(--gap-lg);
}

.wg-details-preview {
    display: flex;
    flex: 0 0 220px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 220px;
    overflow: hidden;
    color: var(--text-muted);
    background-color: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}

.wg-details-preview-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.wg-details-facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .4rem var(--gap);
    flex: 1 1 260px;
    margin: 0;
    align-content: start;
}

.wg-details-facts dt {
    color: var(--text-muted);
    font-weight: 500;
}

.wg-details-facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}

/* ---- Upload veil over the listing ---------------------------------- */

.wg-dropveil {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--accent);
    background-color: var(--accent-soft);
    border: 2px dashed var(--accent);
    pointer-events: none;
}

.wg-dropveil.is-visible {
    display: flex;
}

/* ---- Context menu -------------------------------------------------- */

.wg-contextmenu {
    position: fixed;
    z-index: 1080;
    min-width: 12rem;
    margin: 0;
    padding: .25rem;
    list-style: none;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lift);
}

.wg-contextmenu li {
    display: flex;
    align-items: center;
    padding: .35rem .6rem;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
}

.wg-contextmenu li:hover {
    background-color: var(--accent-soft);
    color: var(--accent);
}

.wg-contextmenu li.is-disabled {
    color: var(--text-muted);
    opacity: .55;
    cursor: default;
}

.wg-contextmenu li.is-disabled:hover {
    background-color: transparent;
    color: var(--text-muted);
}

.wg-contextmenu hr {
    margin: .25rem .3rem;
    border-color: var(--border-color);
}

.wg-menu-shortcut {
    margin-left: auto;
    padding-left: var(--gap);
    font-size: .78rem;
    color: var(--text-muted);
}

/* ---- Toasts -------------------------------------------------------- */

.wg-toasts {
    position: fixed;
    right: var(--gap);
    bottom: var(--gap);
    z-index: 1090;
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    max-width: min(26rem, calc(100vw - 2 * var(--gap)));
}

.wg-toast {
    padding: .6rem .9rem;
    color: var(--text-primary);
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--success);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lift);
    transition: opacity .35s ease, transform .35s ease;
}

.wg-toast.is-error {
    border-left-color: var(--danger);
}

.wg-toast.is-leaving {
    opacity: 0;
    transform: translateY(.5rem);
}

/* ---- Centred single-message pages ---------------------------------- */

.wg-centre {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--navbar-height));
    padding: var(--gap-lg);
}

.wg-centre .wg-card {
    max-width: 32rem;
    padding: var(--gap-lg);
    text-align: center;
}

.wg-status-icon {
    font-size: 3.5rem;
    margin-bottom: var(--gap);
}

.wg-status-icon--success {
    color: var(--success);
}

.wg-code {
    display: inline-block;
    margin-top: var(--gap);
    padding: .5rem 1rem;
    font-family: var(--bs-font-monospace, monospace);
    font-size: .9rem;
    color: var(--text-muted);
    background-color: var(--surface-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow-wrap: anywhere;
}

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