/* ═══════════════════════════════════════════
   IPA Signer — Premium Dark Theme
   ═══════════════════════════════════════════ */

:root {
    /* Color palette */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #16161f;
    --bg-elevated: #1c1c28;
    --bg-glass: rgba(22, 22, 31, 0.75);

    --accent: #6c5ce7;
    --accent-bright: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.25);

    --success: #00cec9;
    --success-glow: rgba(0, 206, 201, 0.2);
    --danger: #ff6b6b;
    --danger-glow: rgba(255, 107, 107, 0.2);
    --warning: #ffd93d;

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #555568;

    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: 80px;
}

/* Animated gradient background */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 20% 50%, rgba(108, 92, 231, 0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 20%, rgba(0, 206, 201, 0.06) 0%, transparent 50%),
                radial-gradient(ellipse at 50% 80%, rgba(255, 107, 107, 0.04) 0%, transparent 50%);
    z-index: 0;
    animation: bgShift 20s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes bgShift {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(-5%, 3%) rotate(3deg); }
}

/* ─── Header ─── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
}

.header-inner {
    max-width: 640px;
    margin: 0 auto;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), var(--success));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.logo-icon svg {
    width: 18px;
    height: 18px;
}

.logo-text {
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-bright));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-bright);
    background: var(--accent-glow);
    padding: 4px 10px;
    border-radius: 100px;
    border: 1px solid rgba(108, 92, 231, 0.2);
}

/* ─── Upload Section ─── */
.upload-section {
    position: relative;
    z-index: 1;
    max-width: 640px;
    margin: 24px auto 0;
    padding: 0 20px;
}

.upload-zone {
    border: 2px dashed rgba(108, 92, 231, 0.3);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-card);
    position: relative;
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--accent-glow), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.upload-zone:hover::before,
.upload-zone.dragover::before {
    opacity: 1;
}

.upload-icon {
    position: relative;
    z-index: 1;
    margin-bottom: 16px;
    color: var(--accent-bright);
}

.upload-icon svg {
    width: 48px;
    height: 48px;
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.upload-title {
    position: relative;
    z-index: 1;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}

.upload-subtitle {
    position: relative;
    z-index: 1;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ─── Progress ─── */
.progress-container {
    margin-top: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.82rem;
}

.progress-filename {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70%;
}

.progress-percent {
    color: var(--accent-bright);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.progress-bar {
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 100px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 100px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 25%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2));
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* ─── Apps Section ─── */
.apps-section {
    position: relative;
    z-index: 1;
    max-width: 640px;
    margin: 32px auto 0;
    padding: 0 20px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

.app-count {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 100px;
    border: 1px solid var(--border);
}

.app-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ─── Empty State ─── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* ─── App Card ─── */
.app-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: cardIn 0.4s ease-out backwards;
}

.app-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
}

.app-card:nth-child(1) { animation-delay: 0.05s; }
.app-card:nth-child(2) { animation-delay: 0.1s; }
.app-card:nth-child(3) { animation-delay: 0.15s; }
.app-card:nth-child(4) { animation-delay: 0.2s; }
.app-card:nth-child(5) { animation-delay: 0.25s; }

.app-card-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.app-icon-wrapper {
    flex-shrink: 0;
}

.app-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
    box-shadow: 0 4px 12px var(--accent-glow);
}

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

.app-name {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-version {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.app-bundle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-badge {
    flex-shrink: 0;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 100px;
    white-space: nowrap;
}

.app-badge.signed {
    color: var(--success);
    background: var(--success-glow);
    border: 1px solid rgba(0, 206, 201, 0.2);
}

.app-badge.unsigned {
    color: var(--text-muted);
    background: rgba(85, 85, 104, 0.15);
    border: 1px solid rgba(85, 85, 104, 0.2);
}

.app-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-sign {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: white;
    border: none;
    box-shadow: 0 2px 12px var(--accent-glow);
    flex: 1;
}

.btn-sign:hover {
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4);
    transform: translateY(-1px);
}

.btn-sign:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-install {
    background: linear-gradient(135deg, var(--success), #00b894);
    color: white;
    border: none;
    box-shadow: 0 2px 12px var(--success-glow);
    flex: 1;
    justify-content: center;
}

.btn-install:hover {
    box-shadow: 0 4px 20px rgba(0, 206, 201, 0.4);
    transform: translateY(-1px);
}

.btn-delete {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-delete:hover {
    color: var(--danger);
    border-color: rgba(255, 107, 107, 0.3);
    background: var(--danger-glow);
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ─── Log Panel ─── */
.log-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
}

.log-panel {
    width: 100%;
    max-width: 640px;
    max-height: 70vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
}

.log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.log-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.log-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.log-close-btn:hover {
    background: var(--danger-glow);
    color: var(--danger);
    border-color: rgba(255, 107, 107, 0.3);
}

.log-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px 24px;
}

.log-content {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.78rem;
    line-height: 1.7;
}

.log-line {
    padding: 2px 0;
    color: var(--text-secondary);
    animation: logLineIn 0.15s ease;
}

@keyframes logLineIn {
    from { opacity: 0; transform: translateX(-4px); }
}

.log-line.log-success {
    color: var(--success);
    font-weight: 600;
}

.log-line.log-error {
    color: var(--danger);
    font-weight: 600;
}

/* ─── Toasts ─── */
.toast-container {
    position: fixed;
    top: 76px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 90%;
    max-width: 400px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
    opacity: 0;
    transform: translateY(-8px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

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

.toast-hide {
    opacity: 0;
    transform: translateY(-12px);
}

.toast-success {
    background: rgba(0, 206, 201, 0.15);
    color: var(--success);
    border: 1px solid rgba(0, 206, 201, 0.25);
}

.toast-error {
    background: rgba(255, 107, 107, 0.15);
    color: var(--danger);
    border: 1px solid rgba(255, 107, 107, 0.25);
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Desktop Enhancements ─── */
@media (min-width: 768px) {
    .upload-zone {
        padding: 64px 32px;
    }

    .log-panel {
        max-height: 60vh;
        border-radius: var(--radius-xl);
        border-bottom: 1px solid var(--border);
        margin-bottom: 32px;
    }

    .log-overlay {
        align-items: center;
    }
}
