/* Basic Rest (minimal since we use custom styles mostly) */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #333;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: #f5f7fa;
}

h1,
h2 {
    margin-top: 0;
}

/* Layout */
.container {
    max-width: 95%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.top-bar h1 {
    margin: 0;
    font-size: 20px;
}

/* Controls */
.controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

button {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #2980b9;
}

button:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #95a5a6;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-build {
    background-color: #e67e22;
}

.btn-build:hover {
    background-color: #d35400;
}

.btn-download {
    background-color: #27ae60;
}

.btn-download:hover {
    background-color: #219150;
}



#encryptModal input[type="text"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: monospace;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.2s;
}

.btn-danger:hover {
    background-color: #c0392b;
}

#encryptModal input[type="text"]:focus {
    outline: 2px solid #9b59b6;
    border-color: #9b59b6;
}

#encryptModal small {
    color: #7f8c8d;
    font-size: 11px;
}

.modal-small {
    max-width: 400px;
    width: 90%;
}

.modal-small .modal-content {
    padding: 20px;
}

/* Hex Panel Toolbar */
.hex-toolbar {
    display: flex;
    gap: 8px;
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    flex-wrap: wrap;
    align-items: center;
}

.btn-hex-tab {
    padding: 6px 12px;
    font-size: 12px;
    background: #ecf0f1;
    color: #7f8c8d;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-hex-tab:hover {
    background: #dfe6e9;
}

.btn-hex-tab.active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

.btn-encrypt-hex {
    margin-left: auto;
    padding: 6px 14px;
    font-size: 12px;
    background: #9b59b6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-encrypt-hex:hover {
    background: #8e44ad;
}

.btn-encrypt-hex:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.btn-copy-hex {
    padding: 6px 14px;
    font-size: 12px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copy-hex:hover {
    background: #219150;
}



#status {
    margin-left: 10px;
    font-weight: bold;
    color: #555;
}

.error {
    color: #e74c3c;
    background: #fadbd8;
    padding: 10px;
    border-radius: 4px;
}

.error:empty {
    display: none;
}

/* Output Container - Two Column Layout */
.output-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 150px);
}

.hex-panel {
    flex: 0 0 35%;
    transition: flex-basis 0.3s ease, min-width 0.3s ease, width 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.hex-panel.collapsed {
    flex: 0 0 0;
    min-width: 0;
    width: 0;
    opacity: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
    border: none;
}

.panel-header {
    background: #ecf0f1;
    padding: 10px 15px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    margin: 0;
    font-size: 16px;
    color: #2c3e50;
}

.panel-content {
    padding: 15px;
    /* Added padding back to general panel content */
    overflow-y: auto;
    flex: 1;
}

#jsonList {
    padding: 0;
    /* Remove padding for the list container */
    background: #f9f9f9;
}

/* Hex Panel Specifics */
.hex-header {
    user-select: none;
    padding: 10px 15px;
    background: #ecf0f1;
    border-bottom: 1px solid #ddd;
    margin: 0;
    font-size: 16px;
    color: #2c3e50;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hex-title {
    font-weight: 600;
}

.hex-toggle {
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: transform 0.3s, background 0.2s;
}

.hex-toggle:hover {
    background: rgba(0, 0, 0, 0.1);
}

.hex-panel.collapsed .hex-toggle {
    transform: rotate(180deg);
}

.hex-panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    /* Prevent double scrollbars */
}

#hexOutput {
    width: 100%;
    height: 100%;
    border: none;
    resize: none;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 12px;
    padding: 10px;
    box-sizing: border-box;
    background: #fdfdfd;
    white-space: pre-wrap;
    /* Allow wrapping */
    overflow-y: auto;
    /* Scroll inside the textarea */
}

/* Profile Element Item */
.pe-item {
    background: white;
    border-bottom: 1px solid #eee;
    margin-bottom: 0;
}

.pe-item:last-child {
    border-bottom: none;
}

.pe-header {
    padding: 12px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    transition: background 0.2s;
}

.pe-header:hover {
    background: #f8f9fa;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ecf0f1;
    /* Grey = Unchanged/Invisible */
    display: inline-block;
}

.status-dot.invalid {
    background-color: #e74c3c;
    /* Red */
}

.status-dot.modified {
    background-color: #2ecc71;
    /* Green */
}

.pe-title {
    color: #2c3e50;
}

.pe-type,
.pe-id {
    font-size: 0.85em;
    color: #7f8c8d;
    background: #ecf0f1;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

.badge {
    font-size: 12px;
    background: #ecf0f1;
    color: #7f8c8d;
    padding: 4px 8px;
    border-radius: 12px;
    transition: all 0.2s;
}

.badge:hover {
    background: #bdc3c7;
    color: #2c3e50;
}

.pe-body {
    display: none;
    padding: 0;
    border-top: 1px solid #f0f0f0;
}

.pe-body.open {
    display: block;
}

/* Toolbar inside PE Body */
.pe-toolbar {
    padding: 8px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    gap: 8px;
}

.pe-toolbar button {
    padding: 4px 10px;
    font-size: 12px;
}

/* Drag and Drop */
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.drag-handle {
    cursor: grab;
    font-size: 18px;
    color: #95a5a6;
    padding: 0 5px;
    user-select: none;
}

.drag-handle:hover {
    color: #3498db;
}

.drag-handle:active {
    cursor: grabbing;
}

.dragging {
    opacity: 0.5;
    background: #f0f0f0;
    border: 2px dashed #ccc;
}

.drag-over {
    border-top: 3px solid #3498db;
    transition: 0.1s;
}

/* Modal */
.modal {
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 0;
    max-width: 500px;
    width: 90%;
}

.modal::backdrop {
    background: rgba(0,0,0,0.5);
}

.modal-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal h3 {
    margin-top: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.type-def-preview {
    background: #f8f9fa;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 4px;
    max-height: 200px;
    overflow: auto;
    font-size: 12px;
}

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

.btn-view {
    background-color: #fff;
    color: #333;
    border: 1px solid #ddd;
}

.btn-view:hover {
    background-color: #f0f0f0;
}

.btn-view.active {
    background-color: #3498db;
    color: white;
    border-color: #3498db;
}

.btn-validate {
    background-color: #2ecc71;
    /* margin-left: auto; Removed, handled by btn-delete */
    /* Push to right */
}

.btn-validate:hover {
    background-color: #27ae60;
}

.btn-delete {
    background-color: #e74c3c;
    color: white;
    margin-left: auto; /* Push to right */
}

.btn-delete:hover {
    background-color: #c0392b;
}

/* Views Content */
.view-hex,
.view-asn1,
.view-asn {
    padding: 15px;
    background: #fdfdfd;
    border-bottom: 1px solid #eee;
    word-break: break-all;
    margin: 0;
}

.hex-view,
.asn-view,
.asn1-view {
    color: #2c3e50;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #eee;
    white-space: pre-wrap;      /* Key for wrapping */
    word-break: break-all;      /* Key for breaking long hex */
}



.hidden {
    display: none !important;
}

/* Placeholder */
.placeholder-text {
    text-align: center;
    color: #95a5a6;
    margin-top: 50px;
    font-style: italic;
}

/* CodeMirror Overrides */
.CodeMirror {
    height: auto;
    min-height: 100px; /* Prevent collapse on empty files */
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    overflow: hidden !important; /* Required for resize to handle visibility */
}

.CodeMirror-focused {
    outline: 2px solid #3498db;
}

.CodeMirror-scroll {
    overflow-y: scroll;
    overflow-x: auto;
}

.CodeMirror-sizer {
    min-height: 100% !important;
    border-right: 0px !important;
}