/**
 * JSON Formatter App Styles
 *
 * A production-ready JSON formatter with accessible, responsive design
 * Features: Two-panel layout, syntax highlighting, dark mode support
 */

/* ========================================
   App Page Layout (Override for wider container)
   ======================================== */

.app-container--wide {
    max-width: 1200px;
    margin: 0 auto;
}

/* ========================================
   JSON Formatter Container
   ======================================== */

.json-formatter {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

/* ========================================
   Controls Bar
   ======================================== */

.jf-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
}

.jf-controls-left,
.jf-controls-right {
    display: flex;
    gap: var(--space-2);
}

.jf-controls-center {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Buttons */
.jf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), transform 0.1s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

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

.jf-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.jf-btn-primary {
    background: var(--color-primary);
    color: white;
    border: none;
}

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

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

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

/* Indentation Selector */
.jf-indent-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.jf-indent-select {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.jf-indent-select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ========================================
   Status Bar
   ======================================== */

.jf-status-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    min-height: 40px;
}

.jf-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
}

.jf-status-icon {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-text-muted);
}

.jf-status--valid .jf-status-icon {
    background: var(--color-success, #22c55e);
}

.jf-status--invalid .jf-status-icon {
    background: var(--color-error, #ef4444);
}

.jf-status-text {
    color: var(--color-text-muted);
}

.jf-status--valid .jf-status-text {
    color: var(--color-success-text, #047857);
}

.jf-status--invalid .jf-status-text {
    color: var(--color-error-text, #dc2626);
}

.jf-error {
    font-size: var(--font-size-sm);
}

.jf-error[hidden] {
    display: none;
}

.jf-error-message {
    color: var(--color-error, #ef4444);
}

/* ========================================
   Two-Panel Layout
   ======================================== */

.jf-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 400px;
}

.jf-panel {
    display: flex;
    flex-direction: column;
}

.jf-panel--input {
    border-right: 1px solid var(--color-border);
}

.jf-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
}

.jf-panel-title {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.jf-panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Input Textarea
   ======================================== */

.jf-textarea {
    flex: 1;
    width: 100%;
    min-height: 350px;
    padding: var(--space-4);
    font-size: var(--font-size-sm);
    font-family: var(--font-mono);
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg-card);
    border: none;
    resize: none;
    tab-size: 2;
}

.jf-textarea::placeholder {
    color: var(--color-text-muted);
}

.jf-textarea:focus {
    outline: none;
    background: var(--color-bg-alt);
}

/* ========================================
   Output Display with Line Numbers
   ======================================== */

.jf-output-wrapper {
    flex: 1;
    display: flex;
    overflow: auto;
    background: var(--color-bg-card);
}

.jf-line-numbers {
    flex-shrink: 0;
    padding: var(--space-4) var(--space-3);
    font-size: var(--font-size-sm);
    font-family: var(--font-mono);
    line-height: 1.6;
    color: var(--color-text-muted);
    background: var(--color-bg-alt);
    border-right: 1px solid var(--color-border);
    text-align: right;
    user-select: none;
    min-width: 40px;
    white-space: pre;
}

.jf-output {
    flex: 1;
    margin: 0;
    padding: var(--space-4);
    font-size: var(--font-size-sm);
    font-family: var(--font-mono);
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg-card);
    white-space: pre;
    overflow: auto;
    min-height: 350px;
}

.jf-output:focus {
    outline: none;
    background: var(--color-bg-alt);
}

/* Empty state */
.jf-output:empty::before {
    content: attr(data-placeholder);
    color: var(--color-text-muted);
}

/* ========================================
   Syntax Highlighting
   ======================================== */

.jf-string {
    color: var(--color-syntax-string, #22863a);
}

.jf-number {
    color: var(--color-syntax-number, #005cc5);
}

.jf-boolean {
    color: var(--color-syntax-boolean, #d73a49);
}

.jf-null {
    color: var(--color-syntax-null, #6f42c1);
}

.jf-key {
    color: var(--color-syntax-key, #032f62);
}

.jf-bracket {
    color: var(--color-text-muted);
}

/* Dark mode syntax highlighting */
:root[data-theme="dark"] {
    --color-syntax-string: #a5d6ff;
    --color-syntax-number: #79c0ff;
    --color-syntax-boolean: #ff7b72;
    --color-syntax-null: #d2a8ff;
    --color-syntax-key: #7ee787;
}

/* ========================================
   Use Cases Section
   ======================================== */

.use-cases {
    margin-top: var(--space-8);
    padding: var(--space-6);
    background: var(--color-bg-alt);
    border-radius: var(--radius-lg);
}

.use-cases h2 {
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-3);
    text-align: center;
}

.use-cases-intro {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--space-6);
}

.use-cases-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-4);
    list-style: none;
    padding: 0;
    margin: 0;
}

.use-cases-list li {
    padding: var(--space-4);
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.use-cases-list strong {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.use-cases-list p {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 768px) {
    .jf-layout {
        grid-template-columns: 1fr;
    }

    .jf-panel--input {
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .jf-textarea,
    .jf-output {
        min-height: 200px;
    }

    .jf-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .jf-controls-left,
    .jf-controls-center,
    .jf-controls-right {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .jf-controls-left,
    .jf-controls-right {
        flex-direction: column;
    }

    .jf-btn {
        width: 100%;
    }

    .jf-textarea,
    .jf-output {
        min-height: 150px;
        font-size: var(--font-size-xs);
    }

    .jf-line-numbers {
        font-size: var(--font-size-xs);
        padding: var(--space-4) var(--space-2);
        min-width: 30px;
    }
}

/* ========================================
   RTL Support
   ======================================== */

[dir="rtl"] .jf-panel--input {
    border-right: none;
    border-left: 1px solid var(--color-border);
}

[dir="rtl"] .jf-line-numbers {
    border-right: none;
    border-left: 1px solid var(--color-border);
    text-align: left;
}

/* JSON content is always LTR */
.jf-output {
    direction: ltr;
    text-align: left;
}

/* ========================================
   Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .jf-btn,
    .jf-textarea {
        transition: none;
    }

    .jf-btn:active {
        transform: none;
    }
}

/* ========================================
   Help Panel (Modal)
   ======================================== */

.help-panel {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.help-panel[hidden] {
    display: none;
}

.help-content {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}

.help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    background: var(--color-bg-card);
}

.help-header h2 {
    font-size: var(--font-size-lg);
    margin: 0;
}

.help-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xl);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
}

.help-close:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.help-close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.help-body {
    padding: var(--space-6);
}

.help-section {
    margin-bottom: var(--space-6);
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-size: var(--font-size-base);
    font-weight: 600;
    margin-bottom: var(--space-3);
    color: var(--color-text);
}

.help-steps {
    padding-left: var(--space-5);
    margin: 0;
}

.help-steps li {
    margin-bottom: var(--space-2);
    color: var(--color-text-muted);
}

.help-features {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-features li {
    position: relative;
    padding-left: var(--space-5);
    margin-bottom: var(--space-2);
    color: var(--color-text-muted);
}

.help-features li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--color-success-text, #047857);
    font-weight: bold;
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .jf-controls,
    .help-panel,
    .nav-actions {
        display: none;
    }

    .json-formatter {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .jf-layout {
        display: block;
    }

    .jf-panel--input {
        display: none;
    }

    .jf-output {
        min-height: auto;
    }
}
