/* Apply dark theme to scrollbars */
html {
    color-scheme: dark;
}

::-webkit-scrollbar {
    width: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

:root {
    /* Backgrounds */
    --bg-color: #09090b;      /* Zinc-950 */
    --card-bg: #121214;      /* Slightly lighter Zinc */
    --card-hover: #18181b;

    /* Text */
    --text-main: #fafafa;    /* Zinc-50 */
    --text-muted: #a1a1aa;   /* Zinc-400 */

    /* Brand / Action */
    --primary: #3b82f6;      /* Blue-500 */
    --primary-hover: #60a5fa;
    --danger: #ef4444;
    --danger-hover: #f87171;

    /* UI Details */
    --border-color: #27272a; /* Zinc-800 */
    --radius: 12px;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    /* Subtle glow effect in the corner */
    background-image: radial-gradient(circle at top center, #1e1b4b 0%, transparent 600px);
}

#app {
    width: 100%;
    max-width: 1000px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

header {
    box-sizing: border-box;
    width: 100%;
    min-height: 70px;
    margin-bottom: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    /* PWA Titlebar Support */
    padding-left: calc(env(titlebar-area-x, 0px) + 20px);
    padding-right: 20px;
    padding-top: env(titlebar-area-y, 0px);

    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: rgba(18, 18, 20, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);

    -webkit-app-region: drag;
    app-region: drag;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;

    /* The Gradient */
    background: linear-gradient(to right, #ffffff, #a1a1aa);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

header nav,
header button {
    app-region: no-drag;
    -webkit-app-region: no-drag;
}

h1 {
    margin: 0 0 20px 0;
    font-weight: 800;
    color: var(--text-main);
}

#stepper {
    display: flex;
    gap: 8px;
    align-items: center;
    -webkit-app-region: no-drag;
    app-region: no-drag;
    background: var(--bg-color);
    padding: 4px;
    border-radius: 99px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

.step {
    padding: 6px 14px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    border: 1px solid transparent;
    transition: all 0.2s;
}

.step.active {
    background: rgba(59, 130, 246, 0.1); /* 10% opacity Blue */
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.4);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.15); /* Soft glow */
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.view {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: block;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    text-align: center;
}

.card h2 {
    margin-top: 0;
}

.card p {
    color: var(--text-muted);
    margin-bottom: 20px;
}

button {
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    transition: all 0.2s;
}

.primary-btn, .secondary-btn {
    padding: 12px 24px;
    border-radius: var(--radius);
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.primary-btn {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.secondary-btn {
    background: #27272a;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.secondary-btn:hover {
    background: #3f3f46;
}

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

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

.actions {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.progress-container {
    width: 100%;
    max-width: 400px;
    height: 12px;
    background: var(--border-color);
    border-radius: 6px;
    margin: 20px auto;
    overflow: hidden;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.preview-pane {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: var(--radius);
    text-align: left;
    min-height: 300px;
    font-family: monospace;
}

.tree-view {
    max-height: 400px;
    overflow-y: auto;
    font-family: monospace;
    white-space: pre;
    line-height: 1.5;
    padding: 10px;
    border-radius: var(--radius);
}

footer {
    margin-top: auto;
    padding-top: 20px;
}

@media (max-width: 600px) {
    #app {
        padding: 12px;
    }

    header {
        flex-direction: column;
        align-items: center;
        height: auto;
        gap: 15px;
        margin-bottom: 24px;
        padding: 16px 12px;
        text-align: center;
        justify-content: center;
        border: 1px solid var(--border-color);
        background: rgba(18, 18, 20, 0.9);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    header h1 {
        margin-bottom: 0;
    }

    #stepper {
        flex-wrap: nowrap;
        justify-content: center;
        width: auto;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .step {
        flex-shrink: 0;
        font-size: 0.65rem;
        padding: 6px 8px;
    }

    .preview-grid {
        grid-template-columns: 1fr;
    }
}

#status-bar {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--border-color);
    padding: 10px;
    border-radius: var(--radius);
}

/* New Component Styles for Dark Theme */

.custom-labels-container {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    text-align: left;
}

.labels-label {
    font-size: 0.9rem;
    font-weight: bold;
    display: block;
    margin-bottom: 8px;
}

.labels-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}

.labels-input-group input {
    flex: 1;
    padding: 8px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
}

.labels-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
}

.log-container {
    margin-top: 20px;
    text-align: left;
    max-height: 200px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.8rem;
    background: var(--bg-color);
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.gallery-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.rule-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    margin-bottom: 10px;
    transition: background 0.2s;
}

.rule-item:hover {
    background: var(--card-hover);
}

.gallery-item-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    font-size: 0.8rem;
}

.gallery-item {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-color);
    transition: transform 0.2s, border-color 0.2s;
}

.gallery-item:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}

.gallery-input {
    width: 90px;
    font-size: 0.7rem;
    margin-top: 5px;
    text-align: center;
    background: var(--bg-color);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 4px;
}

.gallery-input:focus {
    outline: none;
    border-color: var(--primary);
}
