/* THEME TOKENS */
:root {
    color-scheme: dark;

    --bg:             #0b1220;
    --bg-elev:        #111827;
    --bg-elev-2:      #1f2937;
    --bg-input:       #1f2937;
    --bg-hover:       #273449;

    --border:         #334155;
    --border-strong:  #475569;

    --text:           #e5e7eb;
    --text-muted:     #94a3b8;
    --text-dim:       #64748b;

    --primary:        #6366f1;
    --primary-hover:  #818cf8;
    --primary-soft:   rgba(99, 102, 241, 0.18);

    --danger:         #ef4444;
    --danger-bg:      #3f1d1d;
    --danger-fg:      #fca5a5;

    --success-bg:     #0f2e22;
    --success-fg:     #6ee7b7;

    --info-bg:        #1e293b;
    --info-fg:        #93c5fd;

    --shadow-sm:      0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow-md:      0 4px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg:      0 10px 40px rgba(0, 0, 0, 0.55);
}

/* RESET */
body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}

/* LAYOUT */
.layout {
    display: flex;
    height: 100vh;
}

/* SIDEBAR */
.sidebar {
    width: 220px;
    background: var(--bg-elev);
    color: var(--text);
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-right: 1px solid var(--border);
}

.logo {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 30px;
}

.nav-link {
    display: block;
    padding: 10px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 6px;
    margin-bottom: 5px;
}

.nav-link:hover {
    background: var(--bg-elev-2);
    color: var(--text);
}

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

/* MAIN AREA */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* HEADER */
.header {
    height: 60px;
    background: var(--bg-elev);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header a {
    color: var(--primary-hover);
    text-decoration: none;
}

.header a:hover {
    text-decoration: underline;
}

.header-right {
    display: flex;
    gap: 15px;
    align-items: center;
}

.lang-switcher {
    display: flex;
    gap: 4px;
}

.lang-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 2px 6px;
    transition: background 0.15s;
}

.lang-btn:hover {
    background: var(--bg-hover);
}

/* CONTENT */
.content {
    padding: 20px;
    overflow-y: auto;
}

/* CARD */
.card {
    background: var(--bg-elev);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    overflow-x: auto;
}

.card h1, .card h2, .card h3 {
    color: var(--text);
    margin-top: 0;
}

/* TABLES */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    color: var(--text);
}

.table th,
.table td {
    text-align: left;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--bg-elev-2);
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

.table th a {
    color: var(--text-muted);
    text-decoration: none;
    display: block;
    white-space: nowrap;
}

.table th a:hover {
    color: var(--text);
}

.table tbody tr:hover {
    background: var(--bg-hover);
}

.table a {
    color: var(--primary-hover);
    text-decoration: none;
}

.table a:hover {
    text-decoration: underline;
}

/* GLOBAL FORM CONTROLS */
input[type="text"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="file"],
select,
textarea {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    background: var(--bg-input);
    color: var(--text);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-dim);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

button {
    font-family: inherit;
}

/* SEARCH FORM */
.search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 4px;
}

.search-form input {
    max-width: 250px;
}

/* Make native <select> look like Select2 single select */
.search-form select {
    height: 38px;
    padding: 8px 28px 8px 12px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3e%3cpath fill='none' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 10px 6px;
}

.search-form select::-ms-expand {
    display: none;
}

.search-form select option {
    background: var(--bg-elev);
    color: var(--text);
}

.pagination {
    margin-top: 15px;
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
}

.pagination a {
    color: var(--primary-hover);
    text-decoration: none;
}

.pagination a:hover {
    text-decoration: underline;
}

.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.json-box {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.error-box {
    border-left: 4px solid var(--danger);
}

/* BUTTONS */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-elev-2);
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-cancel {
    background: var(--bg-elev-2);
    color: var(--text-muted);
}

.btn-cancel:hover {
    background: var(--bg-hover);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

/* BUILD TOOLS BAR */
.build-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 4px 0;
}

.btn-build-tool {
    background: var(--bg-elev-2);
    color: var(--text);
    border-color: var(--border);
    font-size: 13px;
    padding: 6px 14px;
}

.btn-build-tool:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    color: var(--text);
}

/* BUILD FORM */
.build-form .form-group {
    margin-bottom: 16px;
}

.build-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}

.build-form input[type="text"],
.build-form input[type="url"],
.build-form input[type="number"],
.build-form input[type="password"],
.build-form input[type="file"],
.build-form select,
.build-form textarea {
    width: 100%;
    max-width: 500px;
}

.build-form .help-text {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.build-form .field-error {
    display: block;
    margin-top: 4px;
    color: var(--danger-fg);
    font-size: 13px;
}

.build-form .has-error input,
.build-form .has-error select {
    border-color: var(--danger);
}

.build-form .form-errors {
    background: var(--danger-bg);
    border: 1px solid var(--danger);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 16px;
    color: var(--danger-fg);
}

.build-form .form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.password-field-wrapper {
    display: flex;
    gap: 8px;
    align-items: stretch;
    max-width: 500px;
}

.password-field-wrapper input {
    flex: 1;
}

.btn-toggle-password {
    padding: 8px 16px;
    background: var(--secondary-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.btn-toggle-password:hover {
    background: var(--hover-bg);
}

.icon-field-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.icon-field-row .select2-container {
    flex: 1;
}

.icon-popup-btn {
    height: 38px;
    min-width: 38px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-elev);
    color: var(--text);
    max-width: 420px;
    width: 90%;
    padding: 24px;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 16px;
}

.modal-content .form-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

/* BADGES */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success-fg);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger-fg);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info-fg);
}

/* PARAMS TABLE */
.params-table {
    width: 100%;
    border-collapse: collapse;
}

.params-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.params-table tr:last-child td {
    border-bottom: none;
}

.params-table td:first-child {
    width: 30%;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ARTIFACTS */
.artifacts-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.artifact-with-scan {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.artifact-with-scan-frame {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    background: var(--bg-elev-2);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.artifact-with-scan-frame:hover {
    border-color: var(--border-strong);
    background: var(--bg-hover);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.18);
}

.artifact-with-scan-frame .btn {
    border-color: transparent;
    background: transparent;
}

.artifact-with-scan-frame .btn:hover {
    background: var(--bg-hover);
    border-color: transparent;
}

.scan-summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border);
    background: var(--bg-elev-2);
    color: var(--text-muted);
    cursor: default;
}

button.scan-summary {
    cursor: pointer;
    line-height: 1;
}

button.scan-summary:hover {
    filter: brightness(1.08);
}

.scan-summary-success {
    border-color: #1f6f4a;
    background: rgba(34, 197, 94, 0.16);
    color: #86efac;
}

.scan-summary-danger {
    border-color: #8b2f2f;
    background: rgba(239, 68, 68, 0.16);
    color: #fca5a5;
}

.scan-modal-content {
    max-width: 680px;
}

.scan-modal-table {
    margin-top: 8px;
}

/* SELECT2 in dashboard forms */
.build-form .select2-container {
    width: 100% !important;
    max-width: 500px;
}

/* CARD ROW */
.card-row {
    display: flex;
    gap: 16px;
    margin-top: 16px;
}

.card-half {
    flex: 1;
}

.card + .card,
.card-row + .card {
    margin-top: 16px;
}

/* DATE HIERARCHY */
.date-hierarchy {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text);
}

.date-hierarchy-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    background: var(--bg-hover);
    color: var(--text);
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
}

.date-hierarchy-back:hover {
    background: var(--border);
}

.date-hierarchy-title {
    font-weight: 600;
    color: var(--text);
    margin-right: 4px;
}

.date-hierarchy-link {
    padding: 3px 10px;
    border-radius: 4px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--primary-hover);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.date-hierarchy-link:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

/* SEARCH FORM SELECT2 */
.search-form .select2-container {
    min-width: 200px;
}

/* Match Select2 look with native .search-form select */
.search-form .select2-container--default .select2-selection--single {
    height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

.search-form .select2-container--default .select2-selection--single .select2-selection__rendered {
    padding: 0;
    line-height: 1.2;
    color: var(--text);
    padding-right: 36px;
}

.search-form .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-dim);
}

.search-form .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
    top: 0;
    right: 6px;
}

.search-form .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-muted) transparent transparent transparent;
}

.search-form .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--text-muted) transparent;
}

.search-form .select2-container--default.select2-container--focus .select2-selection--single,
.search-form .select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-form .select2-container--default .select2-selection--single .select2-selection__clear {
    position: absolute;
    top: 50%;
    right: 28px;
    transform: translateY(-50%);
    margin: 0;
    padding: 0;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    font-weight: 400;
    color: var(--text-muted);
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.search-form .select2-container--default .select2-selection--single .select2-selection__clear:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* Select2 dropdown (dark) */
.select2-container--default .select2-dropdown,
.select2-dropdown {
    background: var(--bg-elev) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px;
    font-size: 14px;
    color: var(--text) !important;
    box-shadow: var(--shadow-md);
}

/* Limit dropdown height to prevent body scroll */
.select2-container--default .select2-results > .select2-results__options {
    max-height: 300px;
    overflow-y: auto;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--bg-input) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
    border-radius: 4px;
}

.select2-container--default .select2-results__option {
    color: var(--text) !important;
    background: transparent;
}

.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted {
    background-color: var(--primary);
    color: #fff;
}

.select2-container--default .select2-results__option[aria-selected=true],
.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: var(--primary) !important;
    color: #fff !important;
}

/* Global Select2 dark theme (single + multiple) */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    background: var(--bg-input) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px;
    color: var(--text) !important;
    min-height: 38px;
}

.select2-container--default .select2-selection--single {
    height: 38px !important;
    display: flex;
    align-items: center;
    padding: 0 12px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered,
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    color: var(--text) !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px !important;
    padding-left: 0 !important;
    padding-right: 28px !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
    top: 0 !important;
    right: 6px !important;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-dim) !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-muted) transparent transparent transparent;
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--text-muted) transparent;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
    background: var(--primary) !important;
    border: 1px solid var(--primary) !important;
    color: #fff !important;
    border-radius: 4px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    color: var(--text-muted);
    margin-right: 4px;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    color: var(--text);
}

.select2-container--default .select2-search--inline .select2-search__field {
    color: var(--text);
}

/* Scrollbar (WebKit) */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}
