:root {
    --primary: #9d8cff;
    --primary-dark: #7a6bdb;
    --accent: #64d2ff;
    --accent-dark: #4fb8e6;
    --white: #FFFFFF;
    --bg-body: #1e1e2a;
    --bg-panel: #2d2d3a;
    --bg-input: #3d3d4a;
    --bg-hover: #4d4d5a;
    --border: #4d4d5a;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --danger: #ff6b6b;
    --danger-dark: #e55a5a;
    --focus-ring: 0 0 0 3px rgba(157, 140, 255, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Skip link for keyboard navigation */
.skip-link {
    position: absolute;
    top: -50px;
    left: 0;
    background: var(--accent);
    color: var(--bg-body);
    padding: 0.75rem 1.5rem;
    z-index: 1000;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

header {
    background-color: var(--bg-panel);
    color: var(--text-primary);
    padding: 1.5rem 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
}

header svg {
    width: 40px;
    height: 40px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.save-indicator {
    margin-left: auto;
    font-size: 0.875rem;
    color: var(--accent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-indicator.visible {
    opacity: 1;
}

.container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: start;
    gap: 1.5rem;
    padding: 1.5rem;
}


.panel {
    background: var(--bg-panel);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    overflow: hidden;
    border: 1px solid var(--border);
}

.panel-header {
    background: var(--bg-input);
    padding: 1rem 1.5rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.panel-body {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

label small {
    font-weight: 400;
    color: var(--text-secondary);
}

input[type="text"],
input[type="url"],
input[type="number"],
select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--bg-input);
    color: var(--text-primary);
}

input.empty-warning {
    border-color: var(--danger);
    background-color: rgba(255, 107, 107, 0.1);
}

input[type="text"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

input[type="text"]:focus-visible,
input[type="url"]:focus-visible,
input[type="number"]:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 1px;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-group input[type="checkbox"]:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.checkbox-group label {
    margin-bottom: 0;
    cursor: pointer;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--bg-body);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-primary:focus-visible {
    outline-color: var(--accent);
}

.btn-secondary {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-danger {
    background-color: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background-color: var(--danger-dark);
}

.btn-danger:focus-visible {
    outline-color: var(--danger);
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    min-height: 36px;
    min-width: 36px;
}

.btn-generate {
    background-color: var(--accent);
    color: var(--bg-body);
    font-weight: 600;
    padding: 0.875rem 2rem;
    font-size: 1rem;
    min-height: 44px;
}

.btn-generate:hover {
    background-color: var(--accent-dark);
}

.btn-generate:focus-visible {
    outline-color: var(--primary);
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .btn,
    input[type="text"],
    input[type="url"] {
        transition: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    input[type="text"],
    input[type="url"] {
        border-width: 2px;
    }
}

/* Visually hidden but accessible to screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Groups Section */
.groups-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.group-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    padding: 0;
    margin: 0;
    background: var(--bg-input);
}

.group-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border);
}

.group-header input {
    flex: 1;
    font-weight: 500;
}

.group-icon-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.group-icon-label {
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0;
    white-space: nowrap;
}

.group-icon-row input[type="url"] {
    flex: 1;
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
}

.group-icon-row .btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.group-links {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.link-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.link-row input {
    flex: 1;
    min-width: 120px;
}

.link-row input:first-of-type {
    max-width: 35%;
}

.link-row select.link-type-select {
    width: 65px;
    flex: 0 0 auto;
    font-size: 0.75rem;
    padding: 0.375rem 0.25rem;
    border-radius: 4px;
}

/* Drag and drop styles */
.drag-handle {
    cursor: grab;
    padding: 0.25rem;
    color: var(--text-secondary);
    font-size: 1rem;
    user-select: none;
    display: flex;
    align-items: center;
}

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

.group-card.dragging,
.link-row.dragging {
    opacity: 0.5;
    background: var(--bg-hover);
}

.group-card.drag-over {
    border: 2px dashed var(--primary);
    background: rgba(157, 140, 255, 0.1);
}

.link-row.drag-over {
    border-top: 2px solid var(--primary);
}

/* Collapsible sections */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 0.5rem 0;
    user-select: none;
}

.section-header:hover {
    opacity: 0.8;
}

.section-header h3,
.section-header legend {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.collapse-icon {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}

.section-header.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.section-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    max-height: 2000px;
    opacity: 1;
}

.section-content.collapsed {
    max-height: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
}

@media (prefers-reduced-motion: reduce) {
    .collapse-icon,
    .section-content {
        transition: none;
    }
}

/* Input validation */
input.invalid {
    border-color: var(--danger);
    background-color: rgba(255, 107, 107, 0.1);
}

input.invalid:focus {
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.3);
}

.validation-error {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 0.25rem;
    display: none;
}

.validation-error.visible {
    display: block;
}

.empty-message {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

.actions-bar {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Preview Section */
.preview-container {
    position: sticky;
    top: 1.5rem;
}

.preview-frame {
    background: var(--bg-input);
    border-radius: 6px;
    min-height: 500px;
    overflow: hidden;
}

.preview-frame iframe {
    width: 100%;
    height: 600px;
    border: none;
}

/* Output Section */
.output-section {
    margin-top: 1.5rem;
}

.output-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    padding: 1rem;
}

/* Info text */
.info-text {
    background: rgba(157, 140, 255, 0.15);
    border: 1px solid var(--primary);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: var(--primary);
    margin-bottom: 1rem;
}

/* Scrollable editor */
.editor-scroll {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Theme swatches */
.theme-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.theme-swatch {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    cursor: pointer;
    border: 3px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.theme-swatch:hover {
    border-color: var(--text-secondary);
}

.theme-swatch.selected {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

.theme-swatch:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.theme-swatch .swatch-primary,
.theme-swatch .swatch-accent {
    flex: 1;
}

.theme-swatch-custom {
    background: linear-gradient(135deg, #ff6b6b 0%, #feca57 25%, #48dbfb 50%, #ff9ff3 75%, #54a0ff 100%);
    position: relative;
}

.theme-swatch-custom::after {
    content: '+';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.swatch-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 0.25rem;
}

.swatch-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Custom colors section */
.custom-colors {
    display: none;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem;
    background: var(--bg-input);
    border-radius: 6px;
    margin-top: 0.5rem;
}

.custom-colors.visible {
    display: flex;
}

.color-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.color-input-group label {
    font-size: 0.875rem;
    margin-bottom: 0;
}

.color-input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.color-input-row input[type="color"] {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.color-input-row input[type="text"] {
    width: 90px;
    font-family: monospace;
}

/* Logo input row */
.logo-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.logo-input-row input[type="url"] {
    flex: 1;
}

.logo-input-row .upload-btn {
    cursor: pointer;
    white-space: nowrap;
}

.logo-input-row .btn-sm:last-child {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    background: var(--bg-input);
    color: var(--text-secondary);
}

.logo-input-row .btn-sm:last-child:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.custom-warning {
    display: none;
    background: rgba(255, 193, 7, 0.15);
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: #ffc107;
    margin-top: 0.5rem;
}

.custom-warning.visible {
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    .theme-swatch {
        transition: none;
    }
}

/* Instruction modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--bg-panel);
    border-radius: 8px;
    max-width: 550px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
}

.modal-header {
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    opacity: 0.8;
}

.modal-body {
    padding: 1.5rem;
    color: var(--text-primary);
}

.modal-body h3 {
    color: var(--primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.modal-body p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.modal-body ol {
    margin: 0 0 1rem 1.25rem;
    line-height: 1.8;
}

.modal-body code {
    background: var(--bg-input);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.875rem;
    word-break: break-all;
}

.modal-body .code-block {
    background: var(--bg-body);
    color: var(--accent);
    padding: 0.75rem 1rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
    margin: 0.5rem 0 1rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* Tab styles */
.tab-nav {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1rem;
    gap: 0;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem 0.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--primary);
    background: var(--bg-input);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}
