/* ===============================================================
   ToolDuck — JSON to CSV Converter
   Styles for /json-to-csv/
   =============================================================== */

.j2c-app {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

/* ---------------------------------------------------------------
   Header Bar
   --------------------------------------------------------------- */
.j2c-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.85rem 1.15rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 8px);
}

.j2c-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.j2c-toolbar-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.j2c-format-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--primary, #1d4ed8);
    background: rgba(29, 78, 216, 0.08);
    border: 1px solid rgba(29, 78, 216, 0.2);
    border-radius: 999px;
}

.j2c-global-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.j2c-file-btn {
    cursor: pointer;
    margin: 0;
}

/* ---------------------------------------------------------------
   Options Bar
   --------------------------------------------------------------- */
.j2c-options-bar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
    padding: 0.7rem 1.15rem;
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    font-size: 0.85rem;
}

.j2c-option-group {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.j2c-option-label {
    font-weight: 550;
    color: var(--ink-2);
    font-size: 0.82rem;
}

.j2c-option-select {
    padding: 4px 8px;
    font-size: 0.82rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--ink);
}

.j2c-option-toggles {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.j2c-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-2);
    cursor: pointer;
    user-select: none;
}

.j2c-checkbox {
    cursor: pointer;
    accent-color: var(--primary, #1d4ed8);
}

/* ---------------------------------------------------------------
   Status Bar & Indicators
   --------------------------------------------------------------- */
.j2c-status-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
    color: var(--ink-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.j2c-status-indicator {
    font-size: 0.75rem;
    color: #10b981; /* Green */
}

.j2c-status-bar.is-error .j2c-status-indicator {
    color: #ef4444; /* Red */
}

.j2c-status-bar.is-error {
    background: rgba(239, 68, 68, 0.05);
    border-color: rgba(239, 68, 68, 0.3);
    color: #b91c1c;
}

html[data-theme="dark"] .j2c-status-bar.is-error {
    color: #f87171;
}

/* ---------------------------------------------------------------
   Error Banner
   --------------------------------------------------------------- */
.j2c-error-banner {
    padding: 0.85rem 1.15rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid #ef4444;
    border-radius: 4px;
    color: #991b1b;
    font-size: 0.86rem;
    line-height: 1.45;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

html[data-theme="dark"] .j2c-error-banner {
    background: #450a0a;
    border-color: #7f1d1d;
    border-left-color: #ef4444;
    color: #fca5a5;
}

/* ---------------------------------------------------------------
   Dual Column Editors
   --------------------------------------------------------------- */
.j2c-editors {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

@media (min-width: 900px) {
    .j2c-editors {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.j2c-column {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 8px);
    overflow: hidden;
}

.j2c-column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: var(--bg-muted);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.j2c-column-title {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.j2c-badge {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink-2);
}

.j2c-badge--primary {
    background: rgba(29, 78, 216, 0.1);
    color: var(--primary, #1d4ed8);
    border-color: rgba(29, 78, 216, 0.2);
}

.j2c-meta-count {
    font-size: 0.75rem;
    color: var(--ink-3);
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.j2c-column-tools {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* View Tabs */
.j2c-view-tabs {
    display: inline-flex;
    background: var(--surface);
    padding: 2px;
    border-radius: 6px;
    border: 1px solid var(--border);
    gap: 2px;
}

.j2c-view-btn {
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--ink-2);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.j2c-view-btn:hover {
    color: var(--ink);
}

.j2c-view-btn.is-active {
    background: var(--primary, #1d4ed8);
    color: #ffffff;
    font-weight: 600;
}

/* ---------------------------------------------------------------
   Editor Body & Gutters
   --------------------------------------------------------------- */
.j2c-editor-body {
    position: relative;
    display: flex;
    min-height: 440px;
    max-height: 720px;
    background: var(--surface);
    overflow: hidden;
}

.j2c-view-panel {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.j2c-gutter {
    flex-shrink: 0;
    width: 44px;
    padding: 0.85rem 0.5rem 0.85rem 0;
    text-align: right;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--ink-3, #94a3b8);
    background: var(--bg-muted);
    border-right: 1px solid var(--border);
    user-select: none;
    overflow: hidden;
    white-space: pre-wrap;
    box-sizing: border-box;
}

.j2c-textarea,
.j2c-output {
    flex: 1;
    width: 100%;
    margin: 0;
    padding: 0.85rem 1rem;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--ink);
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    white-space: pre;
    overflow: auto;
    tab-size: 2;
    box-sizing: border-box;
}

.j2c-output {
    background: rgba(0, 0, 0, 0.015);
    user-select: text;
}

html[data-theme="dark"] .j2c-output {
    background: rgba(255, 255, 255, 0.015);
}

/* ---------------------------------------------------------------
   Table Preview
   --------------------------------------------------------------- */
.j2c-table-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.j2c-table-container {
    flex: 1;
    width: 100%;
    overflow: auto;
    padding: 0;
}

.j2c-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    text-align: left;
}

.j2c-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 0.65rem 0.85rem;
    background: var(--bg-muted);
    color: var(--ink);
    font-weight: 650;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    border-right: 1px solid var(--border);
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.j2c-table td {
    padding: 0.55rem 0.85rem;
    color: var(--ink-2);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

.j2c-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.015);
}

html[data-theme="dark"] .j2c-table tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

.j2c-table tr:hover td {
    background: rgba(29, 78, 216, 0.04);
}

.j2c-table-truncation {
    padding: 0.5rem 0.85rem;
    font-size: 0.75rem;
    color: var(--ink-3);
    background: var(--bg-muted);
    border-top: 1px solid var(--border);
    text-align: center;
}

/* ---------------------------------------------------------------
   Toast Notifications
   --------------------------------------------------------------- */
.j2c-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    padding: 0.65rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: #ffffff;
    background: #1e293b;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.j2c-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
    .j2c-header-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    .j2c-global-actions {
        width: 100%;
        justify-content: flex-start;
    }
    .j2c-options-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .j2c-editor-body {
        min-height: 320px;
    }
}
