/* console.css — shared design system. Loaded AFTER bootstrap + base.html inline
   styles so these classes win. Migrate per-page inline blocks onto these. */

:root {
    /* Missing tokens referenced by existing templates (kic_agent.html etc.) */
    --card-bg: var(--bg-card);
    --bg-secondary: var(--bg-card-header);

    /* Border-radius scale — use ONLY these going forward */
    --radius-sm: 6px;    /* inputs, small chips */
    --radius-md: 8px;    /* buttons */
    --radius-lg: 12px;   /* cards, panels */
    --radius-xl: 16px;   /* modals, hero */
    --radius-pill: 999px;

    /* Layout gutter — the single horizontal/vertical padding between the
       sidebar/viewport edge and page content. See "Screen usage" rule below. */
    --content-gutter-x: 1.25rem;
    --content-gutter-y: 1.25rem;
}

/* ---- Page shell / screen-usage rule ---------------------------------
   DESIGN RULE: maximize horizontal screen usage. Content fills the width
   available after the contextual sidebar with ONE consistent gutter — no
   max-width cap and no doubled padding. The single gutter lives on the page
   <main> (.app-content-v2 / .utility-content); .page-container is a full-width
   pass-through so it never adds a second layer of padding or re-centers/squishes
   content. Spacing BETWEEN sections stays on the sections themselves (mb-*, gap-*). */
.app-content-v2,
.utility-content {
    padding: var(--content-gutter-y) var(--content-gutter-x);
}
.page-container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}
.page-container.page-fluid { max-width: none; padding: 0; }

/* ---- Shared page header --------------------------------------------- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.page-header__main { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }
.page-header__icon {
    width: 44px; height: 44px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-lg);
    font-size: 1.25rem; color: #fff;
    background: var(--section-accent, var(--primary-color));
}
.page-header__title { margin: 0; font-size: 1.35rem; font-weight: 600; color: var(--text-heading); }
.page-header__subtitle { margin: 0; font-size: 0.85rem; color: var(--text-secondary); }
.page-header__actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.page-breadcrumb { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.page-breadcrumb a { color: var(--text-secondary); text-decoration: none; }
.page-breadcrumb a:hover { color: var(--primary-color); }

/* ---- Shared detail/editor page header (see partials/detail_header.html) --- */
.detail-hdr { margin-bottom: 1.5rem; }
.detail-hdr__back {
    display: inline-flex; align-items: center;
    font-size: 0.8rem; color: var(--text-secondary); text-decoration: none; margin-bottom: 0.6rem;
}
.detail-hdr__back:hover { color: var(--primary-color); }
.detail-hdr__row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.detail-hdr__main { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }
.detail-hdr__icon {
    width: 44px; height: 44px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-lg); font-size: 1.25rem; color: #fff;
    background: var(--section-accent, var(--primary-color));
}
.detail-hdr__title { margin: 0; font-size: 1.35rem; font-weight: 600; color: var(--text-heading); }
.detail-hdr__subtitle { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.2rem; }

/* ---- Shared entity-hero card (see partials/entity_hero.html) -------- */
.entity-hero {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--section-accent, var(--primary-color));
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem; margin-bottom: 1.5rem;
}
.entity-hero__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.entity-hero__main { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.entity-hero__icon {
    width: 48px; height: 48px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-lg); font-size: 1.4rem; color: #fff;
    background: var(--section-accent, var(--primary-color));
}
.entity-hero__title { margin: 0; font-size: 1.4rem; font-weight: 600; color: var(--text-heading); }
.entity-hero__meta { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.2rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 0.85rem; }
.entity-hero__actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.entity-hero__badges { margin-top: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }

/* ---- Shared data table (replaces the duplicated 531-line blocks) ---- */
.data-table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.data-table-card .table { margin: 0; }
.data-table-card .table thead th {
    background: var(--bg-table-header);
    color: var(--text-secondary);
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em;
    font-weight: 600; border-bottom: 1px solid var(--border-color);
}
.data-table-card .table tbody tr:hover { background: var(--bg-hover); }

/* ---- Shared stat card ---------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--section-accent, var(--primary-color));
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
}
.stat-card__value { font-size: 1.5rem; font-weight: 700; color: var(--text-heading); line-height: 1.1; }
.stat-card__label { font-size: 0.8rem; color: var(--text-secondary); }

/* ---- Top-bar module switcher --------------------------------------- */
.module-switcher { align-items: center; gap: 0.15rem; margin-left: 0.5rem; }
.module-switcher__item {
    background: none; border: none; color: rgba(255,255,255,0.72);
    font-size: 0.85rem; font-weight: 500; padding: 0.4rem 0.7rem;
    border-radius: var(--radius-md); cursor: pointer; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 0.35rem;
    border-bottom: 2px solid transparent;
}
.module-switcher__item:hover { color: #fff; background: rgba(255,255,255,0.08); }
.module-switcher__item.active { color: #fff; border-bottom-color: var(--section-accent, var(--primary-color)); }
.module-switcher .dropdown-toggle::after {
    margin-left: 0.35rem; border: none; content: "\F229"; /* bootstrap-icons chevron-down */
    font-family: "bootstrap-icons"; font-size: 0.7rem; vertical-align: -0.05em;
    transition: transform 0.15s ease; opacity: 0.7;
}
.module-switcher .dropdown-toggle[aria-expanded="true"]::after { transform: rotate(180deg); opacity: 1; }

/* Polished dropdown menu */
.module-switcher .dropdown-menu {
    --bs-dropdown-min-width: 232px;
    margin-top: 0.45rem;
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: 0 12px 32px -10px rgba(0,0,0,0.30), 0 2px 8px rgba(0,0,0,0.06);
    /* Opacity-only fade. Do NOT animate transform here: Bootstrap/Popper sets an
       inline transform to position the menu, and a transform animation overrides
       it mid-flight, making the menu snap from the top-left into place. */
    animation: ms-dropdown-in 0.13s ease;
}
@keyframes ms-dropdown-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.module-switcher .dropdown-item {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem; font-weight: 500;
    color: var(--text-primary);
    transition: background 0.12s ease, color 0.12s ease;
}
.module-switcher .dropdown-item i {
    width: 1.5rem; height: 1.5rem; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.9rem; border-radius: var(--radius-sm);
    color: var(--section-accent, var(--text-secondary));
    background: color-mix(in srgb, var(--section-accent, var(--text-secondary)) 12%, transparent);
}
.module-switcher .dropdown-item:hover,
.module-switcher .dropdown-item:focus {
    background: var(--bg-hover); color: var(--text-heading);
}
.module-switcher .dropdown-item.active {
    background: color-mix(in srgb, var(--section-accent, var(--primary-color)) 14%, transparent);
    color: var(--text-heading); font-weight: 600;
}
.module-switcher .dropdown-item.active i {
    color: #fff; background: var(--section-accent, var(--primary-color));
}

/* ---- Contextual sidebar -------------------------------------------- */
:root { --topbar-height: 48px; }

/* Reset the old always-on 60px rail margin; content is full-width by default.
   (Horizontal/vertical gutter is the single --content-gutter-* set above.) */
.app-layout-v2, .app-footer-v2 { margin-left: 0 !important; }
/* When a contextual sidebar is present (active module), clear it. */
.ctx-sidebar ~ .app-layout-v2,
.ctx-sidebar ~ .app-footer-v2 { margin-left: 240px !important; }

.ctx-sidebar {
    position: fixed; left: 0; top: var(--topbar-height); z-index: 1020;
    width: 240px; flex: none; background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    height: calc(100vh - var(--topbar-height)); overflow-y: auto;
}
.ctx-sidebar__header { display: flex; align-items: center; gap: 0.6rem; padding: 1rem; border-bottom: 1px solid var(--border-color); }
.ctx-sidebar__icon {
    width: 34px; height: 34px; border-radius: var(--radius-md); color: #fff;
    display: flex; align-items: center; justify-content: center; flex: none;
    background: var(--section-accent, var(--primary-color));
}
.ctx-sidebar__title { font-weight: 600; color: var(--text-heading); }
.ctx-sidebar__body { padding: 0.5rem; }
.ctx-sidebar__group { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 0.75rem 0.75rem 0.35rem; }
.ctx-sidebar__link {
    display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md); color: var(--text-secondary); text-decoration: none;
    font-size: 0.875rem; border-left: 2px solid transparent;
}
.ctx-sidebar__link i { width: 1rem; text-align: center; }
.ctx-sidebar__link:hover { background: var(--bg-hover); color: var(--text-primary); }
.ctx-sidebar__link.active { background: var(--bg-hover); color: var(--text-heading); border-left-color: var(--section-accent); font-weight: 600; }

/* Mobile: sidebar slides in over content via the existing toggleMobileSidebar() */
@media (max-width: 991px) {
    .ctx-sidebar { transform: translateX(-100%); transition: transform 0.25s ease; }
    .ctx-sidebar.mobile-open { transform: translateX(0); box-shadow: 0 0 24px rgba(0,0,0,0.25); }
    .ctx-sidebar ~ .app-layout-v2,
    .ctx-sidebar ~ .app-footer-v2 { margin-left: 0 !important; }
}

/* ---- Mobile offcanvas nav ------------------------------------------ */
.mobile-nav { width: 270px; }
.mobile-nav .mnav-domain {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); font-weight: 700;
    padding: 0.85rem 0.25rem 0.35rem; border-bottom: 2px solid var(--section-accent, var(--border-color));
    margin-bottom: 0.25rem;
}
.mobile-nav .mnav-link {
    display: flex; align-items: center; padding: 0.55rem 0.5rem;
    border-radius: var(--radius-md); color: var(--text-secondary);
    text-decoration: none; font-size: 0.9rem;
}
.mobile-nav .mnav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.mobile-nav .mnav-link.active { background: var(--bg-hover); color: var(--text-heading); font-weight: 600; }

/* ---- Shared enhanced tables (.ktable, see ktable.js) --------------- */
.ktable-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.ktable-toolbar {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card-header);
}
.ktable-toolbar .ktable-spacer { flex: 1; }
.ktable-search { position: relative; display: flex; align-items: center; min-width: 220px; }
.ktable-search i {
    position: absolute; left: 0.6rem; color: var(--text-muted); font-size: 0.85rem; pointer-events: none;
}
.ktable-search input.form-control { padding-left: 2rem; border-radius: var(--radius-md); }
.ktable-count { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }
.ktable-cols .dropdown-toggle { border-radius: var(--radius-md); white-space: nowrap; }
.ktable-cols-menu {
    border: 1px solid var(--border-color); border-radius: var(--radius-lg);
    background: var(--bg-card); padding: 0.35rem;
    box-shadow: 0 12px 32px -10px rgba(0,0,0,0.30);
    max-height: 320px; overflow-y: auto;
}
.ktable-col-toggle {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.4rem 0.55rem; border-radius: var(--radius-md);
    font-size: 0.85rem; color: var(--text-primary); cursor: pointer; user-select: none;
}
.ktable-col-toggle:hover { background: var(--bg-hover); }
.ktable-col-toggle input { accent-color: var(--primary-color); }

.ktable-scroll { overflow-x: auto; }

/* Uniform appearance for EVERY ktable (the "Companies look"), regardless of the
   table's legacy class. Child-combinator selectors give enough specificity to
   win over per-page <style> blocks (which load after console.css). The
   .ktable-wrap provides the card, so reset any legacy border/radius on the table. */
table.ktable {
    margin: 0; width: 100%;
    color: var(--text-primary);
    background: transparent;
    border: none; border-radius: 0; box-shadow: none;
    border-collapse: collapse; border-spacing: 0;
}
table.ktable > thead > tr > th {
    position: sticky; top: 0; z-index: 2;
    background: var(--bg-table-header);
    color: var(--text-secondary);
    padding: 0.6rem 0.75rem;
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
table.ktable > tbody > tr > td,
table.ktable > tbody > tr > th {
    padding: 0.55rem 0.75rem;
    font-size: 0.875rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
}
table.ktable > tbody > tr:hover > td,
table.ktable > tbody > tr:hover > th { background: var(--bg-hover); }
table.ktable > tbody > tr:last-child > td,
table.ktable > tbody > tr:last-child > th { border-bottom: none; }
table.ktable th.ktable-sortable { cursor: pointer; position: sticky; }
table.ktable th.ktable-sortable::after {
    content: "\F575"; /* bootstrap-icons chevron-expand */
    font-family: "bootstrap-icons"; font-size: 0.7rem; opacity: 0.3; margin-left: 0.35rem; vertical-align: -0.05em;
}
table.ktable th.ktable-sort-asc::after { content: "\F235"; opacity: 0.9; } /* chevron-up */
table.ktable th.ktable-sort-desc::after { content: "\F229"; opacity: 0.9; } /* chevron-down */
table.ktable .ktable-col-hidden { display: none !important; }
table.ktable tr.ktable-empty td { text-align: center; color: var(--text-muted); padding: 1.5rem; }
