/* ================= 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(1rem + var(--safe-top)) 2rem 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 0.5px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

[data-theme="dark"] header {
    background-color: rgba(0, 0, 0, 0.7);
}

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

.logo-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.25rem;
    gap: 10px;
}

.logo-link img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

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

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

.theme-toggle svg {
    width: 24px;
    height: 24px;
    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;
    }

    .app-card {
        border-radius: 0;
        border: none;
        box-shadow: none;
        min-height: calc(100vh - 66px - var(--safe-top));
        display: flex;
        flex-direction: column;
        padding: 1.5rem 1rem calc(6rem + 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: 20px;
    }

    .controls {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background-color: rgba(255, 255, 255, 0.8);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        padding: 1rem 1.5rem calc(1rem + var(--safe-bottom)) 1.5rem;
        border-top: 0.5px solid var(--border-color);
        z-index: 50;
        margin-top: 0;
        flex-direction: row;
        align-items: center;
    }

    [data-theme="dark"] .controls {
        background-color: rgba(28, 28, 30, 0.8);
    }

    .format-selector {
        flex-grow: 1;
    }

    select {
        flex-grow: 1;
        max-width: 100%;
    }

    header {
        padding: calc(1rem + var(--safe-top)) 1.5rem 1rem 1.5rem;
    }

    .progress-container {
        position: fixed;
        top: calc(70px + var(--safe-top));
        left: 5%;
        width: 90%;
        z-index: 60;
        background: var(--surface-color);
        padding: 1rem;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.1);
        border: 1px solid var(--border-color);
    }
}