/* ============================================
   NSO Map Editor — Premium Dark Theme
   ============================================ */

:root {
    --bg-deep: #0d0d1a;
    --bg-main: #12122a;
    --bg-surface: #1a1a3a;
    --bg-elevated: #222250;
    --bg-hover: #2a2a5a;
    --bg-active: #333370;

    --border: rgba(100, 120, 200, 0.15);
    --border-active: rgba(100, 160, 255, 0.4);

    --text-primary: #e8e8f4;
    --text-secondary: #9898b8;
    --text-muted: #6868a0;

    --accent: #6c8aff;
    --accent-glow: rgba(108, 138, 255, 0.3);
    --accent-hover: #8aa4ff;

    --success: #4ade80;
    --error: #ef4444;
    --warning: #f59e0b;

    --toolbar-h: 52px;
    --sidebar-w: 260px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);

    --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset ---- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ---- App Layout ---- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ---- Toolbar ---- */
#toolbar {
    height: var(--toolbar-h);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 6px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    flex-shrink: 0;
}

.brand {
    gap: 8px;
}

.logo {
    font-size: 20px;
    color: var(--accent);
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

.app-title {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    margin: 0 4px;
}

.toolbar-spacer {
    flex: 1;
}

/* ---- Toolbar Buttons ---- */
.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.toolbar-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    flex-shrink: 0;
}

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

.toolbar-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.toolbar-btn.active:hover {
    background: var(--accent-hover);
}

.toolbar-btn.icon-only {
    padding: 6px 8px;
}

.toolbar-btn.icon-only span {
    display: none;
}

/* ---- Toolbar Select ---- */
.toolbar-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    margin-right: 4px;
}

.toolbar-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    padding: 5px 28px 5px 10px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239898b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: all var(--transition);
}

.toolbar-select:hover {
    border-color: var(--border-active);
}

.toolbar-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ---- Status Items ---- */
.status-info {
    gap: 12px;
}

.status-item {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    padding: 4px 8px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    min-width: 50px;
    text-align: center;
}

/* ---- Main Content ---- */
#main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ---- Sidebar ---- */
#sidebar {
    width: var(--sidebar-w);
    background: var(--bg-main);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
}

.sidebar-section:first-child {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.palette-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding: 0 16px;
}

.sidebar-section:first-child .sidebar-header {
    padding: 0;
}

.palette-section .sidebar-header {
    padding-top: 14px;
}

.sidebar-header h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.tile-count {
    font-size: 11px;
    color: var(--text-muted);
}

/* ---- Selected Tile Preview ---- */
.selected-tile-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tile-preview-large {
    width: 56px;
    height: 56px;
    background: var(--bg-surface);
    border: 2px solid var(--border-active);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 0 16px var(--accent-glow);
}

.tile-index-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
}

/* ---- Palette Grid ---- */
.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 3px;
    padding: 8px 12px 16px;
    overflow-y: auto;
    flex: 1;
}

.palette-grid::-webkit-scrollbar {
    width: 6px;
}

.palette-grid::-webkit-scrollbar-track {
    background: transparent;
}

.palette-grid::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

.palette-grid::-webkit-scrollbar-thumb:hover {
    background: var(--bg-active);
}

.palette-tile {
    aspect-ratio: 1;
    background: var(--bg-surface);
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    overflow: hidden;
    transition: all var(--transition);
    image-rendering: pixelated;
}

.palette-tile:hover {
    border-color: var(--text-muted);
    transform: scale(1.1);
    z-index: 2;
    box-shadow: var(--shadow-md);
}

.palette-tile.selected {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
    transform: scale(1.05);
}

/* ---- Viewport / Canvas ---- */
#viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-deep);
}

#map-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    cursor: crosshair;
}

/* ---- Dialog Overlay ---- */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.dialog-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    min-width: 340px;
    box-shadow: var(--shadow-lg);
    transform: translateY(8px);
    transition: transform 0.2s ease;
}

.dialog-overlay.visible .dialog {
    transform: translateY(0);
}

.dialog h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dialog-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 24px;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.form-row label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    width: 60px;
}

.form-row input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    padding: 8px 12px;
    transition: all var(--transition);
}

.form-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.dialog-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: -4px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-primary,
.btn-secondary {
    padding: 8px 20px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ---- Toasts ---- */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
}

.toast {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s ease;
    max-width: 320px;
}

.toast.visible {
    opacity: 1;
    transform: translateX(0);
}

.toast.error {
    border-left-color: var(--error);
}

.toast.success {
    border-left-color: var(--success);
}

/* ---- Scrollbar for body ---- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--bg-active);
    border-radius: 4px;
}

/* ---- Help Dialog ---- */
.help-dialog {
    min-width: 480px;
    max-width: 540px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.help-dialog h3 {
    margin-bottom: 0;
}

.dialog-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.dialog-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: all var(--transition);
}

.dialog-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

.help-body {
    overflow-y: auto;
    gap: 18px;
    margin-bottom: 0;
    padding-right: 4px;
}

.help-section {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    border: 1px solid var(--border);
}

.help-section h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.shortcut-row kbd {
    display: inline-block;
    min-width: 70px;
    padding: 3px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: 'Inter', monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.shortcut-row span {
    color: var(--text-secondary);
}

.help-tips {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.help-tips li {
    font-size: 13px;
    color: var(--text-secondary);
    padding-left: 16px;
    position: relative;
}

.help-tips li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
}

.help-tips kbd {
    display: inline;
    padding: 1px 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: 'Inter', monospace;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}