/* ==========================================================================
   Integration Bridge – admin design system
   Tokens + components layered on top of Bootstrap 5.3
   ========================================================================== */

:root {
    --app-bg: #f4f6fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e6e9f0;
    --border-strong: #d6dee6;
    --text: #1f2733;
    --muted: #6b7686;

    --brand: #3b5bdb;
    --brand-rgb: 59, 91, 219;
    --brand-dark: #2f49b0;

    --sidebar-bg: #1a2233;
    --sidebar-surface: #232d42;
    --sidebar-text: #d7deec;
    --sidebar-muted: #97a3bd;
    --sidebar-active-bg: rgba(91, 120, 240, 0.22);
    --sidebar-active-text: #ffffff;
    --sidebar-active-bar: #7d96ff;

    --radius: 0.75rem;
    --radius-sm: 0.5rem;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --shadow: 0 4px 12px rgba(16, 24, 40, 0.08);

    --sidebar-width: 256px;
}

body {
    background-color: var(--app-bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ----------------------------------------------------------------- Layout */

.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.app-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1 1 auto;
    padding: 1.75rem 2rem 3rem;
    max-width: 1280px;
    width: 100%;
}

.app-content:has(.page-wide) {
    max-width: none;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.page-wide {
    width: 100%;
    max-width: none;
}

@media (max-width: 991.98px) {
    .app-content { padding: 1.25rem 1rem 2.5rem; }
    .app-content:has(.page-wide) {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* ---------------------------------------------------------------- Sidebar */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar.offcanvas-lg {
    --bs-offcanvas-width: var(--sidebar-width);
    --bs-offcanvas-bg: var(--sidebar-bg);
    --bs-offcanvas-color: var(--sidebar-text);
}

@media (min-width: 992px) {
    /* Bootstrap resets .offcanvas-lg to transparent at >=lg; force our theme back. */
    .sidebar.offcanvas-lg {
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
        flex: 0 0 var(--sidebar-width);
        background-color: var(--sidebar-bg) !important;
        color: var(--sidebar-text) !important;
        visibility: visible !important;
        transform: none !important;
        border-right: 1px solid rgba(255, 255, 255, 0.05) !important;
    }
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 1.25rem 1.25rem 1rem;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.2px;
    font-size: 1.05rem;
    text-decoration: none;
}

.sidebar__brand:hover { color: #fff; }

.sidebar__brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand) 0%, #6d8bff 100%);
    color: #fff;
    font-size: 1.05rem;
    box-shadow: 0 2px 8px rgba(var(--brand-rgb), 0.5);
}

.sidebar__nav { padding: 0.5rem 0.75rem 1.5rem; }

.sidebar__section {
    padding: 1rem 0.75rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.75rem;
    margin: 0.1rem 0;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.2;
    position: relative;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.sidebar .nav-link i {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
    color: var(--sidebar-muted);
    transition: color 0.12s ease;
}

.sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.sidebar .nav-link:hover i { color: var(--sidebar-text); }

.sidebar .nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.sidebar .nav-link.active i { color: var(--sidebar-active-bar); }

.sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: -0.75rem;
    top: 0.4rem;
    bottom: 0.4rem;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--sidebar-active-bar);
}

.sidebar__footer {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar__user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.85rem;
    min-width: 0;
}

.sidebar__user:hover { color: #fff; }

.sidebar__avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--sidebar-surface);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    text-transform: uppercase;
}

.sidebar__user-meta { min-width: 0; }

.sidebar__user-email {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__user-role {
    font-size: 0.72rem;
    color: var(--sidebar-muted);
}

/* --------------------------------------------------------- Mobile topbar */

.app-topbar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-topbar__brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

@media (max-width: 991.98px) {
    .app-topbar { display: flex; }
}

/* ------------------------------------------------------------ Page header */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-header__eyebrow {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand);
    margin-bottom: 0.2rem;
}

.page-header__title {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    color: var(--text);
}

.page-header__subtitle {
    margin: 0.35rem 0 0;
    color: var(--muted);
    max-width: 70ch;
}

.page-header__actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.page-breadcrumb {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.page-breadcrumb a {
    color: var(--muted);
    text-decoration: none;
}

.page-breadcrumb a:hover { color: var(--brand); }

/* --------------------------------------------------------------- Surfaces */

.form-section,
.surface-card {
    background: var(--surface);
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.surface-card--flush { padding: 0; overflow: hidden; }

.surface-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.surface-card__title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

/* ----------------------------------------------------------- Stat cards */

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 1.35rem;
    height: 100%;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

a.stat-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
    border-color: var(--border-strong);
    color: inherit;
}

.stat-card__icon {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    background: rgba(var(--brand-rgb), 0.1);
    color: var(--brand);
}

.stat-card__icon--green { background: rgba(25, 135, 84, 0.12); color: #198754; }
.stat-card__icon--amber { background: rgba(255, 193, 7, 0.16); color: #b8860b; }
.stat-card__icon--slate { background: rgba(108, 117, 125, 0.14); color: #5c636a; }

.stat-card__label {
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0;
}

.stat-card__value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    margin: 0.1rem 0 0;
}

/* ----------------------------------------------------------------- Tables */

.table {
    --bs-table-bg: var(--surface);
    margin-bottom: 0;
}

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-card > .table-responsive { margin-bottom: 0; }

.table-card .table { margin-bottom: 0; }

.table-card .table > thead th {
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    white-space: nowrap;
}

.table-card .table > tbody td { vertical-align: middle; }

.table-card .table > tbody tr:last-child > * { border-bottom: 0; }

.table-card .table tbody tr { transition: background-color 0.1s ease; }

.key-cell { font-family: var(--bs-font-monospace); color: var(--muted); }

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

.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--muted);
}

.empty-state__icon {
    font-size: 2rem;
    color: var(--border-strong);
    margin-bottom: 0.5rem;
}

/* --------------------------------------------------------------- Buttons */

.btn { font-weight: 500; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-icon i { font-size: 1rem; line-height: 1; }

.actions-cell { white-space: nowrap; text-align: right; }

/* ---------------------------------------------------------------- Badges */

.badge { font-weight: 600; letter-spacing: 0.01em; }

.badge-role { font-size: 0.72rem; }

.badge-soft {
    background: var(--surface-muted);
    color: var(--muted);
    border: 1px solid var(--border);
}

/* ------------------------------------------------------------------ Forms */

.form-label { font-weight: 500; }

.form-section h5,
.surface-card h5 { font-weight: 600; }

.form-divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

/* ---------------------------------------------------- Connection rows */

.connection-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.connection-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    width: 100%;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.connection-row:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}

.connection-row:has(.collapse.show) {
    border-color: rgba(var(--brand-rgb), 0.35);
    box-shadow: 0 0 0 1px rgba(var(--brand-rgb), 0.12), var(--shadow-sm);
}

.connection-row__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    min-height: 3.5rem;
    padding: 1rem 1.25rem;
    margin: 0;
    border: 0;
    background: transparent;
    text-align: left;
    color: var(--text);
    cursor: pointer;
}

.connection-row__toggle:hover {
    background: var(--surface-muted);
}

.connection-row__main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1 1 auto;
}

.connection-row__chevron {
    color: var(--muted);
    font-size: 0.9rem;
    transition: transform 0.15s ease;
    flex: 0 0 auto;
}

.connection-row__toggle[aria-expanded="true"] .connection-row__chevron {
    transform: rotate(90deg);
}

.connection-row__title {
    font-weight: 650;
    font-size: 1.02rem;
    letter-spacing: -0.01em;
}

.connection-row__meta {
    color: var(--muted);
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.connection-row__content {
    padding: 1.15rem 1.25rem 1.35rem;
    border-top: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface-muted) 0%, var(--surface) 48px);
    width: 100%;
}

.connection-row__content .row {
    --bs-gutter-x: 1.25rem;
}

.connection-list__toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    width: 100%;
}

.strategy-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    width: 100%;
}

.strategy-summary__title {
    font-weight: 650;
    margin-bottom: 0.25rem;
}

/* --------------------------------------------------------------- Warehouse layout */

.wh-layout-grid {
    display: grid;
    grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: stretch;
    /* Fill remaining viewport under page header */
    min-height: calc(100dvh - 10.5rem);
}

@media (max-width: 992px) {
    .wh-layout-grid {
        grid-template-columns: 1fr;
        min-height: 0;
    }
}

.wh-layout-filters {
    position: sticky;
    top: 0.75rem;
    max-height: calc(100dvh - 2rem);
    overflow: auto;
}

.wh-layout-stage {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.wh-layout-hint {
    flex: 0 0 auto;
}

.wh-layout-canvas {
    flex: 1 1 auto;
    width: 100%;
    min-height: clamp(360px, 70dvh, calc(100dvh - 12rem));
    height: calc(100dvh - 12rem);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 2px);
    background: #f2f3f5;
    overflow: hidden;
}

@media (max-width: 992px) {
    .wh-layout-canvas {
        height: min(70dvh, 640px);
        min-height: 360px;
    }
}

.wh-layout-canvas canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.wh-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.wh-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin: 0;
    padding: 0.25rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
}

.wh-chip:has(input:checked) {
    border-color: #1a5fb4;
    background: rgba(26, 95, 180, 0.08);
}

.wh-mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
}

.wh-mode-tab {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.4rem 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.wh-mode-tab.is-active {
    border-color: #1a5fb4;
    background: rgba(26, 95, 180, 0.1);
    color: #1a5fb4;
}

.wh-range-preview {
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.875rem;
    line-height: 1.45;
}

.wh-scene-groups {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.wh-scene-group {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.35rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 0.8125rem;
    text-align: left;
}

.wh-scene-group:hover {
    border-color: #1a5fb4;
}

.wh-start-coords {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
}
.wh-start-coords.is-unset {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #64748b;
}
#wh-place-start.is-active {
  background: #ea580c;
  border-color: #ea580c;
  color: #fff;
}

/* --------------------------------------------------------------- Helpers */

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

hr { color: var(--border); opacity: 1; }
