/* Global Styles */
:root {
    --bg-black: rgba(0, 0, 0, 0.88);
    --bg-white: rgba(255, 255, 255, 0.88);
    --bg-red: rgba(139, 0, 0, 0.88);
    --bg-orange: rgba(204, 102, 0, 0.88);
    --bg-yellow: rgba(204, 204, 0, 0.88);
    --bg-green: rgba(0, 100, 0, 0.88);
    --bg-blue: rgba(0, 0, 139, 0.88);
    --bg-purple: rgba(75, 0, 130, 0.88);
    --bg-brown: rgba(101, 67, 33, 0.88);

    --text-light: antiquewhite;
    --text-dark: #343434;

    --font-family: 'Lato', sans-serif;
}

body {
    margin: 0;
    padding: 20px;
    font-family: var(--font-family);
    background: url('../backgrounds/background.jpg') no-repeat center center fixed;
    background-size: cover;
}

/* App Container */
#app {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Zones */
#zone-top {
    width: 100%;
}

#zone-middle {
    /* CSS Columns layout for masonry-style top-to-bottom flow */
    display: block;
    column-count: 3;
    column-gap: 20px;
}

/* For Masonry via CSS columns, we need to ensure groups don't break */
#zone-middle .group-container {
    break-inside: avoid;
    margin-bottom: 20px;
}

#zone-bottom {
    width: 100%;
}

/* Responsive */
@media (max-width: 900px) {
    #zone-middle {
        column-count: 2;
    }
}

@media (max-width: 600px) {
    #zone-middle {
        column-count: 1;
    }
}


/* Group Styles */
.group-container {
    /* margin: 20px; removed, handled by break-inside/margin-bottom in zone */
    margin-bottom: 20px;
}

.group-fieldset {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin: 0;
    padding: 8px 10px 4px 10px;
    border: 1px solid rgba(255, 255, 255, 0.33);
    border-radius: 24px;
}

.group-legend {
    display: none;
    /* Default hidden as per original CSS .qlom-base32-lgnd */
    padding: 4px 12px;
    font-size: 1.1em;
    font-weight: bold;
    
    /* Tab Styling */
    background-color: inherit; /* Matches the group color */
    border: 1px solid rgba(255, 255, 255, 0.33);
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    margin-left: 15px; /* Offset from the rounded corner */
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1); 
}

/* When legends are enabled via class on body */
body.show-legends .group-legend {
    display: block;
}


/* Colors */
.bg-black {
    background-color: var(--bg-black);
    color: var(--text-light);
}

.bg-white {
    background-color: var(--bg-white);
    color: var(--text-dark);
}

.bg-red {
    background-color: var(--bg-red);
    color: var(--text-light);
}

.bg-orange {
    background-color: var(--bg-orange);
    color: var(--text-dark);
}

.bg-yellow {
    background-color: var(--bg-yellow);
    color: var(--text-dark);
}

.bg-green {
    background-color: var(--bg-green);
    color: var(--text-light);
}

.bg-blue {
    background-color: var(--bg-blue);
    color: var(--text-light);
}

.bg-purple {
    background-color: var(--bg-purple);
    color: var(--text-light);
}

.bg-brown {
    background-color: var(--bg-brown);
    color: var(--text-light);
}

/* Link/Glyph Styles */
.link-item {
    width: 50px;
    height: 50px;
    margin: 1px 2px 8px 2px;
    text-align: center;
}

.link-anchor {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 9px;
    color: inherit;
    width: 100%;
    height: 100%;
}

.link-anchor:hover {
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.link-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.link-text {
    margin-top: 1px;
    font-size: 9px;
    text-align: center;
    color: inherit;
    /* Ellipsis if too long? Original doesn't have it, but might be good. */
    white-space: nowrap;
    overflow: hidden;
    max-width: 48px;
}

/* Visibility toggles via body classes */
body.hide-labels .link-text {
    display: none;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #2c2b28;
    color: antiquewhite;
    padding: 20px;
    border-radius: 12px;
    min-width: 300px;
    max-width: 80%;
    max-height: 90%;
    overflow-y: auto;
    border: 1px solid #d4af37;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #d4af37;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.modal-close {
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.5em;
}

/* Form Elements */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-control {
    width: 100%;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #555;
    background: #444;
    color: white;
}

.btn {
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    border: none;
}

.btn-primary {
    background: #d4af37;
    color: black;
    font-weight: bold;
}

/* Footer */
.footer {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.8em;
    margin-top: 40px;
}

.footer a {
    color: inherit;
    text-decoration: none;
}

.footer a:hover {
    color: white;
}

.hint {
    opacity: 0.5;
    font-style: italic;
}

/* Editor Modal Styles */
.large-modal {
    min-width: 800px;
    height: 80vh;
    display: flex;
    flex-direction: column;
}

#editor-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
}

#editor-status {
    color: #ffd700;
}

.editor-layout {
    display: flex;
    flex: 1;
    gap: 20px;
    overflow: hidden;
}

.editor-sidebar {
    width: 250px;
    border-right: 1px solid #555;
    padding-right: 10px;
    overflow-y: auto;
}

.editor-main {
    flex: 1;
    overflow-y: auto;
    padding-left: 10px;
}

.editor-group-item {
    padding: 8px;
    cursor: pointer;
    border-bottom: 1px solid #444;
}

.editor-group-item:hover,
.editor-group-item.selected {
    background: #444;
}

.editor-link-item {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 5px;
    background: #333;
    padding: 5px;
    border-radius: 4px;
}

.form-control.sm {
    width: 80px;
}

.form-control.md {
    flex: 1;
}

.btn-icon {
    background: none;
    border: none;
    color: #ff4444;
    cursor: pointer;
    font-size: 1.2em;
}

.row {
    display: flex;
    gap: 10px;
}

.col {
    flex: 1;
}

.btn-small {
    padding: 4px 8px;
    font-size: 0.8em;
}

.btn-danger {
    background: #900;
    color: white;
}

/* Button row for multiple buttons */
.button-row {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* Validation and Error Styles */
.input-error {
    border-color: #ff4444 !important;
    box-shadow: 0 0 3px rgba(255, 68, 68, 0.5);
}

.error-text {
    color: #ff6b6b;
    font-size: 0.85em;
    margin-top: 4px;
    min-height: 1.2em;
}

.required {
    color: #ff6b6b;
}

/* Status Message Styles */
.status-saving {
    color: #ffd700;
}

.status-success {
    color: #4caf50;
}

.status-error {
    color: #ff6b6b;
}

/* Text utilities */
.text-muted {
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
}

/* Focus states for accessibility */
.form-control:focus,
.btn:focus,
.modal-close:focus {
    outline: 2px solid #d4af37;
    outline-offset: 2px;
}

/* Hover states */
.btn:hover {
    opacity: 0.9;
}

.btn-primary:hover {
    background: #e5c048;
}

.btn-danger:hover {
    background: #b00;
}

.modal-close:hover {
    color: #d4af37;
}

/* Link drag handle styling */
.link-drag-handle {
    cursor: grab;
    color: #666;
    padding: 0 5px;
    user-select: none;
}

.link-drag-handle:hover {
    color: #999;
}

/* Gray color (was missing from color definitions) */
.bg-gray {
    background-color: rgba(128, 128, 128, 0.88);
    color: var(--text-light);
}

/* ============================================
   Search Bar Styles
   ============================================ */
#search-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0 10px;
    opacity: 0;
    transition: max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease, opacity 0.3s ease;
}

#search-bar.visible {
    max-height: 80px;
    padding: 10px;
    margin-bottom: 20px;
    opacity: 1;
}

#search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 15px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 1em;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: #d4af37;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

#search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#search-clear {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px 10px;
    transition: color 0.2s;
}

#search-clear:hover {
    color: white;
}

/* No results message */
.no-results {
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.2em;
    padding: 40px;
    font-style: italic;
}

/* ============================================
   Drag and Drop Styles
   ============================================ */
.editor-group-item {
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.editor-group-item.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.editor-group-item.drag-over {
    background: #555;
    border-top: 2px solid #d4af37;
}

.editor-link-item {
    transition: background 0.2s, transform 0.1s;
}

.editor-link-item.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.editor-link-item.drag-over {
    background: #444;
    border-top: 2px solid #d4af37;
}

/* Make items look draggable */
.editor-group-item[draggable="true"],
.editor-link-item[draggable="true"] {
    cursor: grab;
}

.editor-group-item[draggable="true"]:active,
.editor-link-item[draggable="true"]:active {
    cursor: grabbing;
}

/* Small text helper */
small.text-muted {
    font-size: 0.75em;
    font-weight: normal;
}