:root {
    --sg-sidebar-width: 270px;
    --sg-sidebar-bg: #111827;
    --sg-sidebar-hover: #1f2937;
    --sg-primary: #2563eb;
    --sg-page-bg: #f5f7fb;
    --sg-border: #e5e7eb;
    --sg-text: #111827;
    --sg-muted: #64748b;
    --sg-radius: 14px;
}

* { box-sizing: border-box; }
html { max-width: 100%; overflow-x: hidden; }
body {
    margin: 0;
    min-width: 320px;
    max-width: 100%;
    overflow-x: hidden;
    background: var(--sg-page-bg);
    color: var(--sg-text);
    font-family: Arial, Helvetica, sans-serif;
}
img, svg, video, canvas, iframe { max-width: 100%; height: auto; }
button, input, select, textarea { max-width: 100%; }

/* Sidebar */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1045;
    width: var(--sg-sidebar-width);
    height: 100dvh;
    padding: 24px 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--sg-sidebar-bg);
    box-shadow: 10px 0 30px rgba(15, 23, 42, .08);
    transition: transform .28s ease;
}
.brand {
    margin: 0 0 34px;
    padding: 0 10px;
    color: #fff;
    font-size: clamp(24px, 2vw, 28px);
    font-weight: 700;
    line-height: 1.2;
}
.brand span { color: #3b82f6; }
.menu { display: grid; gap: 6px; }
.menu a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 11px 14px;
    border-radius: 9px;
    color: #cbd5e1;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: background .2s ease, color .2s ease, transform .2s ease;
}
.menu a:hover, .menu a:focus-visible, .menu a.active {
    color: #fff;
    background: var(--sg-sidebar-hover);
}
.menu a:active { transform: scale(.99); }

/* Main shell */
.main {
    width: calc(100% - var(--sg-sidebar-width));
    min-height: 100dvh;
    margin-left: var(--sg-sidebar-width);
    transition: margin .28s ease, width .28s ease;
}
.navbar {
    min-height: 70px;
    height: auto;
    gap: 16px;
    padding: 12px 25px !important;
    border-bottom: 1px solid var(--sg-border);
    background: rgba(255,255,255,.96) !important;
    backdrop-filter: blur(10px);
}
.navbar h5 { color: var(--sg-text); }
.navbar .dropdown { min-width: 0; }
.navbar .dropdown-toggle {
    display: block;
    max-width: min(42vw, 340px);
    padding-inline: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.content {
    width: 100%;
    max-width: 100%;
    padding: clamp(18px, 2.6vw, 34px);
}
.content > .container,
.content > .container-fluid { max-width: 100%; padding-inline: 0; }

/* Cards and typography */
.card, .dashboard-card {
    max-width: 100%;
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: var(--sg-radius);
    background: #fff;
    box-shadow: 0 5px 20px rgba(15, 23, 42, .05);
}
.dashboard-card { height: 100%; padding: clamp(18px, 2vw, 25px); }
.card-body { min-width: 0; padding: clamp(16px, 2vw, 24px); }
.card-title { color: var(--sg-muted); }
.card-number { margin-top: 10px; font-size: clamp(28px, 4vw, 38px); font-weight: 700; }
h1, h2, h3, h4, h5, h6, p, td, th, label { overflow-wrap: anywhere; }
h2 { font-size: clamp(1.45rem, 3vw, 2rem); }

/* Forms */
.form-control, .form-select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
}
textarea.form-control { min-height: 110px; }
.input-group { flex-wrap: nowrap; }
.form-label { font-weight: 500; }

/* Buttons */
.btn { min-height: 42px; white-space: normal; }
.btn-group { flex-wrap: wrap; gap: 6px; }
.btn-group > .btn { border-radius: 6px !important; }

/* Tables */
.table-responsive, .sg-table-responsive {
    position: relative;
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    border: 1px solid var(--sg-border);
    border-radius: 10px;
    background: #fff;
    scrollbar-width: auto;
    scrollbar-color: #94a3b8 #e2e8f0;
}
.table-responsive::-webkit-scrollbar,
.sg-table-responsive::-webkit-scrollbar { height: 12px; }
.table-responsive::-webkit-scrollbar-track,
.sg-table-responsive::-webkit-scrollbar-track { background: #e2e8f0; border-radius: 999px; }
.table-responsive::-webkit-scrollbar-thumb,
.sg-table-responsive::-webkit-scrollbar-thumb { background: #94a3b8; border: 3px solid #e2e8f0; border-radius: 999px; }
.table-responsive::-webkit-scrollbar-thumb:hover,
.sg-table-responsive::-webkit-scrollbar-thumb:hover { background: #64748b; }

table.table {
    width: max-content;
    min-width: 100%;
    margin-bottom: 0;
    table-layout: auto;
}
table.table.sg-wide-table { min-width: 1050px; }
table.table th {
    white-space: nowrap;
    vertical-align: middle;
}
table.table td {
    min-width: 110px;
    vertical-align: middle;
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
}
table.table td.sg-wrap-cell {
    min-width: 240px;
    max-width: 360px;
    white-space: normal;
    overflow-wrap: anywhere;
}
table.table .btn { min-height: 36px; padding: .375rem .65rem; white-space: nowrap; }

/* DataTables must stay inside the card and allow its table to scroll. */
.dt-container, .dataTables_wrapper { width: 100%; max-width: 100%; min-width: 0; }
.dt-container .row, .dataTables_wrapper .row { min-width: 0; }
.dt-container .dt-layout-table, .dataTables_wrapper .row:has(table) { min-width: 0; }
.dt-scroll, .dt-scroll-body { max-width: 100%; }
.dt-scroll-body { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }

.sg-table-scroll-note {
    display: none;
    margin: 0 0 10px;
    color: var(--sg-muted);
    font-size: 13px;
    font-weight: 600;
}

/* Modal and dropdown safeguards */
.dropdown-menu { max-width: calc(100vw - 24px); }
.modal-dialog { margin-inline: auto; }
.modal-content { border-radius: var(--sg-radius); }

/* Mobile navigation */
.sidebar-toggle {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: var(--sg-sidebar-bg);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-shadow: 0 5px 14px rgba(17, 24, 39, .2);
}
.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 999px;
    background: #fff;
    transition: transform .25s ease, opacity .25s ease;
}
.sidebar-toggle.is-active span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-toggle.is-active span:nth-child(2) { opacity: 0; }
.sidebar-toggle.is-active span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 1040;
    display: none;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }
body.sidebar-open { overflow: hidden; }

/* Standalone authentication pages */
body.bg-light > .container {
    width: 100%;
    max-width: 100%;
    padding-inline: 16px;
}
body.bg-light > .container > .card.mx-auto {
    width: 100%;
    margin-block: clamp(24px, 8vh, 80px);
}

@media (max-width: 1199.98px) {
    .content { padding: 24px; }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-105%); width: min(82vw, 280px); }
    .sidebar.active { transform: translateX(0); }
    .main { width: 100%; margin-left: 0; }
    .sidebar-toggle { display: flex; }
    .navbar { padding: 10px 16px !important; }
    .navbar h5 { font-size: 18px; }
    .content { padding: 20px; }
    .row > [class*="col-"] { min-width: 0; }
}

@media (max-width: 767.98px) {
    .content { padding: 16px; }
    .content .d-flex.justify-content-between,
    .content .d-flex.align-items-center.justify-content-between {
        align-items: stretch !important;
        flex-direction: column;
        gap: 12px;
    }
    .content .d-flex.justify-content-between > .btn,
    .content .d-flex.align-items-center.justify-content-between > .btn { width: 100%; }
    .card-body { padding: 16px; }
    .row { --bs-gutter-x: 1rem; }
    .row.g-4 { --bs-gutter-y: 1rem; }
    table.table { min-width: 760px; }
    table.table.sg-wide-table { min-width: 1050px; }
    .sg-table-scroll-note { display: flex; align-items: center; gap: 6px; }
    .pagination { flex-wrap: wrap; gap: 4px; }
}

@media (max-width: 575.98px) {
    .navbar { min-height: 62px; gap: 10px; }
    .navbar h5 { max-width: 34vw; font-size: 16px; line-height: 1.2; }
    .navbar .d-flex.align-items-center.gap-3 { min-width: 0; margin-left: auto; }
    .navbar .dropdown-toggle { max-width: 34vw; padding-inline: 2px; font-size: 13px; }
    .content { padding: 12px; }
    .brand { margin-bottom: 24px; }
    .card, .dashboard-card { border-radius: 11px; }
    .dashboard-card { padding: 16px; }
    .content .btn:not(.btn-sm):not(.dropdown-toggle),
    form .btn:not(.btn-sm) { width: 100%; }
    .modal-dialog { width: auto; margin: 12px; }
    .modal-footer { flex-direction: column; }
    .modal-footer .btn { width: 100%; margin: 0; }
    body.bg-light > .container { margin-top: 0 !important; }
    body.bg-light > .container > .card.mx-auto { margin-block: 20px; }
}

/* Phase 1 dashboard components */
.sg-chart-wrap { position: relative; min-height: 300px; }
.sg-status,
.sg-severity {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}
.sg-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}
.sg-status-online { color: #166534; background: #dcfce7; }
.sg-status-warning { color: #92400e; background: #fef3c7; }
.sg-status-offline { color: #991b1b; background: #fee2e2; }
.sg-severity-info { color: #1e3a8a; background: #dbeafe; }
.sg-severity-low { color: #166534; background: #dcfce7; }
.sg-severity-medium { color: #92400e; background: #fef3c7; }
.sg-severity-high { color: #9a3412; background: #ffedd5; }
.sg-severity-critical { color: #991b1b; background: #fee2e2; }
.sg-project-card { transition: transform .2s ease, box-shadow .2s ease; }
.sg-project-card:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(15, 23, 42, .1); }
.sg-mini-stat {
    min-height: 76px;
    padding: 12px;
    border: 1px solid var(--sg-border);
    border-radius: 10px;
    background: #f8fafc;
}
.sg-mini-stat span { display: block; color: var(--sg-muted); font-size: 12px; }
.sg-mini-stat strong { display: block; margin-top: 5px; font-size: 22px; }
.sg-project-meta dt { color: var(--sg-muted); font-weight: 600; }
.sg-project-meta dd { text-align: right; overflow-wrap: anywhere; }
.sg-detail-list dt { padding-top: 8px; color: var(--sg-muted); }
.sg-detail-list dd { margin-bottom: 0; padding-top: 8px; border-bottom: 1px solid var(--sg-border); }
.sg-detail-value {
    max-width: 100%;
    margin: 0 0 8px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--sg-text);
    font: inherit;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
select[multiple].form-select { min-height: 110px; }

@media (max-width: 767.98px) {
    .sg-chart-wrap { min-height: 240px; }
    .sg-project-meta dd { text-align: left; }
}

/* Plugin Release Manager */
.sg-release-manager { padding-bottom: 28px; }
.sg-release-hero {
    padding: clamp(20px, 3vw, 32px);
    border-radius: 16px;
    color: #fff;
    background: linear-gradient(135deg, #111827 0%, #1e293b 100%);
    box-shadow: 0 14px 34px rgba(15, 23, 42, .16);
}
.sg-release-version {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 800;
    line-height: 1;
    letter-spacing: -.04em;
}
.sg-release-metric {
    min-height: 100px;
    padding: 16px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 12px;
    background: rgba(255,255,255,.08);
    backdrop-filter: blur(6px);
}
.sg-release-metric span { display: block; color: rgba(255,255,255,.72); font-size: 12px; font-weight: 600; }
.sg-release-metric strong { display: block; margin-top: 8px; color: #fff; font-size: 28px; }
.sg-release-step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    color: #1d4ed8;
    background: #dbeafe;
    font-weight: 800;
}
.sg-release-upload {
    display: flex;
    min-height: 130px;
    padding: 20px;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    background: #f8fafc;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    transition: border-color .2s ease, background .2s ease, transform .2s ease;
}
.sg-release-upload:hover { border-color: #3b82f6; background: #eff6ff; transform: translateY(-1px); }
.sg-release-upload span { max-width: 100%; color: #475569; overflow-wrap: anywhere; }
.sg-release-upload small { color: #94a3b8; }
.sg-release-health {
    min-height: 84px;
    padding: 14px 16px;
    border: 1px solid var(--sg-border);
    border-radius: 11px;
    background: #f8fafc;
}
.sg-release-health span { display: block; color: var(--sg-muted); font-size: 12px; }
.sg-release-health strong { display: block; margin-top: 6px; }
.sg-release-health.is-ok { border-color: #bbf7d0; background: #f0fdf4; }
.sg-release-health.is-ok strong { color: #166534; }
.sg-release-health.is-error { border-color: #fecaca; background: #fef2f2; }
.sg-release-health.is-error strong { color: #991b1b; }
.sg-hash {
    display: inline-block;
    max-width: 100%;
    font-size: 11px;
    white-space: normal;
    overflow-wrap: anywhere;
}

@media (max-width: 575.98px) {
    .sg-release-hero { border-radius: 12px; }
    .sg-release-metric { min-height: 84px; padding: 12px; }
    .sg-release-metric strong { font-size: 24px; }
}
