/* =========================================================
   GLOBAL
   ========================================================= */

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;

    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    background: #f5f7fb;
    color: #172033;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease;
}


/* =========================================================
   MAIN LAYOUT
   ========================================================= */

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


/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar {
    width: 240px;
    flex-shrink: 0;

    background: #111827;
    color: white;

    display: flex;
    flex-direction: column;

    padding: 24px 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;

    margin-bottom: 40px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;

    border-radius: 10px;
    background: #2563eb;

    display: flex;
    align-items: center;
    justify-content: center;

    font-weight: 700;
}

.brand h1 {
    margin: 0;
    font-size: 18px;
}

.brand span {
    color: #9ca3af;
    font-size: 12px;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    width: 100%;

    border: 0;
    background: transparent;
    color: #cbd5e1;

    padding: 12px 14px;
    border-radius: 8px;

    text-align: left;
    cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
    background: #1f2937;
    color: white;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 24px;

    color: #64748b;
    font-size: 12px;
}


/* =========================================================
   MAIN CONTENT
   ========================================================= */

.content {
    flex: 1;
    min-width: 0;
    padding: 32px;
}


/* =========================================================
   TOP BAR
   ========================================================= */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: 20px;

    margin-bottom: 28px;
}

.topbar h2 {
    margin: 0 0 4px 0;
}

.topbar p {
    margin: 0;
    color: #64748b;
}

.status {
    flex-shrink: 0;

    background: white;

    border: 1px solid #e5e7eb;
    border-radius: 999px;

    padding: 8px 14px;

    font-size: 13px;
}

.status-dot {
    display: inline-block;

    width: 8px;
    height: 8px;

    border-radius: 50%;
    background: #22c55e;

    margin-right: 6px;
}


/* =========================================================
   SUMMARY CARDS
   ========================================================= */

.cards {
    display: grid;

    grid-template-columns:
        repeat(
            4,
            minmax(0, 1fr)
        );

    gap: 16px;

    margin-bottom: 24px;
}

.card {
    background: white;

    border: 1px solid #e5e7eb;
    border-radius: 12px;

    padding: 20px;
}

.card span {
    display: block;
    margin-bottom: 8px;

    color: #64748b;
    font-size: 13px;
}

.card strong {
    font-size: 28px;
}


/* =========================================================
   PANELS
   ========================================================= */

.panel {
    background: white;

    border: 1px solid #e5e7eb;
    border-radius: 12px;

    padding: 20px;
    margin-bottom: 20px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: 20px;

    margin-bottom: 18px;
}

.panel-header h3 {
    margin: 0;
}

.panel-header p {
    margin: 4px 0 0 0;
    color: #64748b;
}


/* =========================================================
   BUTTONS
   ========================================================= */

.primary-btn {
    border: 0;

    background: #2563eb;
    color: white;

    border-radius: 8px;

    padding: 10px 16px;

    cursor: pointer;
    white-space: nowrap;
}

.primary-btn:hover {
    background: #1d4ed8;
}

.primary-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.secondary-btn {
    border: 1px solid #d1d5db;

    background: white;
    color: #172033;

    border-radius: 8px;

    padding: 9px 14px;

    cursor: pointer;
    white-space: nowrap;
}

.secondary-btn:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #94a3b8;
}

.secondary-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.back-btn {
    border: 0;

    background: transparent;
    color: #2563eb;

    cursor: pointer;

    padding: 0;
    margin-bottom: 18px;
}

.back-btn:hover {
    text-decoration: underline;
}


/* =========================================================
   INPUTS
   ========================================================= */

input,
select {
    border: 1px solid #d1d5db;

    border-radius: 8px;

    padding: 10px 12px;

    background: white;
    color: #172033;

    outline: none;
}

input:focus,
select:focus {
    border-color: #2563eb;

    box-shadow:
        0 0 0 3px
        rgba(37, 99, 235, 0.10);
}

input::placeholder {
    color: #94a3b8;
}


/* =========================================================
   INVENTORY FILTERS
   ========================================================= */

.filters {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;

    gap: 12px;

    margin-bottom: 14px;
}

#region-filter {
    min-width: 220px;
}

#scope-filter {
    min-width: 150px;
}

#inventory-search {
    flex: 1;
    min-width: 280px;
}


/* =========================================================
   SEARCHABLE ACCOUNT FILTER
   ========================================================= */

.searchable-filter {
    position: relative;

    width: 280px;
    min-width: 260px;
}

.searchable-filter input {
    width: 100%;
}

.searchable-dropdown {
    position: absolute;

    top: calc(100% + 5px);
    left: 0;
    right: 0;

    z-index: 1000;

    max-height: 320px;
    overflow-y: auto;

    background: #ffffff;

    border: 1px solid #d8dee8;
    border-radius: 8px;

    box-shadow:
        0 8px 24px
        rgba(15, 23, 42, 0.12);
}

.searchable-dropdown-item {
    padding: 10px 12px;

    cursor: pointer;
    font-size: 14px;

    border-bottom: 1px solid #eef2f7;
}

.searchable-dropdown-item:last-child {
    border-bottom: 0;
}

.searchable-dropdown-item:hover {
    background: #f5f7fb;
}

.searchable-dropdown-item strong {
    display: block;

    font-size: 14px;
    color: #172033;
}

.searchable-dropdown-meta {
    display: block;

    margin-top: 3px;

    font-size: 12px;
    color: #64748b;
}

.searchable-dropdown-empty {
    padding: 12px;

    font-size: 13px;
    color: #64748b;
}


/* =========================================================
   INVENTORY RESULT SUMMARY
   ========================================================= */

.inventory-result-summary {
    margin-top: 2px;
    margin-bottom: 16px;

    padding-top: 2px;

    font-size: 13px;
    color: #475569;
}


/* =========================================================
   TABLES
   ========================================================= */

.table-container {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;

    padding: 12px;

    border-bottom: 1px solid #e5e7eb;

    vertical-align: middle;
}

th {
    background: #fafbfc;

    font-size: 12px;
    font-weight: 600;

    color: #64748b;

    text-transform: uppercase;
    white-space: nowrap;
}

td {
    font-size: 14px;
}

tbody tr:hover {
    background: #fafcff;
}

.action-link {
    color: #2563eb;

    cursor: pointer;

    font-weight: 600;
    white-space: nowrap;
}

.action-link:hover {
    text-decoration: underline;
}


/* =========================================================
   INVENTORY PAGINATION
   ========================================================= */

.inventory-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;

    gap: 20px;

    margin-top: 22px;
    padding-top: 16px;

    border-top: 1px solid #e5e7eb;
}

#inventory-page-info {
    display: inline-block;

    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;

    color: #64748b;
}

.inventory-pagination-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    gap: 8px;

    font-size: 12px;
    color: #64748b;
}

.inventory-pagination-actions label {
    white-space: nowrap;
}

.inventory-pagination-actions select {
    min-width: 70px;

    padding: 8px 10px;

    font-size: 13px;
}


/* =========================================================
   PROTECTED RESOURCES
   ========================================================= */

.protected-resource-cell {
    vertical-align: top;
    min-width: 220px;
}

.protected-resource-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.protected-resource-item {
    max-width: 420px;

    font-weight: 600;
    color: #172033;

    word-break: break-word;
}

.resource-refresh-link {
    display: inline-block;

    margin-top: 6px;
    padding: 0;

    border: 0;

    background: transparent;
    color: #2563eb;

    cursor: pointer;

    font-size: 12px;
    font-weight: 600;
}

.resource-refresh-link:hover {
    text-decoration: underline;
}

.resource-cache-miss {
    margin-top: 0;
    font-size: 13px;
}

.resource-none {
    color: #64748b;
    font-size: 13px;
}

.resource-error {
    color: #b91c1c;
    font-size: 13px;
}


/* =========================================================
   ACL DETAIL VIEW
   ========================================================= */

.acl-heading {
    margin-bottom: 20px;
}

.acl-heading h2 {
    margin: 0 0 4px 0;
}

.acl-heading p {
    margin: 0;
    color: #64748b;
}


/* =========================================================
   ACL TABS
   ========================================================= */

.tabs {
    display: flex;

    overflow-x: auto;

    border-bottom: 1px solid #e5e7eb;

    margin-bottom: 20px;
}

.tab {
    flex-shrink: 0;

    border: 0;

    background: transparent;

    padding: 12px 18px;

    cursor: pointer;
    color: #64748b;
}

.tab:hover {
    color: #2563eb;
}

.tab.active {
    color: #2563eb;

    border-bottom: 2px solid #2563eb;

    font-weight: 600;
}


/* =========================================================
   ACL OVERVIEW
   ========================================================= */

.detail-grid {
    display: grid;

    grid-template-columns:
        repeat(
            3,
            minmax(0, 1fr)
        );

    gap: 16px;

    margin-bottom: 20px;
}

.detail-item {
    border: 1px solid #e5e7eb;
    border-radius: 10px;

    padding: 16px;

    background: white;
}

.detail-item span {
    display: block;

    margin-bottom: 6px;

    color: #64748b;
    font-size: 12px;
}

.detail-item strong {
    display: block;
    word-break: break-word;
}


/* =========================================================
   RULE DETAILS
   ========================================================= */

#acl-rules .panel {
    margin-top: 14px;
}

#acl-rules .panel h4 {
    margin: 0 0 10px 0;
}

#acl-rules .panel p {
    margin: 6px 0 14px 0;

    color: #475569;
    line-height: 1.6;
}

#acl-rules table {
    margin-top: 8px;
}


/* =========================================================
   PER-ACL INVESTIGATION
   ========================================================= */

.log-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    gap: 12px;

    margin-top: 18px;
    margin-bottom: 18px;
}

.log-filters select,
.log-filters input {
    min-width: 170px;
}

#log-client-ip {
    min-width: 210px;
}

.quick-queries {
    display: flex;
    align-items: center;
    flex-wrap: wrap;

    gap: 10px;

    margin-bottom: 18px;
}

.quick-results {
    margin-bottom: 20px;
}


/* =========================================================
   METRICS
   ========================================================= */

#metric-results {
    margin-top: 18px;
}


/* =========================================================
   CODE / JSON OUTPUT
   ========================================================= */

pre {
    max-width: 100%;
    overflow-x: auto;

    white-space: pre-wrap;
    word-break: break-word;

    background: #f8fafc;

    border: 1px solid #e5e7eb;

    padding: 14px;
    border-radius: 8px;

    font-family:
        "SFMono-Regular",
        Consolas,
        "Liberation Mono",
        monospace;

    font-size: 12px;
    line-height: 1.5;
}

/* =========================================================
   INVESTIGATION RESOURCE CONTEXT
   ========================================================= */

#investigation-resource {
    width: 100%;
}


.investigation-resource-result {
    min-width: 220px;

    max-width: 320px;

    font-weight: 500;

    line-height: 1.5;

    word-break: break-word;
}


#investigation-uri-match {
    min-width: 160px;
}

/* =========================================================
   ADVANCED WAF INVESTIGATION
   ========================================================= */

#investigation-view {
    width: 100%;
}

.investigation-notice {
    margin-bottom: 18px;

    padding: 12px 14px;

    border: 1px solid #fde68a;
    border-radius: 8px;

    background: #fffbeb;
    color: #92400e;

    font-size: 13px;
    line-height: 1.5;
}

.investigation-date-filters {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;

    gap: 14px;
}

.investigation-date-filters > div {
    display: flex;
    flex-direction: column;

    gap: 6px;
}

.investigation-date-filters label {
    font-size: 12px;
    font-weight: 600;

    color: #64748b;
}

.investigation-date-filters input {
    min-width: 180px;
}

.investigation-summary-grid {
    display: grid;

    grid-template-columns:
        repeat(
            6,
            minmax(0, 1fr)
        );

    gap: 14px;

    margin-bottom: 20px;
}

.investigation-summary-grid .card {
    margin-bottom: 0;
}

.investigation-summary-grid .card strong {
    font-size: 26px;
}

.investigation-grid {
    display: grid;

    grid-template-columns:
        repeat(
            2,
            minmax(0, 1fr)
        );

    gap: 20px;
}

.investigation-grid .panel {
    min-width: 0;
}

.investigation-grid h3 {
    margin-top: 0;
}

.investigation-result-placeholder {
    margin-top: 12px;

    color: #64748b;
    font-size: 13px;
}

.investigation-event-filters {
    display: grid;

    grid-template-columns:
        repeat(
            5,
            minmax(
                160px,
                1fr
        )
    );

    gap: 12px;

    margin-bottom: 18px;
}

.investigation-event-filters input,
.investigation-event-filters select {
    width: 100%;
    min-width: 0;
}

#investigation-events-container {
    margin-top: 12px;
}

#investigation-events-container table {
    min-width: 1200px;
}

#investigation-events-container td {
    vertical-align: top;
}

#investigation-events-container td:nth-child(8),
#investigation-events-container td:nth-child(10) {
    max-width: 320px;
    word-break: break-word;
}

.investigation-action {
    display: inline-block;

    padding: 3px 8px;

    border-radius: 999px;

    font-size: 11px;
    font-weight: 700;
}

.investigation-action-block {
    background: #fee2e2;
    color: #991b1b;
}

.investigation-action-allow {
    background: #dcfce7;
    color: #166534;
}

.investigation-action-count {
    background: #fef3c7;
    color: #92400e;
}

.investigation-action-captcha,
.investigation-action-challenge {
    background: #dbeafe;
    color: #1e40af;
}

.investigation-action-unknown {
    background: #f1f5f9;
    color: #475569;
}

.investigation-sql-warning {
    margin-bottom: 12px;

    padding: 10px 12px;

    border: 1px solid #dbeafe;
    border-radius: 8px;

    background: #eff6ff;
    color: #1e40af;

    font-size: 12px;
}

.investigation-sql-editor {
    width: 100%;
    min-height: 240px;

    resize: vertical;

    padding: 14px;

    border: 1px solid #334155;
    border-radius: 8px;

    background: #0f172a;
    color: #e2e8f0;

    font-family:
        "SFMono-Regular",
        Consolas,
        "Liberation Mono",
        monospace;

    font-size: 13px;
    line-height: 1.55;

    outline: none;
    tab-size: 4;
}

.investigation-sql-editor:focus {
    border-color: #2563eb;

    box-shadow:
        0 0 0 3px
        rgba(37, 99, 235, 0.10);
}

.investigation-sql-editor::placeholder {
    color: #94a3b8;
}

.investigation-sql-actions {
    display: flex;

    gap: 10px;

    margin-top: 12px;
    margin-bottom: 12px;
}

#investigation-sql-results {
    margin-top: 14px;
}

#investigation-sql-results table {
    min-width: 800px;
}

.investigation-empty {
    color: #64748b;
    font-size: 13px;
}


/* =========================================================
   UTILITY
   ========================================================= */

.hidden {
    display: none !important;
}


/* =========================================================
   RESPONSIVE — MEDIUM SCREENS
   ========================================================= */

@media (max-width: 1400px) {
    .investigation-summary-grid {
        grid-template-columns:
            repeat(
                3,
                minmax(0, 1fr)
            );
    }

    .investigation-event-filters {
        grid-template-columns:
            repeat(
                2,
                minmax(
                    180px,
                    1fr
                )
            );
    }
}

@media (max-width: 1200px) {
    .cards {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );
    }

    .detail-grid {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );
    }

    #inventory-search {
        flex-basis: 100%;
    }
}


/* =========================================================
   RESPONSIVE — TABLET
   ========================================================= */

@media (max-width: 900px) {
    .sidebar {
        width: 200px;
    }

    .content {
        padding: 24px;
    }

    .topbar {
        align-items: flex-start;
    }

    .inventory-pagination {
        align-items: flex-start;
        flex-direction: column;
    }

    .inventory-pagination-actions {
        width: 100%;
    }

    .searchable-filter,
    #region-filter,
    #scope-filter,
    #inventory-search {
        width: 100%;
        min-width: 100%;
    }

    .detail-grid {
        grid-template-columns:
            1fr;
    }

    .investigation-grid {
        grid-template-columns:
            1fr;
    }

    .investigation-summary-grid {
        grid-template-columns:
            repeat(
                2,
                minmax(0, 1fr)
            );
    }

    .investigation-event-filters {
        grid-template-columns:
            1fr;
    }

    .investigation-date-filters {
        align-items: stretch;
        flex-direction: column;
    }

    .investigation-date-filters input {
        width: 100%;
    }
}


/* =========================================================
   RESPONSIVE — SMALL SCREENS
   ========================================================= */

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

    .sidebar {
        width: 100%;
        min-height: auto;

        padding: 16px;
    }

    .brand {
        margin-bottom: 18px;
    }

    nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .nav-item {
        width: auto;
    }

    .sidebar-footer {
        margin-top: 18px;
        padding-top: 0;
    }

    .content {
        padding: 18px;
    }

    .topbar {
        flex-direction: column;
        margin-bottom: 20px;
    }

    .cards {
        grid-template-columns:
            1fr;
    }

    .panel {
        padding: 16px;
    }

    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .filters,
    .log-filters {
        flex-direction: column;
    }

    .filters > *,
    .log-filters > * {
        width: 100%;
    }

    .searchable-filter,
    #region-filter,
    #scope-filter,
    #inventory-search,
    .log-filters select,
    .log-filters input,
    #log-client-ip {
        width: 100%;
        min-width: 100%;
    }

    .inventory-pagination-actions {
        align-items: flex-start;
    }

    .tabs {
        width: 100%;
    }

    .investigation-summary-grid {
        grid-template-columns:
            1fr;
    }
}
