/* Apple Style CSS Design System */
:root {
    --apple-bg: #161617;
    --apple-card: #000000;
    --apple-nav: rgba(22, 22, 23, 0.85);
    --apple-border: rgba(255, 255, 255, 0.12);
    
    --apple-text-primary: #f5f5f7;
    --apple-text-secondary: #86868b;
    --apple-text-muted: #424245;
    
    --apple-blue: #0071e3;
    --apple-blue-hover: #147bdf;
    --apple-gray-btn: #333336;
    --apple-gray-btn-hover: #424245;
    --apple-danger: #ff453a;
    
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --apple-transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--apple-bg);
    color: var(--apple-text-primary);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Global Navigation Bar */
.global-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 48px;
    background-color: var(--apple-nav);
    border-bottom: 1px solid var(--apple-border);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    z-index: 100;
}

.nav-content {
    max-width: 1024px;
    height: 100%;
    margin: 0 auto;
    padding: 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--apple-text-primary);
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.2px;
    transition: opacity 0.2s ease;
}

.nav-brand:hover {
    opacity: 0.8;
}

.nav-logo {
    width: 18px;
    height: 18px;
    color: var(--apple-text-primary);
}

.nav-badge {
    font-size: 0.72rem;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 980px;
    color: var(--apple-text-secondary);
}

/* Container */
.container {
    width: 100%;
    max-width: 1024px;
    padding: 98px 22px 60px 22px; /* Margin top to push past the nav bar */
    display: flex;
    flex-direction: column;
    gap: 40px;
}

/* Apple Page Header */
.app-header {
    text-align: center;
}

.logo-title {
    font-family: var(--font-heading);
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -1.5px;
    color: var(--apple-text-primary);
}

.logo-title span {
    color: var(--apple-blue);
}

.app-subtitle {
    color: var(--apple-text-secondary);
    font-size: 1.22rem;
    font-weight: 400;
    max-width: 600px;
    margin: 12px auto 0 auto;
    letter-spacing: -0.2px;
    line-height: 1.4;
}

/* Main Workspace */
.app-workspace {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Cards (Apple style) */
.card {
    border-radius: 18px;
    border: 1px solid var(--apple-border);
    background-color: var(--apple-card);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.config-card {
    overflow: visible;
}


.card-header {
    padding: 24px 32px 12px 32px;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-icon {
    width: 18px;
    height: 18px;
    color: var(--apple-blue);
}

.card-header h2 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--apple-text-primary);
    letter-spacing: -0.1px;
}

.card-body {
    padding: 12px 32px 32px 32px;
}

/* Upload Card Dropzone */
.upload-card {
    border-style: solid;
}

.dropzone {
    position: relative;
    padding: 48px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    min-height: 240px;
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    margin: 16px;
    transition: var(--apple-transition);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--apple-blue);
    background: rgba(255, 255, 255, 0.01);
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none;
}

.upload-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
    border: 1px solid var(--apple-border);
    transition: var(--apple-transition);
}

.dropzone:hover .upload-icon-wrapper {
    background: var(--apple-blue);
    border-color: var(--apple-blue);
    transform: translateY(-2px);
}

.upload-icon {
    width: 20px;
    height: 20px;
    color: var(--apple-text-primary);
    transition: var(--apple-transition);
}

.dropzone:hover .upload-icon {
    color: #ffffff;
}

.dropzone-content h3 {
    font-size: 1.15rem;
    font-weight: 500;
    letter-spacing: -0.2px;
    color: var(--apple-text-primary);
}

.dropzone-content p {
    font-size: 0.9rem;
    color: var(--apple-text-secondary);
}

.file-types {
    font-size: 0.76rem;
    color: var(--apple-text-muted);
    margin-top: 4px;
}

/* File Info Card */
.file-info-card {
    padding: 24px;
    margin-bottom: 8px;
}

.file-details {
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--apple-border);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
}

.file-detail-icon {
    width: 24px;
    height: 24px;
    color: var(--apple-text-secondary);
}

.file-detail-text {
    flex-grow: 1;
    overflow: hidden;
}

.file-detail-text h4 {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--apple-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-detail-text p {
    font-size: 0.8rem;
    color: var(--apple-text-secondary);
    margin-top: 2px;
}

.delete-btn {
    background: transparent;
    border: none;
    color: var(--apple-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: 50%;
    transition: var(--apple-transition);
}

.delete-btn:hover {
    background: rgba(255, 69, 58, 0.1);
    color: var(--apple-danger);
}

/* Config panel items */
.toggle-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 8px;
    position: relative;
    user-select: none;
}

.toggle-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    background-color: var(--apple-gray-btn);
    border-radius: 24px;
    transition: var(--apple-transition);
    margin-right: 14px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: var(--apple-transition);
}

.toggle-input:checked + .toggle-slider {
    background-color: var(--apple-blue);
}

.toggle-input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--apple-text-primary);
}

.helper-text {
    font-size: 0.8rem;
    color: var(--apple-text-secondary);
    line-height: 1.4;
    margin-left: 58px;
}

.key-wrapper {
    margin-top: 20px;
    margin-left: 58px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--apple-border);
    border-radius: 12px;
    animation: slideDown 0.25s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--apple-text-secondary);
}

.password-input-container {
    display: flex;
    position: relative;
}

.password-input-container input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--apple-border);
    color: white;
    padding: 10px 16px;
    padding-right: 44px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: var(--apple-transition);
}

.password-input-container input:focus {
    border-color: var(--apple-blue);
    background: rgba(255, 255, 255, 0.05);
}

.btn-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--apple-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
}

.btn-icon:hover {
    color: var(--apple-text-primary);
}

.key-status-text {
    display: block;
    margin-top: 8px;
    font-size: 0.72rem;
    color: var(--apple-text-muted);
}

/* Apple Style Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 980px; /* Fully pill-shaped */
    border: none;
    cursor: pointer;
    transition: var(--apple-transition);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-primary {
    background-color: var(--apple-blue);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--apple-blue-hover);
}

.btn-secondary {
    background-color: var(--apple-gray-btn);
    color: var(--apple-text-primary);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.btn-secondary:hover {
    background-color: var(--apple-gray-btn-hover);
}

.btn-link {
    background: transparent;
    color: var(--apple-blue);
    font-weight: 500;
    padding: 8px 16px;
}

.btn-link:hover {
    text-decoration: underline;
}

/* Loading panel & Apple spinner */
.loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    text-align: center;
}

.loading-animation-container {
    margin-bottom: 24px;
}

.apple-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--apple-blue);
    border-radius: 50%;
    animation: apple-spin 0.8s linear infinite;
}

@keyframes apple-spin {
    to { transform: rotate(360deg); }
}

.loading-card h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.loading-card p {
    color: var(--apple-text-secondary);
    font-size: 0.9rem;
}

/* Display & Results Panel */
.result-card {
    display: flex;
    flex-direction: column;
}

.result-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--apple-border);
}

.metric-item {
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--apple-border);
    text-align: center;
}

.metric-item:last-child {
    border-right: none;
}

.metric-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--apple-text-secondary);
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}

.metric-value {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--apple-text-primary);
}

.result-tabs-header {
    padding: 20px 32px;
    border-bottom: 1px solid var(--apple-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    background: rgba(255, 255, 255, 0.01);
}

/* iOS Segment Controller style for tabs */
.tab-segment-control {
    display: flex;
    background: rgba(255, 255, 255, 0.06);
    padding: 3px;
    border-radius: 30px;
    border: 1px solid var(--apple-border);
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 18px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 30px;
    border: none;
    background: transparent;
    color: var(--apple-text-secondary);
    cursor: pointer;
    transition: var(--apple-transition);
}

.tab-btn.active {
    background-color: var(--apple-bg);
    color: var(--apple-text-primary);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.tab-actions {
    display: flex;
    gap: 8px;
}

.result-tabs-content {
    background: rgba(0, 0, 0, 0.2);
}

.tab-pane {
    display: none;
    min-height: 400px;
    max-height: 580px;
    overflow-y: auto;
}

.tab-pane.active {
    display: block;
}

/* Markdown Preview pane custom CSS */
.markdown-preview-body {
    padding: 32px;
    line-height: 1.65;
    color: #e3e3e7;
    font-size: 0.95rem;
}

.markdown-preview-body h1, 
.markdown-preview-body h2, 
.markdown-preview-body h3, 
.markdown-preview-body h4 {
    font-family: var(--font-heading);
    color: #ffffff;
    margin-top: 26px;
    margin-bottom: 12px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.markdown-preview-body h1 { font-size: 1.7rem; border-bottom: 1px solid var(--apple-border); padding-bottom: 8px; }
.markdown-preview-body h2 { font-size: 1.35rem; border-bottom: 1px solid rgba(255,255,255,0.04); padding-bottom: 6px; }
.markdown-preview-body h3 { font-size: 1.12rem; }

.markdown-preview-body p {
    margin-bottom: 16px;
}

.markdown-preview-body ul, 
.markdown-preview-body ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.markdown-preview-body li {
    margin-bottom: 6px;
}

.markdown-preview-body blockquote {
    border-left: 3px solid var(--apple-blue);
    background: rgba(255, 255, 255, 0.02);
    padding: 14px 20px;
    margin: 18px 0;
    border-radius: 0 8px 8px 0;
    color: var(--apple-text-secondary);
    font-style: italic;
}

.markdown-preview-body pre {
    background: #111112;
    border: 1px solid var(--apple-border);
    padding: 18px;
    border-radius: 12px;
    overflow-x: auto;
    margin-bottom: 18px;
}

.markdown-preview-body code {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.88rem;
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    color: #ffd60a; /* Bright clean yellow for code tags */
}

.markdown-preview-body pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.markdown-preview-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 22px 0;
    font-size: 0.88rem;
}

.markdown-preview-body th, 
.markdown-preview-body td {
    border: 1px solid var(--apple-border);
    padding: 12px 14px;
    text-align: left;
}

.markdown-preview-body th {
    background: rgba(255, 255, 255, 0.04);
    font-weight: 500;
}

.markdown-preview-body tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.01);
}

/* Raw Markdown pane styling */
.markdown-raw-container {
    width: 100%;
    height: 100%;
    min-height: 400px;
}

.markdown-raw-container textarea {
    width: 100%;
    height: 100%;
    min-height: 400px;
    background: #111112;
    border: none;
    color: #30d158; /* Apple green for raw markdown text */
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 0.88rem;
    padding: 24px;
    resize: none;
    outline: none;
    line-height: 1.55;
    display: block;
}

.result-footer {
    padding: 20px 32px;
    border-top: 1px solid var(--apple-border);
    display: flex;
    justify-content: center;
    background: rgba(255, 255, 255, 0.01);
}

/* Toast alert styling */
.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: #000000;
    border: 1px solid var(--apple-border);
    color: var(--apple-text-primary);
    padding: 12px 24px;
    border-radius: 980px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 1;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.toast.hidden {
    display: none;
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
}

.toast-icon {
    width: 16px;
    height: 16px;
    color: #30d158; /* Success green */
}

/* Responsive grid layout */
@media (min-width: 850px) {
    .app-workspace {
        display: grid;
        grid-template-columns: 1fr;
        justify-content: center;
        max-width: 480px;
        margin: 0 auto;
        transition: max-width 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    }
    
    .app-workspace.has-results {
        grid-template-columns: 350px 1fr;
        max-width: 1024px;
        align-items: start;
        gap: 28px;
    }
    
    .display-panel {
        grid-column: 2;
    }
}

@media (max-width: 600px) {
    .result-metrics {
        grid-template-columns: repeat(2, 1fr);
    }
    .metric-item {
        border-bottom: 1px solid var(--apple-border);
    }
    .metric-item:nth-child(2n) {
        border-right: none;
    }
    .result-tabs-header {
        flex-direction: column;
        align-items: stretch;
    }
    .tab-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

/* Global Utility Classes */
.hidden {
    display: none !important;
}

/* Apple Style Tooltip */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    cursor: help;
}

.tooltip-icon {
    width: 14px;
    height: 14px;
    color: var(--apple-text-secondary);
    transition: var(--apple-transition);
}

.tooltip-container:hover .tooltip-icon {
    color: var(--apple-blue);
}

.tooltip-text {
    visibility: hidden;
    width: 280px;
    background-color: #1d1d1f;
    color: var(--apple-text-primary);
    text-align: left;
    border: 1px solid var(--apple-border);
    border-radius: 8px;
    padding: 12px 14px;
    position: absolute;
    z-index: 100;
    bottom: 130%; /* Position above the icon */
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    opacity: 0;
    font-size: 0.76rem;
    line-height: 1.45;
    font-weight: 400;
    pointer-events: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
    transition: opacity 0.2s cubic-bezier(0.25, 1, 0.5, 1), transform 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Tooltip arrow pointing down */
.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #1d1d1f transparent transparent transparent;
}

.tooltip-container:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

