:root {
    --bg: #e7eef6;
    --bg-accent: #f8fbff;
    --sidebar-bg: linear-gradient(180deg, #0f2238 0%, #122b46 48%, #16365a 100%);
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --panel-bg: #ffffff;
    --panel-border: #d6e3f1;
    --text: #13243a;
    --muted: #5f728a;
    --primary: #0f6cbd;
    --primary-dark: #0a518f;
    --accent: #1f9d8b;
    --warn: #d97706;
    --danger: #c2410c;
    --active-bg: linear-gradient(90deg, rgba(15, 108, 189, 0.34) 0%, rgba(31, 157, 139, 0.18) 100%);
    --shadow-soft: 0 18px 38px rgba(14, 35, 63, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background:
        radial-gradient(circle at top left, #fbfdff 0%, rgba(251, 253, 255, 0) 32%),
        radial-gradient(circle at right 12%, rgba(31, 157, 139, 0.12) 0%, rgba(31, 157, 139, 0) 28%),
        linear-gradient(180deg, var(--bg-accent) 0%, var(--bg) 100%);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: relative;
    width: 300px;
    background: var(--sidebar-bg);
    color: #f8fbff;
    padding: 18px 14px 24px;
    border-right: 1px solid var(--sidebar-border);
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.03);
    overflow: visible;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 20px;
    padding: 10px 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    width: 100%;
}

.brand-mark {
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    overflow: hidden;
}

.brand-mark img {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.brand-mark-full {
    width: 152px;
    padding: 6px 10px;
    justify-content: flex-start;
}

.brand-mark-icon {
    width: 48px;
    flex: 0 0 48px;
    display: none;
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-title {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.7px;
    color: #f4f8ff;
    white-space: nowrap;
}

.brand-subtitle {
    font-size: 11px;
    color: #b3c4db;
    white-space: nowrap;
}

.sidebar-collapse-btn {
    position: absolute;
    top: 50%;
    right: -16px;
    transform: translateY(-50%);
    border: 1px solid #d8e6f3;
    background: linear-gradient(180deg, #ffffff 0%, #eff6fb 100%);
    color: var(--primary);
    font-size: 14px;
    width: 34px;
    height: 72px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 24px rgba(16, 35, 68, 0.14);
    z-index: 5;
    padding: 0;
}

.sidebar-collapse-btn:hover {
    background: linear-gradient(180deg, #ffffff 0%, #e6f1fb 100%);
}

.sidebar-collapse-btn i {
    transition: transform 0.25s ease;
}

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

.tree > li {
    margin: 4px 0;
}

.tree li a,
.tree-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 12px;
    color: #e8eef9;
    border-radius: 14px;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    border: 0;
    background: transparent;
    text-align: left;
    font-weight: 500;
}

.tree li a i,
.tree-toggle i {
    width: 18px;
    text-align: center;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.menu-label {
    white-space: nowrap;
}

.tree-toggle .tree-chevron {
    margin-left: auto;
}

.tree li a:hover,
.tree-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.tree li a.active {
    background: var(--active-bg);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 10px 18px rgba(5, 16, 31, 0.18);
}

.tree-item.is-open > .tree-toggle {
    background: rgba(255, 255, 255, 0.08);
}

.tree-chevron {
    transition: transform 0.25s ease;
}

.tree-item.is-open .tree-chevron {
    transform: rotate(180deg);
}

.tree-submenu {
    padding-left: 16px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-4px);
    transition: max-height 0.3s ease, opacity 0.25s ease, transform 0.25s ease;
}

.tree-submenu.expanded {
    max-height: 600px;
    opacity: 1;
    transform: translateY(0);
}

.sidebar.is-collapsed {
    width: 86px;
    padding: 18px 8px;
}

.sidebar.is-collapsed .brand-text {
    display: none;
}

.sidebar.is-collapsed .brand-mark-full {
    display: none;
}

.sidebar.is-collapsed .brand-mark-icon {
    display: grid;
}

.sidebar.is-collapsed .tree li a,
.sidebar.is-collapsed .tree-toggle {
    justify-content: center;
    padding: 10px 8px;
}

.sidebar.is-collapsed .tree li a i,
.sidebar.is-collapsed .tree-toggle i {
    width: 20px;
}

.sidebar.is-collapsed .menu-label,
.sidebar.is-collapsed .tree-chevron {
    display: none !important;
}

.sidebar.is-collapsed .tree li a,
.sidebar.is-collapsed .tree-toggle {
    padding: 10px 6px;
}

.sidebar.is-collapsed .menu-item {
    justify-content: center;
    gap: 0;
}

.sidebar.is-collapsed .tree-submenu {
    display: none !important;
}

.sidebar.is-collapsed .sidebar-collapse-btn i {
    transform: rotate(180deg);
}

.main {
    flex: 1;
    padding: 24px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    padding: 14px 18px;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(10px);
}

.role-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: #e6efff;
    color: #1b4ca3;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.logout-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #b91c1c;
    font-weight: 600;
}

.logout-link:hover {
    color: #7f1d1d;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lang-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 30px;
    border-radius: 8px;
    border: 1px solid #d6e2f1;
    color: #3b4f68;
    font-size: 12px;
    font-weight: 700;
    background: #f5f9ff;
}

.lang-link.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.section {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 18px;
    padding: 18px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-soft);
    animation: rise 0.25s ease;
}

.section h1,
.section h2,
.section h3 {
    letter-spacing: -0.02em;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert {
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
}

th,
td {
    border: 1px solid #e4ebf5;
    padding: 10px;
    text-align: left;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}

th {
    background: linear-gradient(180deg, #f7fbff 0%, #eef5fb 100%);
    color: #24364f;
}

input,
select,
button,
textarea {
    border-radius: 10px;
}

button {
    border: 0;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    padding: 10px 12px;
    box-shadow: 0 8px 18px rgba(15, 108, 189, 0.22);
}

button:hover {
    background: var(--primary-dark);
}

.btn {
    border-radius: 12px;
    font-weight: 600;
}

.badge {
    border-radius: 999px;
    padding: 0.5rem 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.tab-button {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    background: #dbeafe;
    color: #1e3a8a;
}

.tab-button.active {
    background: var(--primary);
    color: #fff;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.inline-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.inline-controls .input,
.inline-controls .form-control {
    margin: 0;
}

.inline-controls button {
    width: auto;
    margin: 0;
}

.ou-tree ul {
    list-style: none;
    margin: 6px 0 6px 16px;
    padding: 0;
}

.ou-label {
    margin-left: 8px;
}

.small-button {
    width: auto;
    margin: 0;
    padding: 4px 8px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
    margin-top: 6px;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid #c7d5e6;
    border-radius: 10px;
    padding: 6px 8px;
    background: #fff;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 10px !important;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    color: var(--muted);
    margin-bottom: 8px;
}

.dataTables_wrapper table.dataTable tbody td {
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: top;
}

.log-message-preview {
    max-width: 560px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.35;
}

.log-detail-pre {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    background: #f8fafc;
    border: 1px solid #dbe6f2;
    border-radius: 10px;
    padding: 12px;
    margin: 0;
}

.login-wrapper {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        radial-gradient(circle at left top, rgba(15, 108, 189, 0.18) 0%, rgba(15, 108, 189, 0) 34%),
        radial-gradient(circle at right bottom, rgba(31, 157, 139, 0.14) 0%, rgba(31, 157, 139, 0) 28%),
        linear-gradient(180deg, #edf4fb 0%, #e3edf7 100%);
}

.login-panel {
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 24px 56px rgba(15, 39, 78, 0.16);
}

.brand-icon,
.brand-logo-panel {
    display: grid;
    place-items: center;
}

.brand-logo-panel {
    min-height: 58px;
}

.brand-logo-panel img {
    max-width: 220px;
    width: 100%;
    height: auto;
    object-fit: contain;
}

.login-panel h1 {
    margin: 0;
    font-size: 24px;
}

.login-subtext {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.login-helper-links {
    margin-top: 16px;
    text-align: center;
}

.login-helper-links a {
    color: var(--primary);
    font-weight: 600;
}

.login-helper-links a:hover {
    color: var(--primary-dark);
}

.inventory-table td .btn {
    margin-right: 4px;
}

.inventory-detail-header {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.inventory-stat-card {
    border: 1px solid #d6e3f4;
    border-radius: 14px;
    background: linear-gradient(165deg, #ffffff 0%, #f6faff 100%);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.inventory-stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), #22a6f2);
}

.inventory-stat-label {
    color: var(--muted);
    font-size: 12px;
}

.inventory-stat-value {
    font-weight: 700;
    word-break: break-word;
}

.inventory-visuals {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 14px;
}

.inventory-chart-card {
    border: 1px solid #d6e3f4;
    border-radius: 16px;
    background: #fff;
    padding: 14px;
}

.inventory-chart-card h3 {
    margin: 0 0 10px;
    font-size: 16px;
}

.inventory-tabs .nav-link {
    font-weight: 600;
}

.inventory-tab-content {
    border: 1px solid #d6e3f4;
    border-top: 0;
    border-radius: 0 0 16px 16px;
    background: #fff;
}

.inventory-section-card {
    padding: 14px;
}

.inventory-section-card h4 {
    font-size: 16px;
    margin-bottom: 10px;
}

.inventory-kv-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inventory-kv-row {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 10px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #e5edf8;
    background: #fafcff;
}

.inventory-kv-key {
    font-weight: 700;
    color: #2d3f59;
    overflow-wrap: anywhere;
}

.inventory-kv-value,
.inventory-kv-val {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.inventory-subtable th,
.inventory-subtable td {
    font-size: 12px;
}

.inventory-list {
    margin: 0;
    padding-left: 18px;
}

.inventory-list li {
    margin-bottom: 3px;
}

.inventory-more-note {
    color: var(--muted);
    font-size: 12px;
    margin-top: 8px;
}

.inventory-empty {
    color: var(--muted);
}

.inventory-json {
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 10px;
    padding: 10px;
}

.inventory-metric-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.inventory-metric-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border: 1px solid #e5edf8;
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 8px;
    background: #fafcff;
}

.inventory-metric-list li span {
    font-weight: 700;
}

@media (max-width: 991px) {
    .layout {
        display: block;
    }

    .sidebar {
        width: 100%;
        border-right: 0;
        border-bottom: 1px solid var(--sidebar-border);
        padding-right: 14px;
    }

    .sidebar:not(.is-open) .tree {
        display: none;
    }

    .sidebar.is-collapsed {
        width: 100%;
        padding: 18px 14px;
    }

    .sidebar.is-collapsed .brand-text {
        display: flex;
    }

    .sidebar.is-collapsed .brand-mark-full {
        display: grid;
    }

    .sidebar.is-collapsed .brand-mark-icon {
        display: none;
    }

    .sidebar.is-collapsed .menu-label,
    .sidebar.is-collapsed .tree-chevron {
        display: inline !important;
    }

    .sidebar.is-collapsed .tree-submenu {
        display: block !important;
    }

    .main {
        padding: 14px;
    }

    .sidebar-collapse-btn {
        top: 20px;
        right: 14px;
        transform: none;
        width: 42px;
        height: 42px;
        border-radius: 12px;
    }

    .sidebar.is-collapsed .sidebar-collapse-btn i {
        transform: none;
    }

    .inventory-visuals {
        grid-template-columns: 1fr;
    }

    .inventory-kv-row {
        grid-template-columns: 1fr;
    }
}
