/*
  TrapWatch design tokens — CSS side. Mirrors TrapWatchColors.cs for non-C# contexts
  (inline styles, scoped component CSS, pure CSS). Single source for brand colors, geometry
  and typography variables. Served as a static web asset:
    _content/TrapWatch.Design.Tokens/trapwatch-tokens.css
*/
:root {
    /* Brand */
    --tw-primary: #182b3b;
    --tw-primary-2: #1c3d55;
    --tw-aqua: #20b2aa;
    --tw-aqua-hover: #1a9d96;
    --tw-gold: #ffba00;
    --tw-info: #2196f3;
    --tw-salmon: #f2756b;
    --tw-success: #2e7d57;
    --tw-success-bright: #40c87a;

    /* Surfaces */
    --tw-white: #ffffff;
    --tw-surface: #ffffff;
    --tw-background: #fafafa;
    --tw-drawer-bg: #f5f5f5;
    --tw-drawer-text: #333333;

    /* Geometry */
    --tw-r-card: 12px;
    --tw-r-hero: 14px;
    --tw-shadow-1: 0 1px 2px rgba(24, 43, 59, 0.06), 0 2px 8px rgba(24, 43, 59, 0.06);

    /* Layout widths */
    --tw-search-max-width: 380px;
    --tw-search-max-width-md: 340px;
    --tw-form-max-width: 560px;
    --tw-form-max-width-lg: 640px;
    --tw-actions-col-width: 96px;
    --tw-actions-col-width-sm: 64px;

    /* Typography */
    --tw-font-display: 'Montserrat', 'Roboto', sans-serif;
    --tw-font-body: 'Roboto', 'Helvetica', 'Arial', sans-serif;
}

/* Page hero — shared brand gradient header (consumed by TrapWatch.Blazor.Components/PageHero). */
.tw-page-hero {
    background: linear-gradient(135deg, var(--tw-primary) 0%, var(--tw-primary-2) 100%);
    color: var(--tw-white);
    border-radius: var(--tw-r-hero);
    padding: 1.5rem 1.75rem;
    box-shadow: var(--tw-shadow-1);
}

.tw-hero-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    opacity: 0.8;
}

.tw-hero-title {
    font-family: var(--tw-font-display);
    font-weight: 800;
    font-size: 1.75rem;
    line-height: 1.2;
    margin: 0.15rem 0 0.25rem;
}

.tw-hero-subtitle {
    opacity: 0.85;
    font-size: 0.95rem;
}

/* Utility classes — replace raw inline Style widths. */
.tw-search-field     { max-width: var(--tw-search-max-width); }
.tw-search-field-md  { max-width: var(--tw-search-max-width-md); }
.tw-form-paper       { max-width: var(--tw-form-max-width); }
.tw-form-paper-lg    { max-width: var(--tw-form-max-width-lg); }

/* =====================================================
   TW DESIGN SYSTEM — page scope
   EntityListLayout / EntityDetailLayout / EntityFormLayout
   emit a <div class="tw-page"> wrapper automatically.
   Other pages (Dashboard etc.) add it manually.
   ===================================================== */

/* Cards */
.tw-page .tw-d-card {
    background: var(--mud-palette-surface, #fff);
    border-radius: var(--tw-r-card);
    border: 1px solid var(--mud-palette-lines-default, rgba(0, 0, 0, 0.09));
    box-shadow: var(--tw-shadow-1);
    position: relative;
    overflow: hidden;
}

.tw-page .tw-d-card.padded {
    padding: 18px 20px;
}

.tw-page .tw-d-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
}

.tw-page .tw-d-card-head .title {
    font-family: var(--tw-font-display);
    font-weight: 800;
    font-size: 0.92rem;
    letter-spacing: 0.02em;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
}

.tw-page .tw-d-card-head .meta {
    font-size: 0.78rem;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
}

.tw-page .tw-d-card-head .link {
    font-size: 0.78rem;
    color: var(--tw-aqua);
    cursor: pointer;
    font-weight: 500;
    text-decoration: none;
}

/* Filter bar */
.tw-page .tw-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.tw-page .tw-filter-bar > * {
    flex: 0 0 auto;
    margin: 0;
}

.tw-page .tw-filter-bar .mud-autocomplete .mud-input.mud-input-margin-dense {
    margin-top: 0;
    margin-bottom: 0;
}

.tw-page .tw-filter-bar .mud-input-control.mud-input-control-margin-dense {
    margin: 0;
}

.tw-page .tw-filter-bar .tw-filter-grow,
.tw-page .tw-filter-bar .filter-grow {
    flex: 1 1 240px;
    min-width: 220px;
}

/* Active-filter notice */
.tw-page .tw-filter-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--tw-r-card);
    background: rgba(255, 186, 0, 0.08);
    border: 1px solid rgba(255, 186, 0, 0.22);
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
    font-size: 0.86rem;
    margin: 12px 0;
}

.tw-page .tw-filter-notice .icon { color: var(--tw-gold); display: inline-flex; }
.tw-page .tw-filter-notice .spacer { flex: 1; }

/* Key/value rows */
.tw-page .tw-kv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default, rgba(0, 0, 0, 0.09));
    font-size: 0.86rem;
}

.tw-page .tw-kv-row:last-child { border-bottom: 0; }

.tw-page .tw-kv-row .k {
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    font-weight: 500;
}

.tw-page .tw-kv-row .v {
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
    font-weight: 500;
    text-align: right;
    word-break: break-word;
}

.tw-page .tw-kv-row .v a { color: var(--tw-aqua); text-decoration: none; }
.tw-page .tw-kv-row .v a:hover { text-decoration: underline; }

/* Stat grid */
.tw-page .tw-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

.tw-page .tw-stat-block { display: flex; flex-direction: column; gap: 2px; }

.tw-page .tw-stat-block .v {
    font-family: var(--tw-font-display);
    font-weight: 800;
    font-size: 2rem;
    line-height: 1;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
}

.tw-page .tw-stat-block .l {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    font-weight: 600;
}

.tw-page .tw-stat-block .s {
    font-size: 0.78rem;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    margin-top: 2px;
}

/* List items */
.tw-page .tw-list-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-top: 1px solid var(--mud-palette-lines-default, rgba(0, 0, 0, 0.09));
    cursor: pointer;
    transition: background 0.12s;
    text-decoration: none;
    color: inherit;
}

.tw-page .tw-list-item:hover { background: rgba(32, 178, 170, 0.04); }
.tw-page .tw-list-item:first-child { border-top: 0; }

.tw-page .tw-li-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(24, 43, 59, 0.06);
    color: var(--tw-primary);
    font-weight: 600;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.tw-page .tw-li-main { flex: 1; min-width: 0; }

.tw-page .tw-li-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tw-page .tw-li-sub {
    font-size: 0.78rem;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    margin-top: 2px;
}

.tw-page .tw-li-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.tw-page .tw-li-meta .time {
    font-size: 0.78rem;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    font-weight: 500;
}

.tw-page .tw-li-meta .time.danger { color: var(--tw-salmon); }
.tw-page .tw-li-meta .time.warn { color: var(--tw-gold); }
.tw-page .tw-li-meta .time.info { color: var(--tw-info); }

/* Empty state */
.tw-page .tw-empty {
    padding: 28px 18px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.tw-page .tw-empty-mark {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(46, 125, 87, 0.10);
    color: var(--tw-success);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}

/* Hero slot helpers */
.tw-page-hero .tw-hero-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.tw-page-hero .tw-hero-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.tw-hero-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: white;
    font-size: 0.74rem;
    font-weight: 500;
    line-height: 1.4;
}

/* Section heading */
.tw-page .tw-sec-h {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 28px 0 10px;
    padding: 0 2px;
}

.tw-page .tw-sec-h .t {
    font-family: var(--tw-font-display);
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
}

.tw-page .tw-sec-h .a {
    font-size: 0.82rem;
    color: var(--tw-aqua);
    cursor: pointer;
    font-weight: 500;
    text-decoration: none;
}

/* MudDataGrid inside a card */
.tw-page .tw-grid-card {
    padding: 0;
    overflow: hidden;
}

.tw-page .tw-grid-card .mud-table-container { background: transparent; }

.tw-page .tw-grid-card .mud-table-cell {
    border-bottom-color: var(--mud-palette-lines-default, rgba(0, 0, 0, 0.09));
    font-size: 0.86rem;
}

.tw-page .tw-grid-card .mud-table-head .mud-table-cell {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.7rem;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    font-weight: 600;
    background: rgba(24, 43, 59, 0.02);
}

.tw-page .tw-grid-card .mud-table-row:hover {
    background: rgba(32, 178, 170, 0.04) !important;
}

/* Progress bar */
.tw-page .tw-pct-bar {
    display: inline-block;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: rgba(24, 43, 59, 0.06);
    overflow: hidden;
    vertical-align: middle;
}

.tw-page .tw-pct-bar > div { height: 100%; border-radius: 999px; background: var(--tw-aqua); }
.tw-page .tw-pct-bar.warn > div { background: var(--tw-gold); }
.tw-page .tw-pct-bar.danger > div { background: var(--tw-salmon); }
.tw-page .tw-pct-bar.ok > div { background: var(--tw-success); }

/* Button family */
.tw-page .tw-btn,
.mud-dialog .tw-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 0;
    font: inherit;
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s, color 0.12s, box-shadow 0.12s, transform 0.08s;
    white-space: nowrap;
}

.tw-page .tw-btn:active,
.mud-dialog .tw-btn:active { transform: translateY(1px); }

.tw-page .tw-btn:disabled,
.tw-page .tw-btn[aria-disabled="true"],
.mud-dialog .tw-btn:disabled,
.mud-dialog .tw-btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

.tw-page .tw-btn[aria-disabled="true"],
.mud-dialog .tw-btn[aria-disabled="true"] { pointer-events: none; }

.tw-page .tw-btn-aqua,
.mud-dialog .tw-btn-aqua {
    background: var(--tw-aqua);
    color: white;
    box-shadow: 0 1px 4px rgba(32, 178, 170, 0.35);
}

.tw-page .tw-btn-aqua:hover,
.mud-dialog .tw-btn-aqua:hover { background: var(--tw-aqua-hover); }

.tw-page .tw-btn-ghost,
.mud-dialog .tw-btn-ghost {
    background: transparent;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
    border: 1px solid var(--mud-palette-lines-inputs, rgba(0, 0, 0, 0.23));
}

.tw-page .tw-btn-ghost:hover,
.mud-dialog .tw-btn-ghost:hover { background: rgba(24, 43, 59, 0.04); }

.tw-page .tw-btn-sm,
.mud-dialog .tw-btn-sm { padding: 5px 12px; font-size: 0.78rem; border-radius: 6px; }

.tw-page .tw-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    transition: background 0.12s;
}

.tw-page .tw-btn-icon:hover { background: rgba(255, 255, 255, 0.10); }

/* =====================================================
   TW DESIGN SYSTEM — MultiSelectFilter popover
   Used by TrapWatch.Blazor.Components/MultiSelectFilter.razor
   ===================================================== */

.tw-msf-anchor {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    flex: 0 0 auto;
}

.tw-msf-trigger {
    position: relative;
    border: 1px solid var(--mud-palette-lines-inputs, rgba(0, 0, 0, 0.23));
    border-radius: 4px;
    background: var(--mud-palette-surface, #fff);
    cursor: pointer;
    padding: 8px 10px;
    min-height: 40px;
    box-sizing: border-box;
    transition: border-color 120ms;
}

.tw-msf-trigger:hover { border-color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.6)); }

.tw-msf-trigger.open {
    border-color: var(--mud-palette-primary);
    border-width: 2px;
    padding: 7px 9px;
}

.tw-msf-trigger:focus { outline: none; border-color: var(--mud-palette-primary); }

.tw-msf-trigger-label {
    position: absolute;
    top: -7px;
    left: 8px;
    background: var(--mud-palette-surface, #fff);
    padding: 0 4px;
    font-size: 0.75rem;
    line-height: 1;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.6));
    pointer-events: none;
}

.tw-msf-trigger.open .tw-msf-trigger-label { color: var(--mud-palette-primary); }

.tw-msf-trigger-row { display: flex; align-items: center; gap: 6px; min-height: 22px; }

.tw-msf-trigger-icon {
    flex: 0 0 auto;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
}

.tw-msf-trigger-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
}

.tw-msf-trigger-text.placeholder { color: var(--mud-palette-text-disabled, rgba(0, 0, 0, 0.38)); }

.tw-msf-trigger-caret {
    flex: 0 0 auto;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
}

.tw-msf-popover-shell { z-index: 1200; }

.tw-msf-popover {
    background: var(--mud-palette-surface, #fff);
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    min-width: 280px;
    max-width: 420px;
    overflow: hidden;
}

.tw-msf-search-row {
    padding: 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default, rgba(0, 0, 0, 0.08));
}

.tw-msf-list { max-height: 320px; overflow-y: auto; padding: 4px 0; }

.tw-msf-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    cursor: pointer;
    user-select: none;
}

.tw-msf-item:hover { background: var(--mud-palette-action-default-hover, rgba(0, 0, 0, 0.04)); }
.tw-msf-item.selected { background: rgba(32, 178, 170, 0.08); }
.tw-msf-item-check { flex: 0 0 auto; }

.tw-msf-item-label {
    flex: 1;
    font-size: 0.9rem;
    color: var(--mud-palette-text-primary, rgba(0, 0, 0, 0.87));
}

.tw-msf-empty {
    padding: 12px 16px;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    font-size: 0.875rem;
    font-style: italic;
    text-align: center;
}

.tw-msf-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px 4px 12px;
    border-top: 1px solid var(--mud-palette-lines-default, rgba(0, 0, 0, 0.08));
}

.tw-msf-footer-count {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.6));
}

/* =====================================================
   FORM SECTION LABELS (global — no .tw-page scope)
   ===================================================== */

.tw-form-section-label {
    display: block;
    font-size: 0.70rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--mud-palette-primary);
    padding-bottom: 6px;
    border-bottom: 2px solid rgba(24, 43, 59, 0.18);
    margin-bottom: 2px;
}

/* =====================================================
   COMING SOON PANEL
   ===================================================== */

.tw-coming-soon-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    gap: 8px;
}

/* =====================================================
   NAV — active link styling
   ===================================================== */

.mud-nav-link.active { font-weight: 600; }

/* =====================================================
   IDENTITY CARD — entity detail sidebar
   ===================================================== */

.tw-page .tw-identity-card {
    background: linear-gradient(145deg, var(--tw-primary) 0%, var(--tw-primary-2) 100%);
    color: white;
    border-radius: var(--tw-r-card);
    padding: 20px;
    box-shadow: var(--tw-shadow-1);
    margin-bottom: 12px;
}

.tw-page .tw-avatar-initials {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--tw-font-display);
    font-weight: 800;
    font-size: 1.3rem;
    color: white;
    flex-shrink: 0;
    margin-bottom: 12px;
}

.tw-page .tw-identity-name {
    font-family: var(--tw-font-display);
    font-weight: 800;
    font-size: 1.15rem;
    color: white;
    margin-bottom: 4px;
    line-height: 1.25;
    word-break: break-word;
}

.tw-page .tw-identity-sub {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.72);
    margin-bottom: 14px;
}

.tw-page .tw-identity-card .tw-stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    padding-top: 14px;
    margin-top: 6px;
    margin-bottom: 0;
}

.tw-page .tw-identity-card .tw-stat-block .v {
    color: white;
}

.tw-page .tw-identity-card .tw-stat-block .l {
    color: rgba(255, 255, 255, 0.65);
}

.tw-page .tw-identity-card .tw-stat-block .s {
    color: rgba(255, 255, 255, 0.55);
}

/* Detail-panel quick actions inside identity card */
.tw-page .tw-identity-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 14px;
}

/* =====================================================
   DETAIL SECTION CARD — sidebar detail / kv card
   ===================================================== */

.tw-page .tw-detail-section {
    margin-bottom: 12px;
}

.tw-page .tw-detail-section:last-child {
    margin-bottom: 0;
}

.tw-page .tw-detail-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary, rgba(0, 0, 0, 0.54));
    padding: 0 2px 8px;
}

/* Tabs inside detail pages */
.tw-page .tw-detail-tabs .mud-tab {
    font-weight: 600;
    font-size: 0.86rem;
}
