/* Custom properties */
:root {
    --font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --text: #1b2433;
    --text-muted: rgba(27, 36, 51, 0.55);
    --text-light: rgba(27, 36, 51, 0.4);
    --accent: #2b39ff;
    --accent-hover: #1f2bd4;
    --bg: #f5f6f8;
    --surface: #fff;
    --border: rgba(27, 36, 51, 0.12);
    --border-focus: var(--accent);
    --danger: #cb1f05;
    --shadow-sm: 0 1px 3px rgba(27, 36, 51, 0.08);
    --shadow-md: 0 2px 10px rgba(27, 36, 51, 0.12);
    --shadow-lg: 0 4px 24px rgba(27, 36, 51, 0.16);
    --radius-sm: 3px;
    --radius: 4px;
    --radius-lg: 8px;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Full-viewport canvas */
#cube-map {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    z-index: 0;
}

#cube-map:active {
    cursor: grabbing;
}

/* Floating controls panel */
.controls-panel {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10;
    width: 340px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.controls-panel::-webkit-scrollbar {
    width: 4px;
}

.controls-panel::-webkit-scrollbar-thumb {
    background: rgba(27, 36, 51, 0.15);
    border-radius: 2px;
}

.controls-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px 20px;
    flex-shrink: 0;
}

.controls-header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
    line-height: 1.2;
}

.controls-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Search */
.search-container {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
    z-index: 1;
}

#search-input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
}

#search-input::placeholder {
    color: var(--text-light);
}

#search-input:focus {
    box-shadow: 0 0 0 2px var(--accent);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 360px;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background-color 0.15s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg);
}

.search-result-item.no-results {
    color: var(--text-muted);
    cursor: default;
}

.search-result-item.no-results:hover {
    background: transparent;
}

.search-result-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 2px;
}

.search-result-name strong {
    color: var(--accent);
    font-weight: 600;
}

.search-result-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* Cube details panel */
.cube-details {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    min-height: 0;
}

.cube-details::-webkit-scrollbar {
    width: 4px;
}

.cube-details::-webkit-scrollbar-thumb {
    background: rgba(27, 36, 51, 0.15);
    border-radius: 2px;
}

.cube-details.hidden {
    display: none;
}

.cube-details-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s;
    z-index: 2;
}

.cube-details-close:hover {
    color: var(--text);
    border-color: var(--text-light);
}

.cube-details-top {
    position: relative;
    padding: 16px;
}

.cube-details-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 2px;
    padding-right: 32px;
}

.cube-details-owner {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

.cube-details-stats {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 8px;
}

.cube-details-link {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 14px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}

.cube-details-link:hover {
    background: var(--accent);
    color: #fff;
}

.cube-details-divider {
    height: 1px;
    background: var(--border);
}

.cube-details-region {
    padding: 12px 16px;
}

.cube-details-region-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.cube-details-region-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
}

.cube-details-seed {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.cube-details-seed-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.region-select-dropdown {
    width: 100%;
    padding: 7px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.region-select-dropdown:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(43, 57, 255, 0.15);
}

/* Designer profile panel */
.designer-profile {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    min-height: 0;
    max-height: calc(100vh - 32px - 80px);
}

.designer-profile::-webkit-scrollbar {
    width: 4px;
}

.designer-profile::-webkit-scrollbar-thumb {
    background: rgba(27, 36, 51, 0.15);
    border-radius: 2px;
}

.designer-profile.hidden {
    display: none;
}

.designer-profile-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s;
    z-index: 2;
}

.designer-profile-close:hover {
    color: var(--text);
    border-color: var(--text-light);
}

.designer-profile-top {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.designer-profile-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    padding-right: 32px;
}

.designer-profile-stats {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.designer-profile-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.designer-profile-section:last-child {
    border-bottom: none;
}

.designer-profile-section h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.designer-region-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.designer-region-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.designer-region-name {
    flex: 1;
    color: var(--text);
}

.designer-region-percent {
    font-weight: 600;
    color: var(--accent);
}

.designer-region-count {
    font-size: 11px;
    color: var(--text-muted);
}

.designer-cube-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.designer-cube-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.15s;
}

.designer-cube-item:hover {
    background: var(--bg);
}

.designer-cube-item.disabled {
    cursor: default;
    color: var(--text-muted);
    font-style: italic;
}

.designer-cube-item.disabled:hover {
    background: transparent;
}

.designer-cube-name {
    flex: 1;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.designer-cube-followers {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-section-header {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.search-result-designer {
    font-weight: 500;
}

/* Seed prev/next navigation */
.cube-details-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
}

.cube-details-nav-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.cube-details-nav-btn:hover {
    color: var(--text);
    border-color: var(--text-light);
    background: var(--bg);
}

.cube-details-nav-pos {
    font-size: 11px;
    color: var(--text-muted);
}

/* Region property editing */
.cube-details-region-edit {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.region-edit-field {
    margin-bottom: 8px;
}

.region-edit-field:last-child {
    margin-bottom: 0;
}

.region-edit-label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.region-edit-input,
.region-edit-select {
    width: 100%;
    padding: 6px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.region-edit-input:focus,
.region-edit-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(43, 57, 255, 0.15);
}

.region-edit-select {
    cursor: pointer;
}

/* Regions & seeds sections */
.regions-section,
.seeds-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.regions-section summary,
.seeds-section summary {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    color: var(--text);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.regions-section summary::-webkit-details-marker,
.seeds-section summary::-webkit-details-marker {
    display: none;
}

.regions-section summary::before,
.seeds-section summary::before {
    content: '›';
    font-size: 14px;
    font-weight: 400;
    color: var(--text-muted);
    transition: transform 0.15s;
    display: inline-block;
    width: 12px;
}

.regions-section[open] > summary::before,
.seeds-section[open] > summary::before {
    transform: rotate(90deg);
}

.count-badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg);
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: auto;
}

.region-list,
.seed-list {
    padding: 0 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 240px;
    overflow-y: auto;
}

.region-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 13px;
}

.region-item--selected {
    background: rgba(43, 57, 255, 0.08);
    border: 1px solid rgba(43, 57, 255, 0.2);
}

.region-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.region-item-name {
    font-weight: 500;
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.region-item-name--clickable {
    cursor: pointer;
    transition: color 0.15s;
}

.region-item-name--clickable:hover {
    color: var(--accent);
}

.region-item-count {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.region-item-delete {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.15s;
    flex-shrink: 0;
}

.region-item-delete:hover {
    color: var(--danger);
}

.seed-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 12px;
}

.seed-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.seed-item-name {
    color: var(--text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.seed-item-name--clickable {
    cursor: pointer;
    transition: color 0.15s;
}

.seed-item-name--clickable:hover {
    color: var(--accent);
}

.seed-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.seed-item-btn {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 2px;
    transition: color 0.15s, background-color 0.15s;
}

.seed-item-btn:hover {
    color: var(--text);
    background: rgba(27, 36, 51, 0.06);
}

/* Floating toolbar */
.toolbar {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10;
    display: flex;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 4px;
}

.toolbar-btn {
    padding: 6px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.15s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: var(--bg);
}

.toolbar-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.toolbar-btn--danger:hover {
    color: var(--danger);
    background: rgba(203, 31, 5, 0.06);
}

.toolbar-btn svg {
    flex-shrink: 0;
}

/* View toggle */
.view-toggle {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.view-toggle-btn {
    padding: 4px 12px;
    background: transparent;
    border: none;
    border-radius: 2px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.view-toggle-btn:hover {
    color: var(--text);
}

.view-toggle-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(27, 36, 51, 0.1);
}

.toolbar-separator {
    width: 1px;
    background: var(--border);
    margin: 4px 2px;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 8px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    z-index: 1000;
    white-space: nowrap;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    background: var(--danger);
}

/* Dialog overlay (for region creation) */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(27, 36, 51, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.dialog {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.dialog h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
}

.dialog p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.5;
}

.dialog-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    color: var(--text);
    margin-bottom: 12px;
    outline: none;
}

.dialog-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(43, 57, 255, 0.15);
}

.dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.dialog-btn {
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: background-color 0.15s, border-color 0.15s;
}

.dialog-btn:hover {
    background: var(--bg);
    border-color: var(--text-light);
}

.dialog-btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.dialog-btn--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.dialog-btn--danger {
    color: var(--danger);
    border-color: rgba(203, 31, 5, 0.3);
}

.dialog-btn--danger:hover {
    background: rgba(203, 31, 5, 0.06);
}

/* Focus visible for accessibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input:focus-visible,
select:focus-visible {
    outline: none;
}

/* Scrollbar for search results */
.search-results::-webkit-scrollbar {
    width: 4px;
}

.search-results::-webkit-scrollbar-thumb {
    background: rgba(27, 36, 51, 0.15);
    border-radius: 2px;
}

/* Region level badges */
.region-level-badge {
    font-size: 9px;
    font-weight: 600;
    font-family: var(--font);
    padding: 1px 5px;
    border-radius: 3px;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1.4;
    transition: opacity 0.15s;
}

.region-level-badge:hover {
    opacity: 0.75;
}

.region-level-1 {
    background: #4363d8;
    color: #fff;
}

.region-level-2 {
    background: rgba(27, 36, 51, 0.1);
    color: var(--text-muted);
}

.region-level-3 {
    background: rgba(27, 36, 51, 0.05);
    color: var(--text-light);
}

/* Sidebar inline region editing */
.region-item-wrapper {
    display: flex;
    flex-direction: column;
}

.region-item-edit {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.15s;
    flex-shrink: 0;
}

.region-item-edit:hover {
    color: var(--accent);
}

.region-inline-edit {
    padding: 6px 10px 8px;
    background: var(--surface);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    margin-top: -2px;
}

.region-inline-edit.hidden {
    display: none;
}

/* Tree indentation for child regions */
.region-children {
    padding-left: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.region-item--child {
    background: rgba(27, 36, 51, 0.03);
}

/* Dialog fields */
.dialog-field {
    margin-bottom: 12px;
}

.dialog-field-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.dialog-select {
    width: 100%;
    padding: 7px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s;
}

.dialog-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(43, 57, 255, 0.15);
}

/* Responsive */
@media (max-width: 900px) {
    .controls-panel {
        width: 300px;
    }

    .toolbar {
        top: auto;
        bottom: 16px;
        right: 16px;
    }
}

@media (max-width: 600px) {
    .controls-panel {
        width: calc(100vw - 32px);
    }

    .region-list,
    .seed-list {
        max-height: 160px;
    }

    .toolbar {
        left: 16px;
        right: 16px;
        justify-content: center;
        flex-wrap: wrap;
    }
}
