/**
 * Base64 Encoder/Decoder App Styles
 *
 * A production-ready Base64 encoder/decoder with accessible, responsive design
 * Features: Mode toggle, file support, URL-safe option, drag & drop
 */

/* ========================================
   App Page Layout
   ======================================== */

.app-page {
    padding: var(--space-4);
    padding-top: calc(var(--header-height) + var(--space-4));
    min-height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.app-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.app-header h1 {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--space-2);
}

.app-description {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    margin-bottom: 0;
}

/* ========================================
   Base64 Encoder Container
   ======================================== */

.b64-encoder {
    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
   ======================================== */

.b64-controls {
    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-bottom: 1px solid var(--color-border);
}

/* Mode Toggle */
.b64-mode-toggle {
    display: flex;
    gap: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.b64-mode-btn {
    padding: var(--space-2) var(--space-5);
    font-size: var(--font-size-sm);
    font-weight: 500;
    background: var(--color-bg-card);
    color: var(--color-text-muted);
    border: none;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.b64-mode-btn:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

.b64-mode-btn--active {
    background: var(--color-primary);
    color: white;
}

.b64-mode-btn--active:hover {
    background: var(--color-primary-dark);
    color: white;
}

.b64-mode-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    z-index: 1;
    position: relative;
}

/* Options */
.b64-options {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

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

.b64-checkbox {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

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

/* ========================================
   Panels (Input/Output)
   ======================================== */

.b64-panel {
    position: relative;
    border-bottom: 1px solid var(--color-border);
}

.b64-panel:last-of-type {
    border-bottom: none;
}

.b64-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);
}

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

.b64-char-count {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-family: var(--font-mono);
}

.b64-panel-content {
    padding: 0;
}

/* ========================================
   Textareas
   ======================================== */

.b64-textarea {
    width: 100%;
    min-height: 180px;
    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: vertical;
    tab-size: 2;
}

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

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

.b64-textarea--output {
    background: var(--color-bg-card);
    cursor: text;
}

.b64-textarea--output:focus {
    background: var(--color-bg-alt);
}

/* ========================================
   Panel Actions
   ======================================== */

.b64-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-border);
}

/* Buttons */
.b64-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;
}

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

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

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

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

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

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

.b64-btn--success {
    background: var(--color-success, #22c55e);
    color: white;
    border-color: var(--color-success, #22c55e);
}

.b64-btn--success:hover {
    background: var(--color-success, #22c55e);
}

.b64-btn svg {
    flex-shrink: 0;
}

/* File Label Button */
.b64-file-label {
    cursor: pointer;
}

/* Icon Button */
.b64-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    color: var(--color-text-muted);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.b64-btn-icon:hover {
    background: var(--color-bg-alt);
    color: var(--color-text);
}

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

/* ========================================
   Drop Zone
   ======================================== */

.b64-drop-zone {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(79, 70, 229, 0.1);
    border: 2px dashed var(--color-primary);
    pointer-events: none;
}

.b64-drop-zone[hidden] {
    display: none;
}

.b64-drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    color: var(--color-primary);
    font-weight: 500;
}

/* ========================================
   File Info
   ======================================== */

.b64-file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-border);
}

.b64-file-info[hidden] {
    display: none;
}

.b64-file-details {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    overflow: hidden;
}

.b64-file-details svg {
    flex-shrink: 0;
    color: var(--color-primary);
}

#b64-file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

#b64-file-size {
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* ========================================
   Error Display
   ======================================== */

.b64-error {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: rgba(239, 68, 68, 0.1);
    border-top: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--color-error, #ef4444);
    font-size: var(--font-size-sm);
}

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

.b64-error svg {
    flex-shrink: 0;
}

/* ========================================
   Image Preview
   ======================================== */

.b64-preview {
    padding: var(--space-4);
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-border);
    text-align: center;
}

.b64-preview[hidden] {
    display: none;
}

.b64-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

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

/* ========================================
   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: "\2713";
    position: absolute;
    left: 0;
    color: var(--color-success, #22c55e);
    font-weight: bold;
}

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

@media (max-width: 768px) {
    .b64-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .b64-mode-toggle {
        justify-content: center;
    }

    .b64-options {
        justify-content: center;
    }

    .b64-textarea {
        min-height: 140px;
    }

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

@media (max-width: 480px) {
    .b64-mode-btn {
        padding: var(--space-2) var(--space-4);
        font-size: var(--font-size-xs);
    }

    .b64-textarea {
        min-height: 120px;
        font-size: var(--font-size-xs);
    }

    .b64-btn span {
        display: none;
    }

    .b64-btn {
        padding: var(--space-2);
    }

    .b64-file-label span {
        display: none;
    }

    #b64-file-name {
        max-width: 120px;
    }
}

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

[dir="rtl"] .b64-file-details {
    flex-direction: row-reverse;
}

[dir="rtl"] .help-steps {
    padding-left: 0;
    padding-right: var(--space-5);
}

[dir="rtl"] .help-features li {
    padding-left: 0;
    padding-right: var(--space-5);
}

[dir="rtl"] .help-features li::before {
    left: auto;
    right: 0;
}

/* Base64 content is always LTR */
.b64-textarea {
    direction: ltr;
    text-align: left;
}

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

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

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

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

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

    .b64-encoder {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .b64-textarea {
        min-height: auto;
        height: auto;
    }
}
