/* ═══════════════════════════════════════════════════════════
   CYPHER Design System — iOS IPA Signer
   A premium signing-tool aesthetic with editorial typography
   ═══════════════════════════════════════════════════════════ */

/* — Reset — */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* — Design Tokens — */
:root {
    /* Typography */
    --font-display: 'Bricolage Grotesque', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Menlo', monospace;

    /* Spacing scale */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
    --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
    --sp-12: 48px; --sp-16: 64px;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Light Mode Colors (default) */
    --bg: #F7F7F8;
    --bg-elevated: #FFFFFF;
    --bg-surface: #EDEDF0;
    --bg-inset: #E4E4E8;
    --text: #0C0C0E;
    --text-secondary: #5E5E6E;
    --text-muted: #9898A8;
    --accent: #BE123C;
    --accent-hover: #E11D48;
    --accent-text: #FFFFFF;
    --accent-soft: rgba(190, 18, 60, 0.08);
    --accent-glow: rgba(190, 18, 60, 0.25);
    --blue: #2563EB;
    --blue-soft: rgba(37, 99, 235, 0.08);
    --blue-text: #1D4ED8;
    --green: #059669;
    --green-soft: rgba(5, 150, 105, 0.08);
    --green-text: #047857;
    --amber: #D97706;
    --amber-soft: rgba(217, 119, 6, 0.08);
    --amber-text: #B45309;
    --red: #DC2626;
    --red-soft: rgba(220, 38, 38, 0.08);
    --red-text: #B91C1C;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    --shadow-xl: 0 8px 40px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.04);
    --overlay: rgba(0, 0, 0, 0.5);
    --noise-opacity: 0.03;
    --theme-toggle-icon: '\\263E'; /* moon */
}

/* — Dark Mode — */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0B0B0F;
        --bg-elevated: #141418;
        --bg-surface: #1C1C22;
        --bg-inset: #111115;
        --text: #EEEEF0;
        --text-secondary: #8B8B9E;
        --text-muted: #5C5C6F;
        --accent: #F43F5E;
        --accent-hover: #FB7185;
        --accent-text: #FFFFFF;
        --accent-soft: rgba(244, 63, 94, 0.12);
        --accent-glow: rgba(244, 63, 94, 0.3);
        --blue: #3B82F6;
        --blue-soft: rgba(59, 130, 246, 0.12);
        --blue-text: #60A5FA;
        --green: #10B981;
        --green-soft: rgba(16, 185, 129, 0.12);
        --green-text: #34D399;
        --amber: #F59E0B;
        --amber-soft: rgba(245, 158, 11, 0.12);
        --amber-text: #FBBF24;
        --red: #EF4444;
        --red-soft: rgba(239, 68, 68, 0.12);
        --red-text: #F87171;
        --border: rgba(255, 255, 255, 0.07);
        --border-strong: rgba(255, 255, 255, 0.13);
        --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
        --shadow-md: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
        --shadow-lg: 0 4px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.04);
        --shadow-xl: 0 8px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
        --overlay: rgba(0, 0, 0, 0.7);
        --noise-opacity: 0.04;
        --theme-toggle-icon: '\\2600'; /* sun */
    }
}

/* Manual dark mode override */
[data-theme="dark"] {
    --bg: #0B0B0F;
    --bg-elevated: #141418;
    --bg-surface: #1C1C22;
    --bg-inset: #111115;
    --text: #EEEEF0;
    --text-secondary: #8B8B9E;
    --text-muted: #5C5C6F;
    --accent: #F43F5E;
    --accent-hover: #FB7185;
    --accent-text: #FFFFFF;
    --accent-soft: rgba(244, 63, 94, 0.12);
    --accent-glow: rgba(244, 63, 94, 0.3);
    --blue: #3B82F6;
    --blue-soft: rgba(59, 130, 246, 0.12);
    --blue-text: #60A5FA;
    --green: #10B981;
    --green-soft: rgba(16, 185, 129, 0.12);
    --green-text: #34D399;
    --amber: #F59E0B;
    --amber-soft: rgba(245, 158, 11, 0.12);
    --amber-text: #FBBF24;
    --red: #EF4444;
    --red-soft: rgba(239, 68, 68, 0.12);
    --red-text: #F87171;
    --border: rgba(255, 255, 255, 0.07);
    --border-strong: rgba(255, 255, 255, 0.13);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.04);
    --shadow-xl: 0 8px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
    --overlay: rgba(0, 0, 0, 0.7);
    --noise-opacity: 0.04;
}

/* Manual light mode override */
[data-theme="light"] {
    --bg: #F7F7F8;
    --bg-elevated: #FFFFFF;
    --bg-surface: #EDEDF0;
    --bg-inset: #E4E4E8;
    --text: #0C0C0E;
    --text-secondary: #5E5E6E;
    --text-muted: #9898A8;
    --accent: #BE123C;
    --accent-hover: #E11D48;
    --accent-text: #FFFFFF;
    --accent-soft: rgba(190, 18, 60, 0.08);
    --accent-glow: rgba(190, 18, 60, 0.25);
    --blue: #2563EB;
    --blue-soft: rgba(37, 99, 235, 0.08);
    --blue-text: #1D4ED8;
    --green: #059669;
    --green-soft: rgba(5, 150, 105, 0.08);
    --green-text: #047857;
    --amber: #D97706;
    --amber-soft: rgba(217, 119, 6, 0.08);
    --amber-text: #B45309;
    --red: #DC2626;
    --red-soft: rgba(220, 38, 38, 0.08);
    --red-text: #B91C1C;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    --shadow-xl: 0 8px 40px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.04);
    --overlay: rgba(0, 0, 0, 0.5);
    --noise-opacity: 0.03;
}

/* — Base — */
html {
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color-scheme: light dark;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Subtle noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
    opacity: var(--noise-opacity);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* — Typography — */
h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text);
}

h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; font-weight: 600; }

/* — Animations — */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes pulse-ring {
    0% { transform: scale(0.8); opacity: 1; }
    100% { transform: scale(1.6); opacity: 0; }
}

.animate-up {
    animation: fadeUp var(--duration-slow) var(--ease-out) both;
}

.stagger-1 { animation-delay: 50ms; }
.stagger-2 { animation-delay: 100ms; }
.stagger-3 { animation-delay: 150ms; }
.stagger-4 { animation-delay: 200ms; }
.stagger-5 { animation-delay: 250ms; }

/* — Cards — */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-6);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration-normal) ease, transform var(--duration-normal) ease;
}

.card-accent {
    border-top: 3px solid var(--accent);
}

.card-hover:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

/* — Buttons — */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--duration-fast) ease;
    white-space: nowrap;
}

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

.btn-accent {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 1px 3px var(--accent-glow);
}
.btn-accent:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary {
    background: var(--blue);
    color: #FFFFFF;
}
.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--bg-inset);
    border-color: var(--border-strong);
}

.btn-danger {
    background: var(--red-soft);
    color: var(--red-text);
}
.btn-danger:hover {
    background: var(--red);
    color: #FFFFFF;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-surface);
    color: var(--text);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: var(--radius-md);
}

.btn-full { width: 100%; }

/* — Forms — */
.form-group { margin-bottom: var(--sp-5); }

.form-label {
    display: block;
    margin-bottom: var(--sp-2);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 15px;
    color: var(--text);
    transition: all var(--duration-fast) ease;
}

.form-input::placeholder { color: var(--text-muted); }
.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-input-mono {
    font-family: var(--font-mono);
    font-size: 13px;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%239898A8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.form-hint {
    margin-top: var(--sp-1);
    font-size: 12px;
    color: var(--text-muted);
}

/* — Checkbox Toggle — */
.toggle-group {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    user-select: none;
    transition: border-color var(--duration-fast) ease;
}

.toggle-group:hover { border-color: var(--border-strong); }

.toggle-group input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-strong);
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: all var(--duration-fast) ease;
}

.toggle-group input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-group input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.toggle-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}

.toggle-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* — Badges — */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-blue { background: var(--blue-soft); color: var(--blue-text); }
.badge-green { background: var(--green-soft); color: var(--green-text); }
.badge-amber { background: var(--amber-soft); color: var(--amber-text); }
.badge-red { background: var(--red-soft); color: var(--red-text); }
.badge-muted { background: var(--bg-surface); color: var(--text-muted); }

/* — Progress Bar — */
.progress-track {
    width: 100%;
    height: 8px;
    background: var(--bg-inset);
    border-radius: var(--radius-full);
    overflow: hidden;
}

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

.progress-fill.complete {
    background: linear-gradient(90deg, var(--green) 0%, #34D399 100%);
}

.progress-text {
    margin-top: var(--sp-2);
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* — Tables — */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th {
    background: var(--bg-surface);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-surface); }

.table .mono {
    font-family: var(--font-mono);
    font-size: 11px;
    word-break: break-all;
    white-space: normal;
}

/* — Stat Cards — */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--sp-4);
}

.stat-card {
    padding: var(--sp-5);
    border-radius: var(--radius-lg);
    text-align: center;
}

.stat-card-accent {
    background: linear-gradient(135deg, var(--accent), #F43F5E);
    color: #FFFFFF;
}

.stat-card-blue {
    background: linear-gradient(135deg, #2563EB, #3B82F6);
    color: #FFFFFF;
}

.stat-card-green {
    background: linear-gradient(135deg, #059669, #10B981);
    color: #FFFFFF;
}

.stat-card-amber {
    background: linear-gradient(135deg, #D97706, #F59E0B);
    color: #FFFFFF;
}

.stat-number {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: var(--sp-1);
}

.stat-label {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 500;
}

/* — Tabs — */
.tabs-nav {
    display: flex;
    gap: var(--sp-1);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--sp-8);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tabs-nav::-webkit-scrollbar { display: none; }

.tab-btn {
    padding: var(--sp-3) var(--sp-5);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--duration-fast) ease;
    position: relative;
    bottom: -1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn var(--duration-normal) ease; }

/* — Modal — */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal-box {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--sp-8);
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: fadeUp var(--duration-slow) var(--ease-out);
}

/* — Theme Toggle — */
/* — Theme Segmented Control — */
.theme-seg {
    display: inline-flex;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2px;
    gap: 1px;
}
.theme-seg .seg {
    padding: 4px 10px;
    font-size: 13px;
    border-radius: calc(var(--radius-md) - 2px);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    border: none;
    background: none;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.theme-seg .seg:hover {
    color: var(--text-secondary);
}
.theme-seg .seg.active {
    background: var(--accent-soft);
    color: var(--accent);
}

/* — Page Header — */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--sp-5) 0;
    margin-bottom: var(--sp-6);
}

.page-header h1 {
    font-size: 24px;
}

.page-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.page-brand .seal {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-size: 18px;
    font-weight: 700;
    font-family: var(--font-display);
    flex-shrink: 0;
}

.btn-group {
    display: flex;
    gap: var(--sp-2);
    align-items: center;
}

/* — Upload Area — */
.upload-zone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: var(--sp-10) var(--sp-6);
    text-align: center;
    cursor: pointer;
    transition: all var(--duration-normal) ease;
    background: var(--bg-surface);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.upload-zone .upload-icon {
    font-size: 40px;
    margin-bottom: var(--sp-3);
    opacity: 0.6;
}

.upload-zone .upload-text {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: var(--sp-1);
}

.upload-zone .upload-hint {
    font-size: 13px;
    color: var(--text-muted);
}

.upload-zone .file-name {
    margin-top: var(--sp-3);
    font-weight: 600;
    color: var(--accent);
    font-size: 14px;
}

/* — Result States — */
.result-box {
    display: none;
    padding: var(--sp-6);
    border-radius: var(--radius-lg);
    text-align: center;
}

.result-box.success {
    background: var(--green-soft);
    border: 1px solid var(--green);
}

.result-box.error {
    background: var(--red-soft);
    border: 1px solid var(--red);
}

.result-icon { font-size: 40px; margin-bottom: var(--sp-3); }
.result-title { font-family: var(--font-display); font-size: 18px; margin-bottom: var(--sp-2); }

.install-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    margin-top: var(--sp-4);
    padding: 14px 28px;
    background: var(--green);
    color: #FFFFFF;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font-body);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--duration-fast) ease;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.install-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
}

/* — App Cards (Library) — */
.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--sp-4);
}

.app-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    transition: all var(--duration-normal) ease;
}

.app-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.app-card-header {
    display: flex;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
}

.app-card-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    object-fit: cover;
    background: var(--bg-surface);
    flex-shrink: 0;
}

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

.app-card-name {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-card-version {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.app-card-badges {
    display: flex;
    gap: var(--sp-1);
    flex-wrap: wrap;
    margin-top: var(--sp-2);
}

.app-card-desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: var(--sp-4);
    max-height: 40px;
    overflow: hidden;
}

/* — Section Spacing — */
.section { margin-bottom: var(--sp-8); }
.section-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    margin-bottom: var(--sp-5);
    color: var(--text);
}

/* — Message/Alert — */
.alert {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-md);
    font-size: 14px;
    display: none;
}

.alert-success { background: var(--green-soft); color: var(--green-text); border: 1px solid var(--green); }
.alert-error { background: var(--red-soft); color: var(--red-text); border: 1px solid var(--red); }
.alert-info { background: var(--blue-soft); color: var(--blue-text); border: 1px solid var(--blue); }

/* — Featured Section — */
.featured-section {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--radius-xl);
    padding: var(--sp-6);
    margin-bottom: var(--sp-6);
}

.featured-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: var(--sp-5);
}

/* — Source/Category Tags — */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
}

.tag {
    padding: 6px 14px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
}

.tag:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.tag.active {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

/* — Search — */
.search-box {
    position: relative;
}

.search-box::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239898A8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-size: contain;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 15px;
    color: var(--text);
    transition: all var(--duration-fast) ease;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* — Collapsible — */
.collapsible-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all var(--duration-fast) ease;
}

.collapsible-trigger:hover {
    border-color: var(--border-strong);
}

.collapsible-trigger .arrow {
    transition: transform var(--duration-normal) var(--ease-out);
    font-size: 12px;
    color: var(--text-muted);
}

.collapsible-trigger.open .arrow {
    transform: rotate(180deg);
}

.collapsible-body {
    display: none;
    margin-top: var(--sp-3);
    padding: var(--sp-5);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.collapsible-body.open { display: block; }

/* — Empty State — */
.empty-state {
    text-align: center;
    padding: var(--sp-10);
    color: var(--text-muted);
    font-size: 14px;
}

/* — Layout Containers — */
.page-wrap {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: var(--sp-5);
    padding-top: max(var(--sp-5), env(safe-area-inset-top));
    padding-bottom: max(var(--sp-5), env(safe-area-inset-bottom));
}

.page-wrap-narrow {
    max-width: 680px;
}

.page-wrap-center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--sp-5);
}

/* — Responsive — */
@media (max-width: 768px) {
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }

    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--sp-3);
    }

    .btn-group {
        width: 100%;
        justify-content: stretch;
    }

    .btn-group .btn { flex: 1; text-align: center; }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .apps-grid {
        grid-template-columns: 1fr;
    }

    .table th, .table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .card { padding: var(--sp-4); }

    .modal-box {
        padding: var(--sp-5);
        width: 95%;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* — Utility — */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.font-bold { font-weight: 700; }
.font-mono { font-family: var(--font-mono); }
.hidden { display: none; }
.w-full { width: 100%; }

/* — Toast Notifications — */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    gap: var(--sp-2);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    padding: var(--sp-3) var(--sp-5);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-body);
    box-shadow: var(--shadow-lg);
    animation: toastIn var(--duration-normal) var(--ease-out) both;
    max-width: 380px;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.toast.removing {
    animation: toastOut var(--duration-fast) ease-in both;
}

.toast-success {
    background: var(--green);
    color: #FFFFFF;
}

.toast-error {
    background: var(--red);
    color: #FFFFFF;
}

.toast-info {
    background: var(--blue);
    color: #FFFFFF;
}

.toast-warning {
    background: var(--amber);
    color: #FFFFFF;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to { opacity: 0; transform: translateX(40px) scale(0.95); }
}

@media (max-width: 480px) {
    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
    .toast { max-width: 100%; }
}

/* — Favorites — */
.fav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 2px;
    color: var(--text-muted);
    transition: all var(--duration-fast) ease;
    flex-shrink: 0;
}

.fav-btn:hover {
    color: var(--amber);
    transform: scale(1.15);
}

.fav-btn.active {
    color: var(--amber);
}

.fav-btn:active {
    transform: scale(0.9);
}

/* — Activity Feed — */
.activity-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    flex-shrink: 0;
    animation: pulse-ring 1.5s ease infinite;
}
.pulse-dot.signing { background: var(--amber); }
.pulse-dot.signed {
    animation: none;
}

.activity-time {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 11px;
    white-space: nowrap;
}

/* — WebSocket Status Indicator — */
.ws-indicator {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    font-size: 11px;
    color: var(--text-muted);
}
.ws-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
}
.ws-indicator .dot.connected {
    background: var(--green);
}
.ws-indicator .dot.disconnected {
    background: var(--red);
}

/* — Screenshots Carousel — */
.screenshots-scroll {
    display: flex;
    gap: var(--sp-3);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    padding: var(--sp-2) 0;
}
.screenshots-scroll::-webkit-scrollbar { display: none; }
.screenshot-img {
    scroll-snap-align: start;
    width: 200px;
    height: 433px;
    object-fit: cover;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-surface);
}

/* — Version History — */
.version-item {
    padding: var(--sp-4);
    border-bottom: 1px solid var(--border);
}
.version-item:last-child { border-bottom: none; }
.version-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-2);
}
.version-notes {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-line;
}
