/**
 * Diff Checker App Styles
 *
 * A production-ready text comparison tool with accessible, responsive design
 * Features: Side-by-side panels, diff highlighting, dark mode support, RTL support
 */

/* ========================================
   App Container Centering
   ======================================== */

.app-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

/* ========================================
   Options Bar
   ======================================== */

.dc-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
}

.dc-options-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
}

.dc-option {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    cursor: pointer;
    user-select: none;
}

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

.dc-options-actions {
    display: flex;
    gap: var(--space-2);
}

/* ========================================
   Buttons
   ======================================== */

.dc-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;
    white-space: nowrap;
}

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

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

.dc-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

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

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

.dc-btn-secondary:hover:not(:disabled) {
    background: var(--color-border);
}

.dc-btn-small {
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
}

.dc-btn-nav {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-3);
}

.dc-btn-nav:hover:not(:disabled) {
    background: var(--color-bg-alt);
}

/* ========================================
   Summary Bar
   ======================================== */

.dc-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
}

.dc-stats {
    display: flex;
    gap: var(--space-6);
}

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

.dc-stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: var(--font-size-xs);
}

.dc-stat-added .dc-stat-icon {
    background: var(--diff-added-bg, rgba(46, 160, 67, 0.2));
    color: var(--diff-added-text, #22863a);
}

.dc-stat-removed .dc-stat-icon {
    background: var(--diff-removed-bg, rgba(248, 81, 73, 0.2));
    color: var(--diff-removed-text, #cb2431);
}

.dc-stat-modified .dc-stat-icon {
    background: var(--diff-modified-bg, rgba(210, 153, 34, 0.2));
    color: var(--diff-modified-text, #b08800);
}

.dc-stat-value {
    font-weight: 600;
    color: var(--color-text);
}

.dc-stat-label {
    color: var(--color-text-muted);
}

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

.dc-nav-position {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    min-width: 50px;
    text-align: center;
}

/* ========================================
   Comparison Panels
   ======================================== */

.dc-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    min-height: 400px;
}

.dc-panel {
    display: flex;
    flex-direction: column;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

.dc-panel-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text);
}

.dc-panel-actions {
    display: flex;
    gap: var(--space-2);
}

.dc-panel-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* ========================================
   Editor Wrapper (Input Mode)
   ======================================== */

.dc-editor-wrapper {
    display: flex;
    height: 100%;
    min-height: 350px;
    position: relative;
    z-index: 1;
}

.dc-line-numbers {
    flex-shrink: 0;
    padding: var(--space-4) var(--space-3);
    font-size: var(--font-size-sm);
    font-family: var(--font-family-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;
    overflow: hidden;
}

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

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

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

/* When textarea is focused, ensure it's visible and editable above the diff overlay */
.dc-editor-wrapper:focus-within {
    z-index: 3;
}

/* ========================================
   Diff Output (Result Mode)
   ======================================== */

.dc-diff-output {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: auto;
    background: var(--color-bg-card);
    font-family: var(--font-family-mono);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

.dc-diff-output.dc-active {
    display: block;
}

/* Allow clicks to pass through to textarea when panel is focused */
.dc-panel-content:focus-within .dc-diff-output.dc-active {
    pointer-events: none;
}

/* ========================================
   Diff Lines
   ======================================== */

.dc-line {
    display: flex;
    min-height: 1.6em;
}

.dc-line-num {
    flex-shrink: 0;
    width: 40px;
    padding: 0 var(--space-2);
    text-align: right;
    color: var(--color-text-muted);
    background: var(--color-bg-alt);
    border-right: 1px solid var(--color-border);
    user-select: none;
}

.dc-line-content {
    flex: 1;
    padding: 0 var(--space-3);
    white-space: pre;
    overflow-x: auto;
}

/* Unchanged lines */
.dc-line-unchanged {
    background: var(--color-bg-card);
}

/* Added lines */
.dc-line-added {
    background: var(--diff-added-bg, rgba(46, 160, 67, 0.15));
}

.dc-line-added .dc-line-num {
    background: var(--diff-added-bg, rgba(46, 160, 67, 0.2));
    color: var(--diff-added-text, #22863a);
}

/* Removed lines */
.dc-line-removed {
    background: var(--diff-removed-bg, rgba(248, 81, 73, 0.15));
}

.dc-line-removed .dc-line-num {
    background: var(--diff-removed-bg, rgba(248, 81, 73, 0.2));
    color: var(--diff-removed-text, #cb2431);
}

/* Modified lines */
.dc-line-modified {
    background: var(--diff-modified-bg, rgba(210, 153, 34, 0.15));
}

.dc-line-modified .dc-line-num {
    background: var(--diff-modified-bg, rgba(210, 153, 34, 0.2));
    color: var(--diff-modified-text, #b08800);
}

/* Placeholder lines (for alignment) */
.dc-line-placeholder {
    background: var(--color-bg-alt);
}

.dc-line-placeholder .dc-line-num,
.dc-line-placeholder .dc-line-content {
    background: var(--color-bg-alt);
}

/* Current highlighted diff */
.dc-line.dc-current {
    box-shadow: inset 3px 0 0 var(--color-primary);
}

/* ========================================
   Word-Level Highlighting
   ======================================== */

.dc-word-added {
    background: var(--diff-added-word-bg, rgba(46, 160, 67, 0.4));
    color: var(--diff-added-text, #22863a);
    border-radius: 2px;
}

.dc-word-removed {
    background: var(--diff-removed-word-bg, rgba(248, 81, 73, 0.4));
    color: var(--diff-removed-text, #cb2431);
    border-radius: 2px;
    text-decoration: line-through;
}

/* ========================================
   No Differences Message
   ======================================== */

.dc-no-diff {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-8);
    text-align: center;
    color: var(--color-success, #10b981);
}

.dc-no-diff[hidden] {
    display: none;
}

.dc-no-diff svg {
    opacity: 0.8;
}

.dc-no-diff p {
    font-size: var(--font-size-lg);
    font-weight: 500;
    margin: 0;
}

/* ========================================
   Dark Theme
   ======================================== */

:root[data-theme="dark"] {
    --diff-added-bg: rgba(46, 160, 67, 0.2);
    --diff-added-word-bg: rgba(46, 160, 67, 0.35);
    --diff-added-text: #85e89d;

    --diff-removed-bg: rgba(248, 81, 73, 0.2);
    --diff-removed-word-bg: rgba(248, 81, 73, 0.35);
    --diff-removed-text: #f97583;

    --diff-modified-bg: rgba(210, 153, 34, 0.2);
    --diff-modified-text: #ffdf5d;
}

/* ========================================
   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);
}

/* ========================================
   FAQ Section
   ======================================== */

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

.faq-section h2 {
    font-size: var(--font-size-xl);
    margin-bottom: var(--space-6);
    text-align: center;
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-width: 800px;
    margin: 0 auto;
}

.faq-item {
    padding: var(--space-4);
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.faq-item dt {
    font-weight: 600;
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.faq-item dd {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    line-height: 1.6;
}

/* ========================================
   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-modal-content {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    max-width: 550px;
    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-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-section ol,
.help-section ul {
    padding-left: var(--space-5);
    margin: 0;
}

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

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

.help-color-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    margin-right: var(--space-2);
    vertical-align: middle;
}

.help-color-added {
    background: var(--diff-added-bg, rgba(46, 160, 67, 0.3));
}

.help-color-removed {
    background: var(--diff-removed-bg, rgba(248, 81, 73, 0.3));
}

.help-color-modified {
    background: var(--diff-modified-bg, rgba(210, 153, 34, 0.3));
}

.keyboard-shortcuts {
    width: 100%;
    border-collapse: collapse;
}

.keyboard-shortcuts td {
    padding: var(--space-2);
    color: var(--color-text-muted);
}

.keyboard-shortcuts td:first-child {
    white-space: nowrap;
}

.keyboard-shortcuts kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: var(--font-size-xs);
    font-family: var(--font-family-mono);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.close-help {
    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;
}

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

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

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

@media (max-width: 768px) {
    .dc-panels {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .dc-panel {
        min-height: 300px;
    }

    .dc-editor-wrapper {
        min-height: 250px;
    }

    .dc-textarea {
        min-height: 250px;
    }

    .dc-options {
        flex-direction: column;
        align-items: stretch;
    }

    .dc-options-row {
        flex-direction: column;
        gap: var(--space-3);
    }

    .dc-options-actions {
        justify-content: center;
    }

    .dc-summary {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
    }

    .dc-stats {
        justify-content: center;
    }

    .dc-nav {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .dc-stats {
        flex-wrap: wrap;
        gap: var(--space-3);
    }

    .dc-stat-label {
        display: none;
    }

    .dc-panel-header {
        flex-direction: column;
        gap: var(--space-2);
        align-items: stretch;
    }

    .dc-panel-actions {
        justify-content: center;
    }

    .dc-textarea,
    .dc-editor-wrapper {
        min-height: 200px;
        font-size: var(--font-size-xs);
    }

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

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

[dir="rtl"] .dc-panels {
    direction: rtl;
}

[dir="rtl"] .dc-panel-left {
    order: 2;
}

[dir="rtl"] .dc-panel-right {
    order: 1;
}

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

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

[dir="rtl"] .dc-line.dc-current {
    box-shadow: inset -3px 0 0 var(--color-primary);
}

/* Code content is always LTR */
.dc-line-content,
.dc-textarea {
    direction: ltr;
    text-align: left;
}

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

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

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

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

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

    .dc-panels {
        display: block;
    }

    .dc-panel {
        page-break-inside: avoid;
        margin-bottom: var(--space-4);
    }

    .dc-diff-output {
        display: block !important;
        position: static;
    }

    .dc-editor-wrapper {
        display: none;
    }
}
