/* ================= BIẾN MÀU (NATIVE APP THAY ĐỔI ĐEN/TRẮNG) ================= */
:root {
    --bg-color: #f2f2f7; /* iOS like background */
    --surface-color: #ffffff;
    --text-primary: #1c1c1e;
    --text-secondary: #8e8e93;
    --border-color: #e5e5ea;
    --btn-bg: #007aff; /* Native blue app look */
    --btn-text: #ffffff;
    --btn-hover: #005bb5;
    --drop-zone-bg: #f2f2f7;
    --drop-zone-border: #c7c7cc;
    --drop-zone-hover: #e5e5ea;
    --progress-bg: #e5e5ea;
    --progress-fill: #007aff;
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
    --bg-color: #000000; /* True black for OLED native dark mode */
    --surface-color: #1c1c1e;
    --text-primary: #ffffff;
    --text-secondary: #aeaeb2;
    --border-color: #38383a;
    --btn-bg: #0a84ff; /* Dark mode native blue */
    --btn-text: #ffffff;
    --btn-hover: #0060d1;
    --drop-zone-bg: #1c1c1e;
    --drop-zone-border: #48484a;
    --drop-zone-hover: #2c2c2e;
    --progress-bg: #38383a;
    --progress-fill: #0a84ff;
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

/* ================= HEADER ================= */
header {
    width: 100%;
    padding: calc(0.75rem + var(--safe-top)) 1.5rem 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] header {
    background-color: rgba(0, 0, 0, 0.8);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

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

/* Header & Brand Styles */
.btn-back {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.04);
    border: 1.5px solid rgba(0, 0, 0, 0.22);
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 18px;
}

[data-theme="dark"] .btn-back {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.22);
    color: var(--text-primary);
}

.btn-back:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary);
    transform: translateX(-2px);
    border-color: rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .btn-back:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.45);
}

.btn-back:active {
    transform: scale(0.92);
    background: rgba(0, 0, 0, 0.12);
    border-color: rgba(0, 0, 0, 0.55);
    opacity: 0.85;
}

[data-theme="dark"] .btn-back:active {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.55);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.15s ease;
}

.brand-link:hover {
    opacity: 0.92;
}

.brand-logo-card {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    padding: 3.5px;
    box-sizing: border-box;
    transition: transform 0.2s ease;
}

.brand-link:hover .brand-logo-card {
    transform: scale(1.04);
}

.brand-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 6px;
    display: block;
}

.brand-text {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    line-height: 1;
    white-space: nowrap;
}

.brand-name {
    font-weight: 800;
    font-size: 19px;
    color: var(--text-primary);
    letter-spacing: -0.025em;
    line-height: 1;
}

.brand-divider {
    font-size: 14px;
    font-weight: 300;
    color: var(--text-secondary);
    opacity: 0.7;
}

.brand-app {
    font-size: 14px;
    font-weight: 600;
    color: #4b5563;
    letter-spacing: -0.01em;
}

[data-theme="dark"] .brand-app {
    color: #aeaeb2;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.15s ease;
}

.theme-toggle:hover {
    background-color: var(--surface-color);
}

.theme-toggle:active {
    transform: scale(0.92);
}

.theme-toggle svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

[data-theme="dark"] .icon-sun {
    display: none;
}

[data-theme="light"] .icon-moon {
    display: none;
}

/* ================= GIAO DIỆN CHÍNH ================= */
main {
    width: 100%;
    max-width: 700px;
    margin: 3rem auto;
    padding: 0 1.5rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.app-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2.5rem;
    box-shadow: var(--shadow-md);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.text-center {
    text-align: center;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

p.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

/* ================= KHU VỰC KÉO THẢ ================= */
.drop-zone {
    border: 2px dashed var(--drop-zone-border);
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: var(--drop-zone-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.drop-zone.dragover {
    border-color: var(--text-primary);
    background-color: var(--drop-zone-hover);
}

.drop-zone input[type="file"] {
    display: none;
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    transition: color 0.2s ease;
}

.drop-zone:hover .upload-icon {
    color: var(--text-primary);
}

.drop-zone h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.file-info {
    margin-top: 1rem;
    font-weight: 600;
    color: var(--bg-color);
    background: var(--text-primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* ================= CÀI ĐẶT & NÚT BẤM ================= */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.format-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-grow: 1;
}

.format-selector label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

select {
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    flex-grow: 1;
    max-width: 150px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    transition: border-color 0.2s ease, background-color 0.3s ease;
}

[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23a1a1aa'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

select:focus {
    border-color: var(--text-primary);
}

button {
    background-color: var(--btn-bg);
    color: var(--btn-text);
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 122, 255, 0.15);
}

button:hover:not(:disabled) {
    background-color: var(--btn-hover);
    transform: translateY(-1px);
}

button:active:not(:disabled) {
    transform: scale(0.96);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ================= TIẾN TRÌNH (PROGRESS BAR) ================= */
.progress-container {
    margin-top: 1.5rem;
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--progress-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--progress-fill);
    width: 0%;
    transition: width 0.3s ease, background-color 0.3s ease;
    border-radius: 4px;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

@media (max-width: 600px) {
    main {
        margin: 0;
        padding: 0;
        max-width: 100%;
        display: block;
    }

    h1 {
        font-size: 1.5rem;
        padding: 0 0.5rem;
    }

    p.subtitle {
        font-size: 0.9rem;
        margin-bottom: 1.25rem;
        padding: 0 0.5rem;
    }

    .app-card {
        border-radius: 0;
        border: none;
        box-shadow: none;
        min-height: calc(100vh - 66px - var(--safe-top));
        display: flex;
        flex-direction: column;
        padding: 1rem 1rem calc(13rem + var(--safe-bottom)) 1rem;
        background-color: var(--bg-color); /* use root bg on mobile for full immersion */
    }

    .drop-zone {
        flex-grow: 1;
        justify-content: center;
        border-radius: 28px;
        background-color: var(--surface-color);
        box-shadow: 0 4px 20px rgba(0,0,0,0.03);
        margin-bottom: 0.5rem;
    }

    [data-theme="dark"] .drop-zone {
        box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    }

    .controls {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background-color: rgba(255, 255, 255, 0.85);
        backdrop-filter: blur(28px);
        -webkit-backdrop-filter: blur(28px);
        padding: 1.25rem 1.25rem calc(1.25rem + var(--safe-bottom)) 1.25rem;
        border-top: 1px solid var(--border-color);
        z-index: 50;
        margin-top: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        border-radius: 32px 32px 0 0;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.08);
    }

    [data-theme="dark"] .controls {
        background-color: rgba(28, 28, 30, 0.85);
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
    }

    .format-selector {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--bg-color);
        padding: 0.6rem 0.6rem 0.6rem 1.25rem;
        border-radius: 20px;
        margin: 0;
    }

    [data-theme="dark"] .format-selector {
        background: rgba(0, 0, 0, 0.3);
    }

    .format-selector label {
        font-size: 0.95rem;
        font-weight: 600;
    }

    select {
        flex-grow: 0;
        width: auto;
        max-width: none;
        border: none;
        box-shadow: 0 2px 10px rgba(0,0,0,0.06);
        border-radius: 14px;
        padding: 0.75rem 2.5rem 0.75rem 1.25rem;
        font-weight: 600;
        background-color: var(--surface-color);
        font-size: 0.95rem;
    }

    [data-theme="dark"] select {
        box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    }

    .controls button {
        width: 100%;
        padding: 1.15rem;
        border-radius: 20px;
        font-size: 1.1rem;
        font-weight: 700;
    }

    header {
        padding: calc(0.6rem + var(--safe-top)) 0.85rem 0.6rem 0.85rem;
    }

    .btn-back {
        width: 34px;
        height: 34px;
        border-radius: 10px;
        font-size: 16px;
    }

    .brand-logo-card {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        padding: 3px;
    }

    .brand-name {
        font-size: 17px;
    }

    .brand-app {
        font-size: 13px;
    }

    .progress-container {
        position: fixed;
        top: calc(85px + var(--safe-top));
        left: 1rem;
        width: calc(100% - 2rem);
        z-index: 60;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        padding: 1.25rem 1.5rem;
        border-radius: 24px;
        box-shadow: 0 16px 48px rgba(0,0,0,0.15);
        border: 1px solid var(--border-color);
    }

    [data-theme="dark"] .progress-container {
        background: rgba(28, 28, 30, 0.95);
        box-shadow: 0 16px 48px rgba(0,0,0,0.6);
    }
}