/* ===== TouchDial Folder Builder — Dark Theme ===== */

/* WordPress theme reset — prevent theme styles from leaking in */
.td-folder-builder-wrap,
.td-folder-builder-wrap *,
.td-folder-builder-wrap *::before,
.td-folder-builder-wrap *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
.td-folder-builder-wrap img {
    max-width: none !important;
    height: auto;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    margin: 0 !important;
    padding: 0 !important;
}
.td-folder-builder-wrap {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    color: var(--text-primary) !important;
}

:root {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-card: #2a2a2a;
    --bg-slot: #333333;
    --bg-slot-hover: #3a3a3a;
    --bg-slot-active: #444444;
    --bg-input: #1e1e1e;
    --bg-panel: #262626;
    --border-color: #3a3a3a;
    --border-focus: #2196F3;
    --text-primary: #e0e0e0;
    --text-secondary: #999;
    --text-muted: #666;
    --accent: #2196F3;
    --accent-hover: #1e88e5;
    --accent-dim: rgba(33, 150, 243, 0.15);
    --danger: #f44336;
    --danger-hover: #d32f2f;
    --success: #4caf50;
    --warning: #ff9800;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ===== Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: none;
    position: sticky;
    top: 0;
    z-index: 100;
    max-width: 1200px;
    margin: 0 auto;
}

.header-left {
    flex: 0 0 auto;
}

.header-logo {
    display: flex;
    align-items: center;
}
.header-logo img {
    height: 36px;
    width: auto;
    transition: opacity var(--transition);
}
.header-logo:hover img { opacity: 0.8; }

.header-center {
    flex: 1;
    text-align: left;
    min-width: 0;
}

.app-header h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    gap: 10px;
    flex: 0 0 auto;
}

/* Download dropdown */
.download-wrapper {
    position: relative;
}
.download-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 150;
    overflow: hidden;
    min-width: 180px;
}
.download-option {
    display: block;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition);
}
.download-option:hover { background: var(--bg-slot-hover); }
.download-option + .download-option { border-top: 1px solid var(--border-color); }

/* ===== Buttons ===== */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-slot);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-slot-hover); }

.btn-primary {
    background: #1a78c8;
    border-color: #1a78c8;
    color: #fff;
    font-weight: 500;
}
.btn-primary:hover { background: #1565a8; }

.btn-accent {
    background: #388e3c;
    border-color: #388e3c;
    color: #fff;
    font-weight: 500;
}
.btn-accent:hover { background: #2e7d32; }

.btn-import {
    background: #6a1b9a;
    border-color: #6a1b9a;
    color: #fff;
    font-weight: 500;
}
.btn-import:hover { background: #5c1690; }

.btn-danger {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-muted {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-secondary);
}
.btn-muted:hover { background: var(--bg-slot); color: var(--text-primary); }

.btn-small { padding: 4px 10px; font-size: 12px; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-slot); }

/* ===== Main Content ===== */
.app-main {
    padding: 24px;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 16px; }
.empty-state strong { color: var(--text-secondary); }

/* ===== Folder Card ===== */
/* ===== Folder Container — 2-up layout ===== */
.folders-container {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center;
}

.folder-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    flex: 0 0 auto;
}

.folder-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}

.folder-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 2px dashed var(--border-color);
    background: var(--bg-slot);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: border-color var(--transition);
    flex-shrink: 0;
}
.folder-icon-btn:hover { border-color: var(--accent); }
.folder-icon-btn img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.folder-name-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    outline: none;
    transition: border-color var(--transition);
}
.folder-name-input:focus { border-color: var(--accent); }

.folder-color-swatches {
    display: flex;
    gap: 6px;
    align-items: center;
}
.folder-color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    padding: 0;
    position: relative;
}
.folder-color-swatch:hover { transform: scale(1.15); }
.folder-color-swatch.selected { border-color: #fff; }
.folder-color-swatch.selected::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.folder-count {
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}

.folder-delete-btn { color: var(--text-muted); }
.folder-delete-btn:hover { color: var(--danger); background: rgba(244, 67, 54, 0.1); }

/* ===== Button Grid ===== */
.button-grid {
    display: grid;
    grid-template-columns: repeat(4, 140px);
    gap: 6px;
    padding: 16px;
    width: fit-content;
}

.button-slot {
    aspect-ratio: 1;
    width: 100%;
    background: var(--bg-slot);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.button-slot:hover {
    border-color: var(--accent);
    background: var(--bg-slot-hover);
}
.button-slot.active {
    border-color: var(--accent);
    border-style: solid;
    background: var(--accent-dim);
}
.button-slot.configured {
    border-style: solid;
    border-color: var(--border-color);
}
.button-slot.configured:hover {
    border-color: var(--accent);
}
.button-slot[draggable="true"] {
    cursor: grab;
}
.button-slot[draggable="true"]:active {
    cursor: grabbing;
}

.slot-icon {
    width: 44px;
    height: 44px;
    object-fit: contain;
}

.slot-name {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.slot-placeholder {
    font-size: 20px;
    color: var(--text-muted);
}

.slot-clear {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
    border: none;
}
.button-slot:hover .slot-clear { opacity: 1; }

/* ===== Editor Panel ===== */
.editor-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
}
.editor-overlay.hidden { display: none; }

.editor-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100%;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    z-index: 300;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 16px rgba(0,0,0,0.4);
    transform: translateX(0);
    transition: transform 0.3s ease;
}
.editor-panel.hidden {
    transform: translateX(100%);
    pointer-events: none;
}

.editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.editor-header h2 { font-size: 16px; font-weight: 600; }

.editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.editor-section {
    margin-bottom: 20px;
}
.editor-section > label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.editor-actions {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
}
.editor-actions .btn { flex: 1; }

/* ===== Form Inputs ===== */
input[type="text"],
input[type="url"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

.color-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.color-row input[type="text"] { flex: 1; }

/* ===== Icon Picker ===== */
.icon-picker {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.icon-picker-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}
.icon-picker-tab {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    cursor: pointer;
    border: none;
    transition: all var(--transition);
}
.icon-picker-tab.active {
    background: var(--bg-slot);
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}

.icon-search {
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
}
.icon-search input {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
}

.icon-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.icon-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-slot);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 6px;
    transition: all var(--transition);
}
.icon-item:hover { border-color: var(--accent); background: var(--bg-slot-hover); }
.icon-item.selected { border-color: var(--accent); background: var(--accent-dim); }
.icon-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.icon-selected-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}
.icon-selected-preview img {
    width: 32px;
    height: 32px;
}
.icon-selected-preview span {
    color: var(--text-secondary);
    font-size: 12px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
    margin: 8px;
}
.icon-drop-zone:hover,
.icon-drop-zone.dragover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

/* ===== Action Picker ===== */
.action-picker {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.action-type-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
}

.action-type-btn {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-slot);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.action-type-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.action-type-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.action-config {
    padding: 12px;
}

.action-config h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.action-config p {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.action-result {
    padding: 8px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.action-result-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.action-result-value {
    font-size: 12px;
    color: var(--success);
    font-family: 'Consolas', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* Multimedia grid */
.media-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}
.media-btn {
    padding: 8px;
    font-size: 12px;
    text-align: center;
    background: var(--bg-slot);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
}
.media-btn:hover { border-color: var(--accent); background: var(--bg-slot-hover); }
.media-btn.selected { border-color: var(--accent); background: var(--accent-dim); }

/* Feature toggle buttons */
.feature-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}
.feature-btn {
    padding: 10px 8px;
    font-size: 12px;
    text-align: center;
    background: var(--bg-slot);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
}
.feature-btn:hover { border-color: var(--accent); }
.feature-btn.selected { border-color: var(--accent); background: var(--accent-dim); }

/* Timer config */
.timer-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.timer-row input[type="number"] {
    width: 60px;
    text-align: center;
}
.timer-row span { color: var(--text-muted); font-size: 12px; }

/* Radio group */
.radio-group {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
}
.radio-group label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}
.radio-group input[type="radio"] { accent-color: var(--accent); }

/* Checkbox row */
.checkbox-row {
    display: flex;
    gap: 16px;
    margin-top: 8px;
}
.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}
.checkbox-row input[type="checkbox"] { accent-color: var(--accent); }

/* Hotkey display */
.hotkey-display {
    padding: 12px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    text-align: center;
    font-family: 'Consolas', monospace;
    font-size: 16px;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color var(--transition);
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.hotkey-display.recording {
    border-color: var(--danger);
    animation: pulse 1s ease-in-out infinite;
}
.hotkey-display .placeholder { color: var(--text-muted); font-family: inherit; font-size: 13px; }

@keyframes pulse {
    0%, 100% { border-color: var(--danger); }
    50% { border-color: var(--warning); }
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* Override hidden for panel slide animation */
.editor-panel.hidden {
    display: flex !important;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .editor-panel { width: 100%; }
}
@media (max-width: 700px) {
    .button-grid {
        grid-template-columns: repeat(4, 1fr);
        width: 100%;
    }
    .folder-card { flex: 1 1 100%; }
}
@media (max-width: 768px) {
    .app-header { flex-direction: column; gap: 10px; padding: 12px; }
    .header-center { order: -1; }
    .header-right { width: 100%; flex-wrap: wrap; justify-content: center; }
    .header-right .btn { flex: 1; min-width: 100px; }
}
@media (max-width: 500px) {
    .app-main { padding: 12px; }
    .folder-header { flex-wrap: wrap; }
}
