/* ==========================================================================
   Word Cloud Reader - Master UI Stylesheet
   Modern, High-End Minimalist Design (Apple / Linear / Notion Aesthetic)
   100% Mobile First, Pixel-Perfect Responsive Layout
   ========================================================================== */

:root {
    /* Brand & Accent Palette */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-glow: rgba(37, 99, 235, 0.15);
    
    /* Neutrals & Surfaces */
    --bg-app: #f8fafc;
    --bg-card: #ffffff;
    --bg-surface: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-active: #e2e8f0;
    
    /* Typography */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;
    
    /* Borders & Lines */
    --border-subtle: rgba(226, 232, 240, 0.8);
    --border-focus: #3b82f6;
    
    /* Shadows */
    --shadow-card: 0 2px 8px -2px rgba(15, 23, 42, 0.05), 0 1px 3px -1px rgba(15, 23, 42, 0.03);
    --shadow-card-hover: 0 12px 24px -6px rgba(15, 23, 42, 0.08), 0 4px 8px -2px rgba(15, 23, 42, 0.04);
    --shadow-modal: 0 20px 40px -10px rgba(15, 23, 42, 0.2), 0 8px 16px -4px rgba(15, 23, 42, 0.1);
    
    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 9999px;

    /* Functional */
    --success: #10b981;
    --success-light: #ecfdf5;
    --success-border: #a7f3d0;
    --danger: #ef4444;
    --danger-light: #fef2f2;
}

/* Base Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background-color: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom);
}

/* App Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 60;
    height: 56px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
}

.header-container {
    max-width: 980px;
    height: 100%;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.brand-icon-wrap {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
    overflow: hidden;
}

.brand-icon-wrap img, .brand-icon-wrap svg {
    width: 100%;
    height: 100%;
    display: block;
}

.brand-text {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand-badge {
    font-size: 0.7rem;
    font-weight: 600;
    color: #059669;
    background: var(--success-light);
    border: 1px solid var(--success-border);
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    margin-left: 4px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stats-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stats-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.btn-header-upload {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    font-size: 0.84rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    box-shadow: 0 2px 8px var(--primary-glow);
    transition: all 0.15s ease;
}

.btn-header-upload:hover {
    background: var(--primary-hover);
}

.btn-header-upload:active {
    transform: scale(0.96);
}

/* Main Container */
.main-content {
    max-width: 980px;
    margin: 0 auto;
    padding: 20px 16px 80px;
}

/* Mobile Friendly Search & Action Bar */
.top-action-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.search-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    height: 42px;
    padding: 0 14px 0 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-size: 0.92rem;
    color: var(--text-primary);
    outline: none;
    box-shadow: var(--shadow-card);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.search-icon {
    position: absolute;
    left: 14px;
    color: var(--text-tertiary);
    pointer-events: none;
}

/* Compact Upload Banner */
.upload-banner {
    background: linear-gradient(135deg, #f0f7ff 0%, #e0effe 100%);
    border: 1.5px dashed #93c5fd;
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-banner:hover, .upload-banner.drag-over {
    border-color: var(--primary);
    background: #e0effe;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.12);
}

.upload-banner-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.upload-banner-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: var(--radius-md);
    background: #ffffff;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.15);
}

.upload-banner-title {
    font-size: 0.96rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.upload-banner-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-banner-upload {
    background: #ffffff;
    color: var(--primary);
    border: 1px solid #bfdbfe;
    font-size: 0.84rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.15s ease;
}

.upload-banner:hover .btn-banner-upload {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

/* Progress bar inside upload area */
.upload-progress-box {
    margin-top: 14px;
    width: 100%;
    display: none;
}

.progress-track {
    width: 100%;
    height: 6px;
    background: #dbeafe;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #1d4ed8);
    width: 0%;
    transition: width 0.15s ease-out;
}

.progress-label {
    font-size: 0.78rem;
    color: var(--primary);
    font-weight: 500;
}

/* Section Title */
.doc-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding: 0 4px;
}

.doc-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.doc-count-tag {
    font-size: 0.76rem;
    background: #e2e8f0;
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-weight: 600;
}

/* Document List - Modern Mobile List Style */
.doc-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.doc-item-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-card);
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    user-select: none;
}

.doc-item-card:hover {
    border-color: #cbd5e1;
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.doc-item-card:active {
    transform: scale(0.99);
    background: #f8fafc;
}

.doc-item-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

/* Beautiful Word Document Icon Badge */
.doc-icon-tile {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.22);
    position: relative;
    overflow: hidden;
}

.doc-icon-tile::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 100%);
}

.doc-info-block {
    min-width: 0;
    flex: 1;
}

.doc-title-text {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.35;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-meta-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-tertiary);
}

.doc-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.doc-compress-tag {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--success-light);
    color: #059669;
    border: 1px solid var(--success-border);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 6px;
}

.doc-item-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 10px;
}

.btn-open-read {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f1f5f9;
    color: var(--primary);
    border: none;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-open-read:hover {
    background: var(--primary);
    color: #ffffff;
}

.btn-item-more {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-item-more:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Empty State */
.empty-box {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    color: var(--text-tertiary);
}

.empty-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    color: #cbd5e1;
}

/* Mobile Floating Action Button (FAB) */
.mobile-fab {
    display: none;
    position: fixed;
    right: 20px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 55;
    border: none;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-fab:active {
    transform: scale(0.92);
}

/* Mobile Bottom Action Sheet */
.action-sheet-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    display: flex;
    align-items: flex-end;
}

.action-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.action-sheet {
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-modal);
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
}

.action-sheet-backdrop.open .action-sheet {
    transform: translateY(0);
}

.sheet-handle {
    width: 36px;
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    margin: 0 auto 16px;
}

.sheet-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.sheet-doc-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-doc-sub {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.sheet-actions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sheet-action-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-radius: var(--radius-md);
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.94rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s;
    width: 100%;
    text-align: left;
}

.sheet-action-item:hover, .sheet-action-item:active {
    background: var(--bg-hover);
}

.sheet-action-item.danger {
    color: var(--danger);
}

.sheet-action-item.danger:hover, .sheet-action-item.danger:active {
    background: var(--danger-light);
}

/* Modals & Dialogs */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 160;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 400px;
    padding: 24px;
    box-shadow: var(--shadow-modal);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal-backdrop.open .modal-card {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
}

.qr-canvas-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
}

.qr-img {
    border: 8px solid #ffffff;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    width: 200px;
    height: 200px;
}

.qr-tip {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 14px;
    text-align: center;
    line-height: 1.4;
}

.qr-link-copy {
    margin-top: 16px;
    display: flex;
    gap: 8px;
    width: 100%;
}

.qr-url-input {
    flex: 1;
    background: #f8fafc;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    outline: none;
}

.btn-copy-url {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(8px);
    color: #ffffff;
    padding: 10px 20px;
    border-radius: var(--radius-pill);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-modal);
    opacity: 0;
    transform: translateY(12px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile Screen Breakpoints */
@media (max-width: 640px) {
    .header-container {
        padding: 0 14px;
    }
    .stats-pill {
        display: none;
    }
    .main-content {
        padding: 14px 12px 80px;
    }
    .upload-banner-sub {
        display: none;
    }
    .upload-banner {
        padding: 14px 16px;
        margin-bottom: 18px;
    }
    .btn-open-read {
        display: none; /* On mobile, tapping card directly opens */
    }
    .mobile-fab {
        display: flex;
    }
}
